Curses

From Fernseher
Revision as of 19:18, 23 January 2007 by Admin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

So, I was going to use curses for the frontend. I'm not quite sure anymore what I am going to use for the front end, but I thought I would add this LESENMICH dump.

Fernseher::Menu.pm

The menus module contains functions that can be used by the interface clients to easily draw menus on screen and do that sort of operation.

To create a menu onscreen, first create a menu object, then execute it:

my $mainmenu=new Fernseher::Menu(<menu title list>,<items structure>);
my $selected=$mainmenu->execute(<startindex>);

execute starts with the indexth item currently selected. It will return with the index of the item that was chosen, via the selections or a shortcut key.

Upon execute, the curses interface is initialized. Upon exit, the curses interface has been deinitialized.

The menu title list is a list that will be joined with ':' to create the title line displayed on top of the menu in green.

The items structure is a list of all possible results of the menu execution, including items in the menu list, items that cannot be seen in the list, but can be chosen, items that can be seen but not chosen, and items that can be neither seen nor chosen.

Each item is actually a hash containing these elements: index => value returned if this item is chosen. If not defined, this item cannot be chosen. name => value to display in the menu list. If this is not defined, its not displayed. Only items with a name and an index will allow cursor selection in the menu. shortcuts => keypresses that would select this item other than menu selection. This is actually a list of such keypresses. A given keypress should only appear in one shortcuts list. An item with no index can not have any shortcuts.

So, for the main menu for spieler, we could create the menu as:

new Fernseher::Menu([""," fernSEHER ","spieler"],
	[ {
		index=>-1,
		shortcuts=>["ESC","Left","App Exit"]
	}, {name=>""}, {
		index=>1,
		name=>"1 Watch Recorded Shows",
		shortcuts=>["1","MyTV"]
	}, {
		index=>2,
		name=>"2 Watch Other Video",
		shortcuts=>["2","MyMovie"]
	}, {
		index=>3,
		name=>"3 Watch DVD",
		shortcuts=>["3","MyDVD"]
	}, {name=>""}, {
		index=>4,
		name=>"4 Listen to Music",
		shortcuts=>["4","MyMusic"]
	}, {
		index=>5,
		name=>"5 Listen to CD",
		shortcuts=>["5"]
	}, {name=>""}, {
		index=>6,
		name=>"6 View Pictures",
		shortcuts=>["6","MyPhoto"]
	} ]);