PageRenderTime 22ms CodeModel.GetById 18ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/ncurses/menu.e

http://github.com/tybor/Liberty
Specman e | 76 lines | 62 code | 14 blank | 0 comment | 2 complexity | a2f4766ebcca2fa96c5e2f94cfbdfe87 MD5 | raw file
 1class MENU
 2
 3insert
 4   NCURSES_TOOLS
 5   NCURSES_COLORS
 6
 7create {ANY}
 8   make
 9
10feature {}
11   root_window: NCURSES_WINDOW
12
13   menubar: NCURSES_MENUBAR[STRING]
14
15   make
16      local
17         items: HASHED_DICTIONARY[HASHED_DICTIONARY[STRING, STRING], STRING]; item: HASHED_DICTIONARY[STRING, STRING]
18      do
19         ncurses.enable
20         root_window := ncurses.get_root_window
21         ncurses.set_echoing_policy(False)
22         ncurses.set_cursor_visibility(invisible_cursor_mode)
23
24         create items.make
25         create item.make
26         item.add("1.1", "item 1")
27         item.add("1.2", "item 2")
28         item.add("1.3", "item 3")
29         items.add(item, "menu 1")
30
31         create item.make
32         item.add("2.1", "item 1")
33         item.add("2.2", "item 2")
34         item.add("2.3", "item 3")
35         items.add(item, "menu 2")
36
37         create item.make
38         item.add("3.1", "item 1")
39         item.add("3.2", "item 2")
40         item.add("3.3", "item 3")
41         items.add(item, "menu 3")
42
43         create menubar.make(root_window, 0, items, True)
44         menubar.set_colors(black_color, white_color)
45
46         root_window.put_string_at("Press m to access the menu", 1, menubar.height)
47         root_window.put_string_at("In the menu bar, press <left> and <right> to select a menu", 1, menubar.height + 1)
48         root_window.put_string_at("In a menu, press <up> and <down> to select an item", 1, menubar.height + 2)
49         root_window.put_string_at("At any time, press <enter> to validate your choice or <esc> to go back", 1, menubar.height + 3)
50         root_window.redraw_now
51
52         ncurses.when_key_pressed(agent key_press(?))
53         ncurses.start
54      end
55
56   key_press (key_code: INTEGER)
57      local
58         selected: STRING
59      do
60         if key_code.to_character = 'm' then
61            menubar.read_choice
62            selected := menubar.last_choice
63            if selected = Void then
64               root_window.put_string_at("No selection             ", 1, menubar.height + 5)
65            else
66               root_window.put_string_at("You selected the item ", 1, menubar.height + 5)
67               root_window.put_string(selected)
68            end
69
70            root_window.redraw_now
71         elseif key_code.to_character.to_upper = 'Q' then
72            ncurses.disable
73         end
74      end
75
76end -- class MENU