Class: GitCrecord::Diff::Line

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

Constant Summary

Constants inherited from Difference

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) ⇒ Line

Returns a new instance of Line.



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

def initialize(line)
  @line = line
  @selected = true
  super()
end

Instance Attribute Details

#selectedObject

Returns the value of attribute selected.



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

def selected
  @selected
end

Instance Method Details

#add?Boolean

Returns:

  • (Boolean)


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

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

#del?Boolean

Returns:

  • (Boolean)


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

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

#expandedObject



73
74
75
# File 'lib/git_crecord/diff/line.rb', line 73

def expanded
  false
end

#generate_diffObject



77
78
79
80
81
# File 'lib/git_crecord/diff/line.rb', line 77

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

#selectable?Boolean

Returns:

  • (Boolean)


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

def selectable?
  add? || del?
end

#style(is_highlighted) ⇒ Object



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

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



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

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

#x_offsetObject



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

def x_offset
  6
end