Created
February 23, 2011 21:35
-
-
Save mkhl/841231 to your computer and use it in GitHub Desktop.
Generate ANSI escape sequences.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -w | |
# Usage: ansicolor attr... [-- string...] | |
# Generate ANSI escape sequences. | |
# With string arguments, print them on stdout, | |
# followed by a `clear' escape sequence. | |
begin | |
require 'term/ansicolor' | |
rescue LoadError | |
require 'rubygems' | |
require 'term/ansicolor' | |
end | |
def run(attrs, echos = nil) | |
begin | |
out = attrs.collect { |a| Term::ANSIColor.send a.to_sym } | |
out << echos.join(" ") << Term::ANSIColor.clear << "\n" if echos | |
print out | |
rescue NoMethodError => err | |
puts "#{File.basename($PROGRAM_NAME)}: undefined attribute '#{err.name}'" | |
end | |
end | |
idx = ARGV.index '--' | |
if idx | |
ARGV.delete_at idx | |
run(ARGV[0...idx], ARGV[idx..-1]) | |
else | |
run(ARGV.to_a) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment