/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

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