Module: Gglog::CommitMessageDecorator

Defined in:
lib/gglog/commit_message_decorator.rb

Instance Method Summary collapse

Instance Method Details

#char_display_width(char) ⇒ Object



21
22
23
# File 'lib/gglog/commit_message_decorator.rb', line 21

def char_display_width(char)
  char.bytesize == 1 ? 1 : 2
end

#displayObject



6
7
8
9
10
11
12
13
14
15
# File 'lib/gglog/commit_message_decorator.rb', line 6

def display
  first_line_display_width = 70
  if string_display_width(first_line) < first_line_display_width
    body = sprintf("%-#{first_line_display_width}s", first_line)
  else
    body = first_line[0..(first_line_display_width-5)]+" ..."
  end
  prefix = sprintf("%50s", "#{File.basename(repository)} #{sha}".color("333333"))
  "  #{body} #{prefix}"
end

#string_display_width(string) ⇒ Object



17
18
19
# File 'lib/gglog/commit_message_decorator.rb', line 17

def string_display_width(string)
  string.each_char.map{|char| char_display_width(char) }.inject(0, &:+)
end