class Omglog::Base
Constants
- CLEAR
- HIGHLIGHT
- LOG_CMD
- LOG_REGEX
- SHORTEST_MESSAGE
Public Class Methods
arrange_commit(commit, cols)
click to toggle source
# File lib/omglog.rb, line 59 def self.arrange_commit commit, cols commit[0].chomp!(' ') commit[-2].sub!(/(\d+)\s(\w)[^\s]+ ago/, '\1\2 ago') commit.each{|c| c.sub!(/\t/, ' ')} commit[-2].sub!(/^ (\w)\w+\s(\w).*,/, ' \1\2,') room = [cols - [commit[0].gsub(/\e\[[\d;]*m/, ''), commit[1..-2]].flatten.map(&:length).inject(&:+), SHORTEST_MESSAGE].max commit.tap {|commit| commit[-1, 0] = if commit[-1].length > room commit.pop[0...(room - 1)] + '…' else commit.pop.ljust(room) end } end
log_cmd()
click to toggle source
# File lib/omglog.rb, line 35 def self.log_cmd @log_cmd ||= [LOG_CMD].concat(ARGV).join(' ') end
render_commit(commit, cols)
click to toggle source
# File lib/omglog.rb, line 52 def self.render_commit commit, cols row_highlight = commit[2][/[^\/]HEAD\b/] ? HIGHLIGHT : YELLOW [nil, row_highlight, BLUE, '', GREY].map {|c| "\e[#{c}m" if c }.zip( arrange_commit(commit, cols) ).join + "\e[m" end
run()
click to toggle source
# File lib/omglog.rb, line 39 def self.run rows, cols = `tput lines; tput cols`.scan(/\d+/).map(&:to_i) `#{log_cmd} -#{rows}`.tap {|log| log_lines = Array.new(rows, '') log_lines.unshift *log.split("\n") print CLEAR + log_lines[0...(rows - 1)].map {|l| commit = l.scan(LOG_REGEX).flatten.map(&:to_s) commit.any? ? render_commit(commit, cols) : l }.join("\n") + "\n" + "\e[#{GREY}mupdated #{Time.now.strftime("%a %H:%M:%S")}\e[m ".rjust(cols + 8) } end