Class: Pra::CursesWindowSystem
- Inherits:
-
WindowSystem
- Object
- WindowSystem
- Pra::CursesWindowSystem
- Defined in:
- lib/pra/curses_window_system.rb
Constant Summary collapse
- ENTER_KEY =
10- ESC_KEY =
27- BACKSPACE_KEY =
127
Instance Method Summary collapse
- #fetch_failed ⇒ Object
- #fetching_pull_requests ⇒ Object
- #force_refresh ⇒ Object
- #force_refresh=(force_update) ⇒ Object
-
#initialize ⇒ CursesWindowSystem
constructor
A new instance of CursesWindowSystem.
- #last_updated ⇒ Object
- #refresh_pull_requests(pull_requests) ⇒ Object
- #run_loop ⇒ Object
- #setup ⇒ Object
Constructor Details
#initialize ⇒ CursesWindowSystem
Returns a new instance of CursesWindowSystem.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/pra/curses_window_system.rb', line 14 def initialize @selected_pull_request_page_index = 0 @current_page = 1 @current_pull_requests = [] @previous_number_of_pull_requests = 0 @last_updated = nil @state_lock = Mutex.new @last_updated_access_lock = Mutex.new @force_update = true @force_update_access_lock = Mutex.new @filter_mode = false @filter_string = "" end |
Instance Method Details
#fetch_failed ⇒ Object
62 63 64 |
# File 'lib/pra/curses_window_system.rb', line 62 def fetch_failed output_string(4, 0, "Failed to fetch pull requests on 1 or more pull sources. Check #{Pra::Config.log_path} for details.") end |
#fetching_pull_requests ⇒ Object
56 57 58 59 60 |
# File 'lib/pra/curses_window_system.rb', line 56 def fetching_pull_requests output_string(3, 0, "Fetching pull requests...") Curses.setpos(4,0) Curses.clrtoeol end |
#force_refresh ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/pra/curses_window_system.rb', line 36 def force_refresh do_force_update = false @force_update_access_lock.synchronize { do_force_update = @force_update } do_force_update end |
#force_refresh=(force_update) ⇒ Object
44 45 46 47 48 |
# File 'lib/pra/curses_window_system.rb', line 44 def force_refresh=(force_update) @force_update_access_lock.synchronize { @force_update = force_update } end |
#last_updated ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/pra/curses_window_system.rb', line 28 def last_updated current_last_updated = nil @last_updated_access_lock.synchronize { current_last_updated = @last_updated.dup } current_last_updated end |
#refresh_pull_requests(pull_requests) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/pra/curses_window_system.rb', line 66 def refresh_pull_requests(pull_requests) @previous_number_of_pull_requests = @current_pull_requests.length @state_lock.synchronize { @current_pull_requests = pull_requests.dup @last_updated = Time.now } draw_current_pull_requests end |
#run_loop ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/pra/curses_window_system.rb', line 76 def run_loop c = Curses.getch() while (c != 'q') do if @filter_mode case c when ESC_KEY @filter_mode = false @filter_string = "" Curses.setpos(5, 0) Curses.clrtoeol @current_pull_requests = @original_pull_requests.dup @original_pull_requests = nil draw_current_pull_requests when ENTER_KEY @filter_mode = false @filter_string = "" when "\b", BACKSPACE_KEY, Curses::KEY_BACKSPACE @filter_string.chop! output_string(5, 0, "Filter: #{@filter_string}") clear_pull_requests filter_current_pull_requests(@filter_string) when String @filter_string += c output_string(5, 0, "Filter: #{@filter_string}") clear_pull_requests filter_current_pull_requests(@filter_string) end else case c when 'j', Curses::Key::DOWN move_selection_down draw_current_pull_requests when 'k', Curses::Key::UP move_selection_up draw_current_pull_requests when 'r' @force_update = true Curses.setpos(5, 0) Curses.clrtoeol when 'o', ENTER_KEY @state_lock.synchronize { Launchy.open(@current_pull_requests[selected_pull_request_loc].link) } when 'n' load_next_page when 'p' load_prev_page when '/' @filter_mode = true @original_pull_requests = @current_pull_requests.dup output_string(5, 0, "Filter: #{@filter_string}") end end c = Curses.getch() end Curses.close_screen end |
#setup ⇒ Object
50 51 52 53 54 |
# File 'lib/pra/curses_window_system.rb', line 50 def setup initialize_screen_settings display_instructions output_string(3, 0, "0 Pull Requests") end |