3

I would just like to know how could I print color text without the termcolor module. I don't want the termcolor because if someone use my script and he don't have the termcolor module installed, it won't work! :( I read somewhere that I could just use the code here: http://www.tux-planet.fr/les-codes-de-couleurs-en-bash/

with print. But I just cant get it work.

user1044824
  • 57
  • 1
  • 5

1 Answers1

2

You need to print the escape sequences. For example, to print 'foo' in red, try out this one:

print '\x1b[31mfoo\x1b[0m'

To discover the escape sequences, you can use termcolor.colored function.

But, the "normal" way is to simply have a dependency on termcolor.. you can give them the module at the same time as you give them your script!

wim
  • 338,267
  • 99
  • 616
  • 750