Put colors in Tty class
Changed format of Errors and Warnings slightly.
This commit is contained in:
parent
543a113712
commit
8eb97a7db5
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user