I have a command line program, which outputs logging to the screen.
I want error lines to show up in red. Is there some special character codes I can output to switc
I've authored a small cross-platform gem that handles this seamlessly running on Windows or POSIX-systems, under both MRI and JRuby.
It has no dependencies, and uses ANSI codes on POSIX systems, and either FFI (JRuby) or Fiddler (MRI) for Windows.
To use it, simply:
gem install color-console
ColorConsole provides methods for outputting lines of text in different colors, using the Console.write and Console.puts functions.
require 'color-console'
Console.puts "Some text" # Outputs text using the current console colours
Console.puts "Some other text", :red # Outputs red text with the current background
Console.puts "Yet more text", nil, :blue # Outputs text using the current foreground and a blue background
# The following lines output BlueRedGreen on a single line, each word in the appropriate color
Console.write "Blue ", :blue
Console.write "Red ", :red
Console.write "Green", :green
Visit the project home page at https://github.com/agardiner/color-console for more details.