/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

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