git_spelunk 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,31 +5,17 @@ module GitSpelunk
5
5
  @window = Curses::Window.new(height, Curses.cols, offset, 0)
6
6
  @offset = offset
7
7
  @height = height
8
- @command_mode = false
9
- @command_buffer = ""
10
8
  @content = ""
11
9
  end
12
10
 
13
11
  attr_accessor :content, :command_mode, :command_buffer
14
12
 
15
- def exit_command_mode!
16
- self.command_buffer = ""
17
- self.command_mode = false
18
- end
19
-
20
13
  def draw
21
14
  @window.setpos(0,0)
22
15
  draw_status_line
23
16
  @window.addstr(@content + "\n") if content
24
17
  @window.addstr("\n" * (@height - @content.split("\n").size - 2))
25
-
26
- draw_bottom_line
27
18
  @window.refresh
28
- set_cursor
29
- end
30
-
31
- def set_cursor
32
- Curses::stdscr.setpos(@offset + @height - 1, command_buffer.size + 1)
33
19
  end
34
20
 
35
21
  def draw_status_line
@@ -40,17 +26,6 @@ module GitSpelunk
40
26
  @window.addstr(" " * line_remainder + "\n")
41
27
  end
42
28
  end
43
-
44
- def draw_bottom_line
45
- if command_mode
46
- @window.addstr(":" + command_buffer)
47
- @window.addstr(" " * line_remainder)
48
- else
49
- with_highlighting do
50
- @window.addstr(" " * line_remainder + "\n")
51
- end
52
- end
53
- end
54
29
  end
55
30
  end
56
31
  end
@@ -0,0 +1,37 @@
1
+ module GitSpelunk
2
+ class UI
3
+ class StatusWindow < Window
4
+ def initialize(height, offset)
5
+ @window = Curses::Window.new(height, Curses.cols, offset, 0)
6
+ @offset = offset
7
+ @command_buffer = ""
8
+ end
9
+
10
+ attr_accessor :command_buffer
11
+
12
+ def exit_command_mode!
13
+ self.command_buffer = ""
14
+ end
15
+
16
+ def set_cursor
17
+ Curses::stdscr.setpos(@offset, command_buffer.size + 1)
18
+ end
19
+
20
+ def draw
21
+ @window.setpos(0,0)
22
+ if !command_buffer.empty?
23
+ Curses.curs_set(1)
24
+ @window.addstr(":" + command_buffer)
25
+ @window.addstr(" " * line_remainder)
26
+ else
27
+ Curses.curs_set(0)
28
+ with_highlighting do
29
+ @window.addstr(" " * line_remainder + "\n")
30
+ end
31
+ end
32
+ set_cursor
33
+ @window.refresh
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,43 +1,50 @@
1
1
  require 'git_spelunk/ui/window'
2
2
  require 'git_spelunk/ui/pager'
3
3
  require 'git_spelunk/ui/repo'
4
+ require 'git_spelunk/ui/status'
4
5
  require 'curses'
5
6
 
6
7
  module GitSpelunk
7
8
  class UI
8
-
9
9
  def initialize(file_context)
10
- Curses.init_screen
11
- Curses.start_color
12
- Curses.raw
13
- Curses.nonl
14
- Curses.curs_set(2)
15
- screen = Curses.stdscr
16
- screen.refresh
17
- screen.keypad(1)
18
- Curses.init_pair(ACTIVE_SHA_COLOR, Curses::COLOR_GREEN, Curses::COLOR_BLACK)
10
+ init_curses
19
11
 
20
12
  calculate_heights!
21
13
  @file_context = file_context
22
14
  @history = [file_context]
15
+
23
16
  @pager = PagerWindow.new(@pager_height)
24
17
  @pager.data = @file_context.get_blame
25
18
 
26
19
  @repo = RepoWindow.new(@repo_height, @pager_height)
20
+
21
+ @status = StatusWindow.new(1, Curses.lines - 1)
22
+ end
23
+
24
+ def init_curses
25
+ Curses.init_screen
26
+ Curses.start_color
27
+ Curses.raw
28
+ Curses.nonl
29
+ Curses.noecho
30
+ Curses.curs_set(0)
31
+ screen = Curses.stdscr
32
+ screen.refresh
33
+ screen.keypad(1)
34
+ Curses.init_pair(ACTIVE_SHA_COLOR, Curses::COLOR_GREEN, Curses::COLOR_BLACK)
27
35
  end
28
36
 
29
37
  def calculate_heights!
30
38
  @repo_height = (Curses.lines.to_f * 0.20).to_i
31
- @pager_height = Curses.lines - @repo_height
39
+ @pager_height = Curses.lines - @repo_height - 1
40
+ @status_height = 1
32
41
  end
33
42
 
