I have several Lua scripts that run experiences and output a lot of information, in text files and in the console. I'd like to add some colors in the console output, to make it more readable.
I know that it's possible to color the output of bash scripts using the ANSI escape sequences. For example :
$ echo -e "This is red->\e[00;31mRED\e[00m"
I tried to do the same in Lua :
$ lua -e "io.write('This is red->\\e[00;31mRED\\e[00m\n')"
but it does not work. I also tried with print()
instead of io.write()
, but the result is the same.
lua -e "print('This is red->\27[31mred\n')"
Note the \27. Whenever Lua sees a \
followed by a decimal number, it converts this decimal number into its ASCII equivalent. I used \27 to obtain the bash \033 ESC character. More info here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With