PageRenderTime 13ms CodeModel.GetById 11ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/ncurses/panel.e

http://github.com/tybor/Liberty
Specman e | 78 lines | 57 code | 14 blank | 7 comment | 3 complexity | dab5614de9757f0b8bc3f42e8a029c08 MD5 | raw file
 1class PANEL
 2   --
 3   -- Playing with the PANEL widget.
 4   --
 5
 6insert
 7   NCURSES_TOOLS
 8   NCURSES_KEYS
 9
10create {}
11   main
12
13feature {ANY}
14   ncurses_panel: NCURSES_PANEL
15
16   tabs: FAST_ARRAY[NCURSES_PANELTAB]
17
18   active_tab: INTEGER
19
20   main
21      local
22         root_window, sub_window: NCURSES_WINDOW; labels: FAST_ARRAY[NCURSES_LABEL]
23      do
24         ncurses.enable
25         ncurses.set_cursor_visibility(invisible_cursor_mode)
26
27         root_window := ncurses.get_root_window
28         root_window.put_string("Press <left> and <right> to change the active tab.%NQ or q to Quit")
29
30         sub_window := root_window.create_sub_window(4, 2, 40, 6)
31         sub_window.draw_border
32         -- We create a NCURSES_PANEL that fits inside the `sub_window' (beware of the border):
33         create ncurses_panel.make(sub_window, 1, 1, sub_window.width - 2, sub_window.height - 2)
34         --create ncurses_panel.no_tabs(sub_window, 1, 1, sub_window.width - 2, sub_window.height - 2)
35         -- We create three tabs in this ncurses_panel:
36
37         create tabs.with_capacity(3)
38         tabs.add_last(ncurses_panel.add_tab("Tic"))
39         tabs.add_last(ncurses_panel.add_tab("Tac"))
40         tabs.add_last(ncurses_panel.add_tab("Toe"))
41         if tabs.exists(agent (t: NCURSES_PANELTAB): BOOLEAN then t = Void end (?)) then
42            ncurses.disable
43            std_error.put_line("Could not create tabs!!")
44            die_with_code(0)
45         end
46         -- In each tab, we create a label:
47         create labels.with_capacity(3)
48         labels.add_last(create {NCURSES_LABEL}.make(tabs.item(0), "Tic Panel 0 (first)", 2, 3, 25, 1))
49         labels.add_last(create {NCURSES_LABEL}.make(tabs.item(1), "Tac Panel 1 (middle)", 2, 3, 25, 1))
50         labels.add_last(create {NCURSES_LABEL}.make(tabs.item(2), "Toe Panel 2 (last)", 2, 3, 25, 1))
51
52         activate_tab(tabs.lower)
53
54         ncurses.when_key_pressed(agent key_press(?))
55         ncurses.start
56      end
57
58   key_press (key: INTEGER)
59      do
60         if key = key_left and then active_tab > tabs.lower then
61            activate_tab(active_tab - 1)
62         elseif key = key_right and then active_tab < tabs.upper then
63            activate_tab(active_tab + 1)
64         elseif key.to_character.to_upper = 'Q' then
65            ncurses.disable
66         end
67      end
68
69   activate_tab (tab: like active_tab)
70      do
71         if active_tab /= tab then
72            active_tab := tab
73            tabs.item(active_tab).raise
74            ncurses.get_root_window.redraw_now
75         end
76      end
77
78end -- class PANEL