/tutorial/ncurses/progressbar.e

http://github.com/tybor/Liberty · Specman e · 64 lines · 53 code · 11 blank · 0 comment · 4 complexity · a95b083340727eed0c704586aac7c21e MD5 · raw file

  1. class PROGRESSBAR
  2. insert
  3. NCURSES_TOOLS
  4. NCURSES_KEYS
  5. NCURSES_COLORS
  6. create {}
  7. main
  8. feature {}
  9. progress_bar: NCURSES_PROGRESSBAR
  10. root_window, sub_window: NCURSES_WINDOW
  11. main
  12. do
  13. ncurses.enable
  14. ncurses.set_cursor_visibility(ncurses.invisible_cursor_mode)
  15. ncurses.set_echoing_policy(False)
  16. root_window := ncurses.get_root_window
  17. sub_window := root_window.create_sub_window(4, 4, root_window.width - 8, 3)
  18. create progress_bar.make(sub_window, 1, 1, root_window.width - 10, 0, 100)
  19. progress_bar.set_colors(yellow_color, blue_color)
  20. progress_bar.set_value(50)
  21. ncurses.when_resized(agent redraw)
  22. ncurses.when_key_pressed(agent key_press(?))
  23. redraw
  24. ncurses.start
  25. end
  26. redraw
  27. do
  28. root_window.put_string("Press <left> and <right> for slow changes.")
  29. root_window.put_string_at("Press <page down> and <page up> for fast changes.", 0, 1)
  30. root_window.put_string_at("Press 't' or 'T' to toggle value displaying", 0, 2)
  31. root_window.put_string_at("Press 'q' or 'Q' to quit", 0, 3)
  32. sub_window.draw_border
  33. root_window.redraw_now
  34. end
  35. key_press (key_code: INTEGER)
  36. do
  37. if key_code.to_character.to_upper = 'T' then
  38. progress_bar.display_value(not progress_bar.is_value_displayed)
  39. elseif key_code = key_left then
  40. progress_bar.set_value((progress_bar.current_value - 1).max(progress_bar.min_value))
  41. elseif key_code = key_right then
  42. progress_bar.set_value((progress_bar.current_value + 1).min(progress_bar.max_value))
  43. elseif key_code = key_previous_page then
  44. progress_bar.set_value((progress_bar.current_value - 10).max(progress_bar.min_value))
  45. elseif key_code = key_next_page then
  46. progress_bar.set_value((progress_bar.current_value + 10).min(progress_bar.max_value))
  47. end
  48. root_window.redraw_now
  49. if key_code.to_character.to_upper = 'Q' then
  50. ncurses.disable
  51. end
  52. end
  53. end -- class PROGRESSBAR