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

/tutorial/ncurses/hello.e

http://github.com/tybor/Liberty
Specman e | 49 lines | 38 code | 7 blank | 4 comment | 1 complexity | 126d18b874dbf9f0d1e2153ab79fecec MD5 | raw file
 1class HELLO
 2   --
 3   -- Basic example to start with NCURSES.
 4   --
 5
 6insert
 7   NCURSES_TOOLS
 8
 9create {}
10   main
11
12feature {}
13   main
14      local
15         root_window: NCURSES_WINDOW
16      do
17         std_output.put_string("Leaving the normal terminal mode...%N")
18         ncurses.enable
19         ncurses.set_cursor_visibility(default_visible_cursor_mode)
20
21         root_window := ncurses.get_root_window
22         root_window.put_string("Hello world!")
23         root_window.put_string_at("Q or q to quit.", 0, 2)
24         ncurses.when_key_pressed(agent key_press(?))
25         ncurses.start
26         -- At the end, the terminal is reset in its normal state:
27         std_output.put_string("...normal terminal mode restored.%N")
28      end
29
30   key_press (key_code: INTEGER)
31      local
32         root_window: NCURSES_WINDOW
33      do
34         root_window := ncurses.get_root_window
35         root_window.put_string_at("Press any key: ", 0, 1)
36         root_window.put_string(once " (key code = " + key_code.to_string + once ")")
37         if key_code.to_character.to_upper = 'Q' then
38            ask_quit := True
39            root_window.put_string_at("Really quit (y/n)?", 0, 3)
40         elseif ask_quit = True and then key_code.to_character.to_upper = 'Y' then
41            ncurses.disable
42         else
43            ask_quit := False
44         end
45      end
46
47   ask_quit: BOOLEAN
48
49end -- class HELLO