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 `/usr/bin/tput cols`.strip.to_i
end end
def truncate(str)
str.to_s[0, width - 4]
end
private private
def color n def color n
escape "0;#{n}" escape "0;#{n}"
end end
@ -34,13 +39,13 @@ class Tty
end end
def ohai title, *sput 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 "#{Tty.blue}==>#{Tty.white} #{title}#{Tty.reset}"
puts sput unless sput.empty? puts sput unless sput.empty?
end end
def oh1 title 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}" puts "#{Tty.green}==>#{Tty.white} #{title}#{Tty.reset}"
end end