This might be answered already but I could not figure out a good way to phrase it to look for an answer so I hope you'll bear with me.

I want to change the color of the text output on Terminal if it comes back from running a program. Ex: I make a script called test.py that just prints "Hello World!" and run this by entering

$python test.py

Now this will come back with Hello World! but it's hard to distinguish what's output from the program than from what was written by Terminal since they have same font and color and the terminal may look all convoluted like

User$ ls
FolderA FolderB
User$ cd
User$ python test.py
ImportError: No module name test
User$ vim test.py
Error detected while processing /User/.vimrc:
line xx
XXX: Something Something
Press Enter to Continue
Hello World!
Error Undefined Something something.
User$ cd /User/python/xxx.py

etc etc,

It's hard to debug, look at error messages, see the output of the script to decipher what is happening in the terminal, etc. I was wondering if it was possible to set it up so that each of the messages will come back in different color such that usual Terminal console messages are in black font, any error messages comes back in red font and the output from the script, say "Hello World!" comes back in green font.

  • There seems to be an answer here: stackoverflow.com/questions/287871/… – Ambidextrous May 23 '15 at 23:31
  • This method is actively coding in a color in the program's script every time and I would rather have a method to automatically take any output from a program, if there is any method so that I don't need to specify font and colors in the code every time or not worry about which language I'm using. – user26569 May 23 '15 at 23:55
  • I doubt that there's something so generic available that runs across all languages and everything. Pry is a color-aware REPL for Ruby. IPython is a color-aware REPL for Python. Pyrg is a color-aware test runner for Python. Maybe try IPython - as long as you're just testing little things it would be useful. – Ambidextrous May 24 '15 at 1:52

You must log in to answer this question.

Browse other questions tagged .