/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

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