Class: Pra::CursesWindowSystem

Inherits:
WindowSystem show all
Defined in:
lib/pra/curses_window_system.rb

Constant Summary collapse

ENTER_KEY =
10

Instance Method Summary collapse

Constructor Details

#initializeCursesWindowSystem

Returns a new instance of CursesWindowSystem.



12
13
14
15
16
17
# File 'lib/pra/curses_window_system.rb', line 12

def initialize
  @selected_pull_request_index = 0
  @current_pull_requests = []
  @previous_number_of_pull_requests = 0
  @state_lock = Mutex.new
end

Instance Method Details

#fetch_failedObject



31
32
33
# File 'lib/pra/curses_window_system.rb', line 31

def fetch_failed
  output_string(4, 0, "Failed to fetch pull requests on 1 or more pull sources. Check #{Pra::Config.error_log_path} for details.")
end

#fetching_pull_requestsObject



25
26
27
28
29
# File 'lib/pra/curses_window_system.rb', line 25

def fetching_pull_requests
  output_string(3, 0, "Fetching pull requests...")
  Curses.setpos(4,0)
  Curses.clrtoeol
end

#refresh_pull_requests(pull_requests) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/pra/curses_window_system.rb', line 35

def refresh_pull_requests(pull_requests)
  @previous_number_of_pull_requests = @current_pull_requests.length

  @state_lock.synchronize {
    @current_pull_requests = pull_requests.dup
  }
  draw_current_pull_requests
end

#run_loopObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/pra/curses_window_system.rb', line 44

def run_loop
  c = Curses.getch()
  while (c != 'q') do
    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 'o', ENTER_KEY
      @state_lock.synchronize {
        Launchy.open(@current_pull_requests[@selected_pull_request_index].link)
      }
    end
    c = Curses.getch()
  end

  Curses.close_screen
end

#setupObject



19
20
21
22
23
# File 'lib/pra/curses_window_system.rb', line 19

def setup
  initialize_screen_settings
  display_instructions
  output_string(3, 0, "0 Pull Requests")
end