How can I change the text color in the windows command prompt

后端 未结 14 2486
南旧
南旧 2020-12-14 22:32

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

相关标签:
14条回答
  • 2020-12-14 23:18

    I've been using a freeware windows tail program called baretail (google it) for ages that lets you do a windows-appified version of unix tail command. It lets you colorize lines dependent on whatever keywords you define. What's nice about it as a solution is its not tied to a specific language or setup, etc, you just define your color scheme and its on like donkey kong. In my personal top 10 freeware helpers!

    0 讨论(0)
  • 2020-12-14 23:21

    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.

    0 讨论(0)
提交回复
热议问题