Class: Kronk::Diff::ColorFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/kronk/diff/color_format.rb

Overview

Format diff with ascii

Class Method Summary collapse

Class Method Details

.added(str) ⇒ Object



36
37
38
39
# File 'lib/kronk/diff/color_format.rb', line 36

def self.added str
  rm_color str
  "\033[1;32m+ #{str}\033[0m"
end

.common(str) ⇒ Object



42
43
44
# File 'lib/kronk/diff/color_format.rb', line 42

def self.common str
  "  #{str}"
end

.context(left, right, info = nil) ⇒ Object



15
16
17
# File 'lib/kronk/diff/color_format.rb', line 15

def self.context left, right, info=nil
  "\033[1;35m@@ -#{left} +#{right} @@\033[0m #{info}"
end

.deleted(str) ⇒ Object



30
31
32
33
# File 'lib/kronk/diff/color_format.rb', line 30

def self.deleted str
  rm_color str
  "\033[1;31m- #{str}\033[0m"
end

.head(left, right) ⇒ Object



10
11
12
# File 'lib/kronk/diff/color_format.rb', line 10

def self.head left, right
  ["\033[1;33m--- #{left}", "+++ #{right}\033[0m"]
end

.lines(line_nums, col_width) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/kronk/diff/color_format.rb', line 20

def self.lines line_nums, col_width
  out =
    [*line_nums].map do |lnum|
      lnum.to_s.rjust col_width
    end.join "\033[32m"

  "\033[7;31m#{out}\033[0m "
end

.rm_color(str) ⇒ Object



47
48
49
# File 'lib/kronk/diff/color_format.rb', line 47

def self.rm_color str
  str.gsub!(/\e\[[^m]+m/, '')
end