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 collapse

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, #strings

Constructor Details

#initialize(line, reverse: false) ⇒ Line

Returns a new instance of Line.



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

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

Instance Attribute Details

#selectedObject

Returns the value of attribute selected.



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

def selected
  @selected
end

Instance Method Details

#add?Boolean

Returns:

  • (Boolean)


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

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

#del?Boolean

Returns:

  • (Boolean)


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

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

#expandedObject



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

def expanded
  false
end

#generate_diffObject



79
80
81
82
83
84
# File 'lib/git_crecord/diff/line.rb', line 79

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

  nil
end

#selectable?Boolean

Returns:

  • (Boolean)


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

def selectable?
  add? || del?
end

#style(is_highlighted) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/git_crecord/diff/line.rb', line 86

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



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

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

#x_offsetObject



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

def x_offset
  6
end