class GitCrecord::Diff::Difference
Constants
- REVERSE_SELECTED_MAP
- SELECTED_MAP
- SELECTION_MARKER_WIDTH
Attributes
expanded[RW]
subs[R]
y1[RW]
y2[RW]
Public Class Methods
new(reverse: false)
click to toggle source
# File lib/git_crecord/diff/difference.rb, line 26 def initialize(reverse: false) @reverse = reverse @selection_marker_map = reverse ? REVERSE_SELECTED_MAP : SELECTED_MAP @subs = [] @selected = true end
Public Instance Methods
content_width(width)
click to toggle source
# File lib/git_crecord/diff/difference.rb, line 44 def content_width(width) [1, width - x_offset - SELECTION_MARKER_WIDTH].max end
max_height(width)
click to toggle source
# File lib/git_crecord/diff/difference.rb, line 37 def max_height(width) width = content_width(width) ((to_s.size - 1).abs / width) + 1 + subs.reduce(0) do |a, e| a + e.max_height(width) end end
prefix(line_number)
click to toggle source
# File lib/git_crecord/diff/difference.rb, line 83 def prefix(line_number) show_selection_marker = line_number.zero? && selectable? return @selection_marker_map.fetch(selected) if show_selection_marker ' ' * SELECTION_MARKER_WIDTH end
prefix_style(_is_highlighted)
click to toggle source
# File lib/git_crecord/diff/difference.rb, line 79 def prefix_style(_is_highlighted) UI::Color.normal end
print(win, line_number, is_highlighted)
click to toggle source
# File lib/git_crecord/diff/difference.rb, line 90 def print(win, line_number, is_highlighted) @y1 = line_number + 1 prefix_style = prefix_style(is_highlighted) style = style(is_highlighted) strings(win.width).each_with_index do |string, index| win.addstr(' ' * x_offset, line_number += 1, attr: prefix_style) win.addstr(prefix(index), attr: prefix_style) win.addstr(string, attr: style, fill: ' ') end @y2 = line_number end
selectable?()
click to toggle source
# File lib/git_crecord/diff/difference.rb, line 48 def selectable? true end
selectable_subs()
click to toggle source
# File lib/git_crecord/diff/difference.rb, line 52 def selectable_subs @selectable_subs ||= subs.select(&:selectable?) end
selected()
click to toggle source
# File lib/git_crecord/diff/difference.rb, line 56 def selected return @selected if selectable_subs.empty? s = selectable_subs.map(&:selected).uniq return s[0] if s.size == 1 :partly end
selected=(value)
click to toggle source
# File lib/git_crecord/diff/difference.rb, line 65 def selected=(value) if selectable_subs.empty? @selected = value else selectable_subs.each { |sub| sub.selected = value } end end
strings(width)
click to toggle source
# File lib/git_crecord/diff/difference.rb, line 33 def strings(width) to_s.scan(/.{1,#{content_width(width)}}/) end
style(is_highlighted)
click to toggle source
# File lib/git_crecord/diff/difference.rb, line 73 def style(is_highlighted) return Curses::A_BOLD | UI::Color.hl if is_highlighted Curses::A_BOLD | UI::Color.normal end