DRY ohai truncation

This commit is contained in:
Jack Nagel 2013-03-31 15:18:38 -05:00
parent 4cd95652ea
commit 7af5a74c4e

View File

@ -17,7 +17,12 @@ class Tty
`/usr/bin/tput cols`.strip.to_i
end
def truncate(str)
str.to_s[0, width - 4]
end
private
def color n
escape "0;#{n}"
end
@ -34,13 +39,13 @@ class Tty
end
def ohai title, *sput
title = title.to_s[0, Tty.width - 4] if $stdout.tty? && !ARGV.verbose?
title = Tty.truncate(title) if $stdout.tty? && !ARGV.verbose?
puts "#{Tty.blue}==>#{Tty.white} #{title}#{Tty.reset}"
puts sput unless sput.empty?
end
def oh1 title
title = title.to_s[0, Tty.width - 4] if $stdout.tty? && !ARGV.verbose?
title = Tty.truncate(title) if $stdout.tty? && !ARGV.verbose?
puts "#{Tty.green}==>#{Tty.white} #{title}#{Tty.reset}"
end