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