aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2013-03-31 15:18:38 -0500
committerJack Nagel2013-03-31 15:18:38 -0500
commit7af5a74c4e3d1de334e3d38329243c50adeb342f (patch)
tree7e6ad7b8275fad5af6c708c81f7ff4cd0289eb53 /Library
parent4cd95652ead8923331dd2f5ec0c28b45527cca52 (diff)
downloadbrew-7af5a74c4e3d1de334e3d38329243c50adeb342f.tar.bz2
DRY ohai truncation
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/utils.rb13
1 files changed, 9 insertions, 4 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index ddcdc1aab..2879e6a11 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -3,7 +3,7 @@ require 'exceptions'
require 'macos'
class Tty
- class <<self
+ class << self
def blue; bold 34; end
def white; bold 39; end
def red; underline 31; end
@@ -17,7 +17,12 @@ class Tty
`/usr/bin/tput cols`.strip.to_i
end
- private
+ 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