Module: Gemdiff::Colorize
- Included in:
- CLI
- Defined in:
- lib/gemdiff/colorize.rb
Constant Summary collapse
- COLORS =
{ red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, }.freeze
Instance Method Summary collapse
- #colorize(string, color) ⇒ Object
-
#colorize_git_output(lines) ⇒ Object
works with ‘git show` and `git diff`.
Instance Method Details
#colorize(string, color) ⇒ Object
34 35 36 |
# File 'lib/gemdiff/colorize.rb', line 34 def colorize(string, color) "\e[#{to_color_code(color)}m#{string}\e[0m" end |
#colorize_git_output(lines) ⇒ Object
works with ‘git show` and `git diff`
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gemdiff/colorize.rb', line 15 def colorize_git_output(lines) out = lines.split("\n").map do |line| if line.start_with?("---", "+++", "diff", "index") colorize line, :blue elsif line.start_with?("@@") colorize line, :magenta elsif line.start_with?("commit") colorize line, :yellow elsif line.start_with?("-") colorize line, :red elsif line.start_with?("+") colorize line, :green else line end end out.join("\n") end |