Class: GitCrecord::Diff::Difference
- Inherits:
-
Object
- Object
- GitCrecord::Diff::Difference
show all
- Defined in:
- lib/git_crecord/diff/difference.rb
Constant Summary
collapse
- SELECTED_MAP =
{
true => '[X] ',
false => '[ ] ',
:partly => '[~] '
}.freeze
- SELECTION_MARKER_WIDTH =
SELECTED_MAP[true].size
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Difference.
17
18
19
|
# File 'lib/git_crecord/diff/difference.rb', line 17
def initialize
@subs = []
end
|
Instance Attribute Details
#expanded ⇒ Object
Returns the value of attribute expanded.
6
7
8
|
# File 'lib/git_crecord/diff/difference.rb', line 6
def expanded
@expanded
end
|
#subs ⇒ Object
Returns the value of attribute subs.
8
9
10
|
# File 'lib/git_crecord/diff/difference.rb', line 8
def subs
@subs
end
|
#y1 ⇒ Object
Returns the value of attribute y1.
7
8
9
|
# File 'lib/git_crecord/diff/difference.rb', line 7
def y1
@y1
end
|
#y2 ⇒ Object
Returns the value of attribute y2.
7
8
9
|
# File 'lib/git_crecord/diff/difference.rb', line 7
def y2
@y2
end
|
Instance Method Details
#content_width(width) ⇒ Object
32
33
34
|
# File 'lib/git_crecord/diff/difference.rb', line 32
def content_width(width)
[1, width - x_offset - SELECTION_MARKER_WIDTH].max
end
|
#max_height(width) ⇒ Object
25
26
27
28
29
30
|
# File 'lib/git_crecord/diff/difference.rb', line 25
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) ⇒ Object
63
64
65
66
|
# File 'lib/git_crecord/diff/difference.rb', line 63
def prefix(line_number)
return SELECTED_MAP.fetch(selected) if line_number.zero? && selectable?
' ' * SELECTION_MARKER_WIDTH
end
|
#prefix_style(_is_highlighted) ⇒ Object
59
60
61
|
# File 'lib/git_crecord/diff/difference.rb', line 59
def prefix_style(_is_highlighted)
UI::Color.normal
end
|
#print(win, line_number, is_highlighted) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/git_crecord/diff/difference.rb', line 68
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? ⇒ Boolean
36
37
38
|
# File 'lib/git_crecord/diff/difference.rb', line 36
def selectable?
true
end
|
#selectable_subs ⇒ Object
40
41
42
|
# File 'lib/git_crecord/diff/difference.rb', line 40
def selectable_subs
@selectable_subs ||= subs.select(&:selectable?)
end
|
#selected ⇒ Object
44
45
46
47
48
|
# File 'lib/git_crecord/diff/difference.rb', line 44
def selected
s = selectable_subs.map(&:selected).uniq
return s[0] if s.size == 1
:partly
end
|
#selected=(value) ⇒ Object
50
51
52
|
# File 'lib/git_crecord/diff/difference.rb', line 50
def selected=(value)
selectable_subs.each{ |sub| sub.selected = value }
end
|
#strings(width) ⇒ Object
21
22
23
|
# File 'lib/git_crecord/diff/difference.rb', line 21
def strings(width)
to_s.scan(/.{1,#{content_width(width)}}/)
end
|
#style(is_highlighted) ⇒ Object
54
55
56
57
|
# File 'lib/git_crecord/diff/difference.rb', line 54
def style(is_highlighted)
return Curses::A_BOLD | UI::Color.hl if is_highlighted
Curses::A_BOLD | UI::Color.normal
end
|