/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

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