diff options
| author | Max Howell | 2009-10-15 14:42:19 +0100 |
|---|---|---|
| committer | Max Howell | 2009-10-15 16:51:58 +0100 |
| commit | 8ba0502a014ad2930887e53086156fd2cb49c51d (patch) | |
| tree | 96f1c7f94bc010024ed94e74db26a5604723a6cc /Library/Homebrew/utils.rb | |
| parent | d910c133273cfdea6a673efb8839d2f532c32057 (diff) | |
| download | homebrew-8ba0502a014ad2930887e53086156fd2cb49c51d.tar.bz2 | |
Put colors in Tty class
Changed format of Errors and Warnings slightly.
Diffstat (limited to 'Library/Homebrew/utils.rb')
| -rw-r--r-- | Library/Homebrew/utils.rb | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 6ce87f190..d6f1e401f 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -21,21 +21,44 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +class Tty + class <<self + def blue; bold 34; end + def white; bold 39; end + def red; underline 31; end + def yellow; underline 33 ; end + def reset; escape 0; end + + private + def color n + escape "0;#{n}" + end + def bold n + escape "1;#{n}" + end + def underline n + escape "4;#{n}" + end + def escape n + "\033[#{n}m" if $stdout.tty? + end + end +end + # args are additional inputs to puts until a nil arg is encountered def ohai title, *sput title = title[0, `/usr/bin/tput cols`.strip.to_i-4] unless ARGV.verbose? - puts "\033[0;34m==>\033[0;0;1m #{title}\033[0;0m" + puts "#{Tty.blue}==>#{Tty.white} #{title}#{Tty.reset}" puts *sput unless sput.empty? end -# shows a warning in delicious pink def opoo warning - puts "\033[1;35m==>\033[0;0;1m Warning!\033[0;0m #{warning}" + puts "#{Tty.red}Warning#{Tty.reset}: #{warning}" end def onoe error lines = error.to_s.split'\n' - puts "\033[1;31m==>\033[0;0;1m Error\033[0;0m: #{lines.shift}" + puts "#{Tty.red}Error#{Tty.reset}: #{lines.shift}" puts *lines unless lines.empty? end |
