Module: RuVim::Lang::Diff

Defined in:
lib/ruvim/lang/diff.rb

Constant Summary collapse

ADD_COLOR =

green

"\e[32m"
DELETE_COLOR =

red

"\e[31m"
HUNK_COLOR =

cyan

"\e[36m"
HEADER_COLOR =

bold

"\e[1m"
META_COLOR =

yellow

"\e[33m"

Class Method Summary collapse

Class Method Details

.color_columns(text) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/ruvim/lang/diff.rb', line 14

def color_columns(text)
  cols = {}
  color = line_color(text)
  return cols unless color

  text.length.times { |i| cols[i] = color }
  cols
end

.line_color(text) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ruvim/lang/diff.rb', line 23

def line_color(text)
  return nil if text.empty?

  case text
  when /\A@@/
    HUNK_COLOR
  when /\Adiff /
    HEADER_COLOR
  when /\A\+/
    ADD_COLOR
  when /\A-/
    DELETE_COLOR
  when /\Aindex /, /\Anew file/, /\Adeleted file/, /\Arename/, /\Asimilarity/
    META_COLOR
  end
end