34
43
  def run
35
44
  @repo.content = @file_context.get_line_commit_info(@pager.cursor)
36
45
  pause_thread
37
46
  begin
38
- @pager.draw
39
- @repo.draw
40
- @repo.set_cursor
47
+ [@pager, @repo, @status].each(&:draw)
41
48
  handle_key(Curses.getch)
42
49
  end while true
43
50
  end
@@ -52,6 +59,7 @@ module GitSpelunk
52
59
  if heartbeat_expired? && @pager.cursor == current_line
53
60
  @repo.content = content
54
61
  @repo.draw
62
+ @status.draw
55
63
  @last_line = current_line
56
64
  else
57
65
  @heartbeat = Time.now
@@ -68,7 +76,7 @@ module GitSpelunk
68
76
 
69
77
  def after_navigation
70
78
  @pager.highlight_sha = true
71
- @repo.exit_command_mode!
79
+ @status.exit_command_mode!
72
80
  end
73
81
 
74
82
  def handle_key(key)
@@ -87,16 +95,15 @@ module GitSpelunk
87
95
  @pager.pageup
88
96
  after_navigation
89
97
  when *(0..9).to_a.map(&:to_s)
90
- @repo.command_mode = true
91
- @repo.command_buffer += key
98
+ @status.command_buffer += key
92
99
  when Curses::KEY_CTRL_M
93
- if @repo.command_buffer != ''
94
- @pager.go_to(@repo.command_buffer.to_i)
100
+ if @status.command_buffer != ''
101
+ @pager.go_to(@status.command_buffer.to_i)
95
102
  end
96
103
  after_navigation
97
104
  when 'G'
98
- if @repo.command_buffer != ''
99
- @pager.go_to(@repo.command_buffer.to_i)
105
+ if @status.command_buffer != ''
106
+ @pager.go_to(@status.command_buffer.to_i)
100
107
  else
101
108
  @pager.go_bottom
102
109
  end
@@ -120,6 +127,7 @@ module GitSpelunk
120
127
  @pager.data = @file_context.get_blame
121
128
  @pager.go_to(@file_context.line_number)
122
129
  @pager.draw
130
+ @status.draw
123
131
 
124
132
  # force commit info update
125
133
  @last_line = nil
@@ -130,22 +138,18 @@ module GitSpelunk
130
138
  Curses.close_screen
131
139
  system("git -p --git-dir='#{@file_context.repo.path}' show #{sha} | less")
132
140
  Curses.stdscr.refresh
133
- @pager.draw
134
- @repo.draw
135
- @pager.highlight_sha = true
141
+ [@pager, @repo, @status].each(&:draw)
136
142
  when '/'
137
- @repo.command_mode = true
138
- @repo.command_buffer = '/'
139
- @repo.draw
140
- @repo.set_cursor
141
- begin
142
- line = Curses.getstr
143
- rescue Interrupt
144
- @repo.exit_command_mode!
143
+ @heartbeat = nil
144
+ @status.command_buffer = '/'
145
+ @status.draw
146
+
147
+ line = getline
148
+ if line
149
+ @search_string = line
150
+ @pager.search(@search_string, false)
145
151
  end
146
- @search_string = line
147
- @pager.search(@search_string, false)
148
- @repo.exit_command_mode!
152
+ @status.exit_command_mode!
149
153
  when 'n'
150
154
  @pager.search(@search_string, true)
151
155
  after_navigation
@@ -153,6 +157,29 @@ module GitSpelunk
153
157
  exit
154
158
  end
155
159
  end
160
+
161
+ # you'd really think there was a better way
162
+ def getline
163
+ while ch = Curses.getch
164
+ case ch
165
+ when Curses::KEY_CTRL_C
166
+ @status.command_buffer = ''
167
+ return
168
+ when Curses::KEY_CTRL_M
169
+ return @status.command_buffer[1..-1]
170
+ when Curses::KEY_BACKSPACE, Curses::KEY_CTRL_H, 127
171
+ if @status.command_buffer == "/"
172
+ return
173
+ end
174
+ @status.command_buffer.chop!
175
+ else
176
+ if ch.is_a?(String)
177
+ @status.command_buffer += ch
178
+ end
179
+ end
180
+ @status.draw
181
+ end
182
+ end
156
183
  end
157
184
  end
158
185
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_spelunk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -42,6 +42,7 @@ files:
42
42
  - lib/git_spelunk/offset.rb
43
43
  - lib/git_spelunk/ui/pager.rb
44
44
  - lib/git_spelunk/ui/repo.rb
45
+ - lib/git_spelunk/ui/status.rb
45
46
  - lib/git_spelunk/ui/window.rb
46
47
  - lib/git_spelunk/ui.rb
47
48
  - lib/git_spelunk.rb