PageRenderTime 23ms CodeModel.GetById 16ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/ncurses/list.e

http://github.com/tybor/Liberty
Specman e | 65 lines | 55 code | 10 blank | 0 comment | 3 complexity | 822311754c704cb5070dade3f2c81a90 MD5 | raw file
 1class LIST
 2
 3insert
 4   NCURSES_TOOLS
 5   NCURSES_KEYS
 6   NCURSES_COLORS
 7   NCURSES_CHARACTERS
 8
 9create {}
10   make
11
12feature {ANY}
13   ncurses_list: NCURSES_LIST[ANY]
14
15   make
16      local
17         root_window, sub_window: NCURSES_WINDOW
18      do
19         ncurses.enable
20         ncurses.set_cursor_visibility(ncurses.invisible_cursor_mode)
21         ncurses.set_echoing_policy(False)
22
23         root_window := ncurses.get_root_window
24         root_window.put_string("Press <down> and <up> to move in the list.")
25         root_window.put_string_at("Press <space> to (de)select the item", 0, 1)
26         root_window.put_string_at("Press 't' or 'T' to enable/disable multiple selection", 0, 2)
27         root_window.put_string_at("Press 'q' or 'Q' to quit", 0, 3)
28
29         sub_window := root_window.create_sub_window(4, 4, 22, 12)
30         sub_window.draw_border
31
32         create ncurses_list.make(sub_window, 1, 1, 20, 5)
33         ncurses_list.add_last("item 1", Void)
34         ncurses_list.add_last("item 2", Void)
35         ncurses_list.add_last("item 3", Void)
36         ncurses_list.add_last("item 4", Void)
37         ncurses_list.add_last("item 5", Void)
38
39         ncurses.when_key_pressed(agent key_press(?))
40         ncurses.start
41      end
42
43   key_press (key_code: INTEGER)
44      do
45         if key_code = key_down then
46            ncurses_list.set_focus_on((ncurses_list.focused + 1).min(ncurses_list.upper))
47         elseif key_code = key_up then
48            ncurses_list.set_focus_on((ncurses_list.focused - 1).max(ncurses_list.lower))
49         elseif key_code.to_character.to_upper = 'T' then
50            ncurses_list.allow_multiple_selection(not ncurses_list.is_multiple_selection_allowed)
51         elseif key_code = space then
52            if ncurses_list.is_selected(ncurses_list.focused) then
53               ncurses_list.deselect_item(ncurses_list.focused)
54            else
55               ncurses_list.select_item(ncurses_list.focused)
56            end
57         elseif key_code.to_character.to_upper = 'Q' then
58            ncurses.disable
59         end
60         if ncurses.is_enabled then
61            ncurses.get_root_window.redraw_now
62         end
63      end
64
65end -- class LIST