Module: Holdify::Feedback::Color::GitDiff

Defined in:
lib/holdify/feedback.rb

Overview

Methods enabling the git-diff ANSI feedback

Instance Method Summary collapse

Instance Method Details

#git_commandObject



153
154
155
156
157
# File 'lib/holdify/feedback.rb', line 153

def git_command
  # Words/ruby entities | indent | other single-chars
  re = '[[:alnum:]_:]+|[[:space:]]+|.'
  "git diff --no-index --color-words='#{re}' --unified=1000 #{@exp_path} #{@act_path}"
end

#render_line(line, lineno, width) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/holdify/feedback.rb', line 159

def render_line(line, lineno, width)
  clean       = line.strip
  type, color = case
                when clean.start_with?(SGR[:green]) && !line.include?(SGR[:red]) && clean.end_with?(SGR[:clear], "\e[m")
                  ['+', :green]
                when clean.start_with?(SGR[:red]) && !line.include?(SGR[:green]) && clean.end_with?(SGR[:clear], "\e[m")
                  ['-', :red]
                when line.include?(SGR[:red]) || line.include?(SGR[:green])
                  ['~', :yellow]
                else
                  [' ', :none]
                end

  gutter = if type == '+'
             ' ' * width
           else
             lineno[0] += 1
             lineno[0].to_s.rjust(width)
           end

  "#{dye(color, "#{type}#{gutter}")} #{line}"
end