Sha256: 34dc1c119ebd8505b7ac3f0d2da4b324e0f8ab88f420414b5acfa737f15a8aa2
Contents?: true
Size: 998 Bytes
Versions: 10
Compression:
Stored size: 998 Bytes
Contents
# frozen_string_literal: true module Gemdiff module Colorize COLORS = { red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, } # works with `git show` and `git diff` def colorize_git_output(lines) out = [] lines.split("\n").each do |line| out << 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 def colorize(string, color) "\e[#{to_color_code(color)}m#{string}\e[0m" end private def to_color_code(color) COLORS[color] || 30 end end end
Version data entries
10 entries across 10 versions & 1 rubygems