Class: GitCrecord::Diff::Line

Inherits:
Difference show all
Defined in:
lib/git_crecord/diff/line.rb

Constant Summary

Constants inherited from Difference

Difference::REVERSE_SELECTED_MAP, Difference::SELECTED_MAP, Difference::SELECTION_MARKER_WIDTH

Instance Attribute Summary

Attributes inherited from Difference

#subs, #y1, #y2

Instance Method Summary collapse

Methods inherited from Difference

#content_width, #max_height, #prefix, #prefix_style, #print, #selectable_subs, #selected, #strings

Constructor Details

#initialize(line, reverse: false) ⇒ Line

Returns a new instance of Line.



41
42
43
44
# File 'lib/git_crecord/diff/line.rb', line 41

def initialize(line, reverse: false)
  @line = line
  super(reverse: reverse)
end

Instance Method Details

#add?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/git_crecord/diff/line.rb', line 54

def add?
  @line.start_with?('+')
end

#del?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/git_crecord/diff/line.rb', line 58

def del?
  @line.start_with?('-')
end

#expandedObject



70
71
72
# File 'lib/git_crecord/diff/line.rb', line 70

def expanded
  false
end

#generate_diffObject



74
75
76
77
78
79
# File 'lib/git_crecord/diff/line.rb', line 74

def generate_diff
  return " #{@line[1..-1]}" if !selected && del?
  return @line if selected

  nil
end

#selectable?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/git_crecord/diff/line.rb', line 62

def selectable?
  add? || del?
end

#selected=(value) ⇒ Object



66
67
68
# File 'lib/git_crecord/diff/line.rb', line 66

def selected=(value)
  @selected = selectable? ? value : selected
end

#style(is_highlighted) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/git_crecord/diff/line.rb', line 81

def style(is_highlighted)
  return UI::Color.hl if is_highlighted
  return UI::Color.green if add?
  return UI::Color.red if del?

  UI::Color.normal
end

#to_sObject



46
47
48
# File 'lib/git_crecord/diff/line.rb', line 46

def to_s
  @to_s ||= @line.gsub(/\t/, Git.tab)
end

#x_offsetObject



50
51
52
# File 'lib/git_crecord/diff/line.rb', line 50

def x_offset
  6
end