Module: GitCrecord::UI

Defined in:
lib/git_crecord/ui.rb,
lib/git_crecord/ui/color.rb,
lib/git_crecord/ui/help_window.rb,
lib/git_crecord/ui/hunks_window.rb

Defined Under Namespace

Modules: Color, HelpWindow Classes: HunksWindow

Constant Summary collapse

ACTIONS =
{
  'q' => :quit,
  's' => :stage,
  'c' => :commit,
  'j' => :highlight_next,
  Curses::KEY_DOWN => :highlight_next,
  'k' => :highlight_previous,
  Curses::KEY_UP => :highlight_previous,
  'h' => :collapse,
  Curses::KEY_LEFT => :collapse,
  'l' => :expand,
  Curses::KEY_RIGHT => :expand,
  'f' => :toggle_fold,
  'g' => :highlight_first,
  'G' => :highlight_last,
  ''.ord => :highlight_next_hunk,
  ''.ord => :highlight_previous_hunk,
  ' ' => :toggle_selection,
  'A' => :toggle_all_selections,
  '?' => :help_window,
  'R' => :redraw,
  Curses::KEY_RESIZE => :resize
}.freeze

Class Method Summary collapse

Class Method Details

.run(files) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/git_crecord/ui.rb', line 33

def self.run(files)
  Curses.init_screen.keypad = true
  Color.init
  Curses.clear
  Curses.noecho
  Curses.curs_set(0)
  pad = Curses::Pad.new(1, 1).tap { |p| p.keypad = true }
  run_loop(HunksWindow.new(pad, files))
ensure
  Curses.close_screen
end

.run_loop(win) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/git_crecord/ui.rb', line 45

def self.run_loop(win)
  loop do
    c = win.getch
    next if ACTIONS[c].nil?

    quit = win.send(ACTIONS[c])
    break quit if quit == :quit
  end
end