class GitSpelunk::UI::PagerWindow
Constants
- ACTIVE_SHA_COLOR
- CURRENT_COLOR
- FOUND_COLOR
Attributes
cursor[R]
data[RW]
highlight_sha[RW]
search_term[RW]
top[RW]
Public Class Methods
new(height)
click to toggle source
# File lib/git_spelunk/ui/pager.rb, line 9 def initialize(height) @height = height @cursor = 1 @top = 1 @highlight_sha = true end
Public Instance Methods
adjust_top!()
click to toggle source
# File lib/git_spelunk/ui/pager.rb, line 158 def adjust_top! if @top < 1 @top = 1 end if @top > @cursor @top = @cursor end while @cursor > bufbottom @top += 1 end end
blame_line()
click to toggle source
# File lib/git_spelunk/ui/pager.rb, line 19 def blame_line @data[@cursor - 1] end
bufbottom()
click to toggle source
# File lib/git_spelunk/ui/pager.rb, line 98 def bufbottom @top + (@height - 1) end
cursordown()
click to toggle source
# File lib/git_spelunk/ui/pager.rb, line 108 def cursordown return if @cursor >= data.size @cursor += 1 adjust_top! end
cursorup()
click to toggle source
# File lib/git_spelunk/ui/pager.rb, line 102 def cursorup return if @cursor == 1 @cursor -= 1 adjust_top! end
draw()
click to toggle source
# File lib/git_spelunk/ui/pager.rb, line 23 def draw styles = Dispel::StyleMap.new(@height) line_number_width = (data.size + 1).to_s.size active_sha = blame_line.sha view = Array.new(@height) data[@top - 1, @height].each_with_index do |b, i| line = "" sha, content = b.sha, b.content line_number = i + @top if sha == active_sha && highlight_sha styles.add(ACTIVE_SHA_COLOR, i, 0...999) end sha_abbrev = sha[0..5] if @cursor == line_number styles.add(CURRENT_COLOR, i, 0..(sha_abbrev.size - 1)) end line << sha_abbrev line << " %*s " % [line_number_width, line_number] line << content.gsub(/\r/, '') content_start = (sha_abbrev.size + line_number_width + 2) if @search_term Dispel::Tools.indexes(content, @search_term).each do |found| found = content_start + found styles.add(FOUND_COLOR, i, found...(found + @search_term.size)) end end view[i] = line end [view, styles] end
find_next_index(term, start, reverse)
click to toggle source
returns position in data set, not cursor position
# File lib/git_spelunk/ui/pager.rb, line 69 def find_next_index(term, start, reverse) i = start while i < data.size && i >= 0 if data[i].content =~ /#{term}/ return i end i += reverse ? -1 : 1 end nil end
go_bottom()
click to toggle source
# File lib/git_spelunk/ui/pager.rb, line 153 def go_bottom @cursor = data.size @top = data.size - (@height - 1) end
go_to(l)
click to toggle source
# File lib/git_spelunk/ui/pager.rb, line 140 def go_to(l) if l > @data.size l = @data.size elsif l < 1 l = 1 end previous_offset = @cursor - @top @cursor = l @top = @cursor - previous_offset adjust_top! end
go_top()
click to toggle source
# File lib/git_spelunk/ui/pager.rb, line 136 def go_top @top = @cursor = 1 end
pagedown()
click to toggle source
# File lib/git_spelunk/ui/pager.rb, line 125 def pagedown previous_offset = @cursor - @top @cursor += @height / 2 if @cursor > data.size @cursor = data.size end @top = @cursor - previous_offset adjust_top! end
pageup()
click to toggle source
# File lib/git_spelunk/ui/pager.rb, line 114 def pageup previous_offset = @cursor - @top @cursor -= @height / 2 if @cursor < 1 @cursor = 1 end @top = @cursor - previous_offset adjust_top! end
search(term, skip_current_line, reverse)
click to toggle source
# File lib/git_spelunk/ui/pager.rb, line 80 def search(term, skip_current_line, reverse) if term @search_term = term else term = @search_term # nil indicates 'use-last-term' end search_from = @cursor - 1 if skip_current_line search_from += reverse ? -1 : 1 end p = find_next_index(term, search_from, reverse) || find_next_index(term, reverse ? data.size - 1 : 0, reverse) go_to(p + 1) if p end