Sha256: c55fe5e9f2f6e6698e1bdd99f0b4aa37c837f5ac5665d870bf3a707a50b96ee0
Contents?: true
Size: 1.34 KB
Versions: 3
Compression:
Stored size: 1.34 KB
Contents
class SlimKeyfy::Console::Printer def self.difference(old_line, new_line, translations) puts "#{'-'.red} #{normalize(old_line).red}" puts "#{'+'.green} #{normalize(new_line).green} => #{translations.to_s.yellow}" puts "-"*40 end def self.unix_diff(bak_path, file_path) result = "Please install colordiff or diff (brew install colordiff)" colordiff, diff = `which colordiff`, `which diff` if not colordiff.empty? result = `colordiff #{bak_path} #{file_path}` elsif not diff.empty? result =`diff #{bak_path} #{file_path}` end if result.nil? or result.strip.empty? puts "No changes for comparison found!" else puts "#{result}" end end def self.normalize(line) line.sub(/^\s*/, " ") end def self.tag(old_line, translations, comment_tag) prettified_translations = translations.map{|k, v| "#{k}: #{v}, t('.#{k.split(".").last}')" }.join(" | ") "#{indentation(old_line)}#{comment_tag} #{prettified_translations}\n#{old_line}" end def self.indentation(line) return "" if line.nil? or line.empty? " " * (line.size - line.gsub(/^\s+/, "").size) end end class String def colorize(color_code) "\e[#{color_code}m#{self}\e[0m" end def red colorize(31) end def green colorize(32) end def yellow colorize(34) end def white colorize(37) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
slimkeyfy-0.1.0 | lib/slimkeyfy/console/printer.rb |
slimkeyfy-0.0.4 | lib/slimkeyfy/console/printer.rb |
slimkeyfy-0.0.3 | lib/slimkeyfy/console/printer.rb |