0

Is there a simple way to have the generic Lua console/terminal in windows display colors?

I am basically running the lua53.exe terminal in windows and want to display things with colors.

Mainly in my lua code, I'd like to display debug and error messages in a different color then the default text color. My default color is white in the lua terminal and I would like to output error messages that I print in red and debug in yellow.

I don't want to use other external applications/tools/etc to handle this. I've seen some links for using LOVE to create its own console to get color; and I've seen several ANSI code blocks that don't work natively in windows.

Egor Skriptunoff
  • 906
  • 1
  • 8
  • 23
bigE
  • 1
  • 1
  • 1
  • 1
    https://stackoverflow.com/a/38617204/4567755 - this is a general answer regarding the colours in a command line in Windows. You can apply it to Lua following linked MSDN documentation. Use `string.char` or escape sequences to put bytes by their value into string. – Aki Aug 22 '19 at 13:19
  • Thanks for the link and the info. But being new to Lua, I'm not sure exactly how to use it with string.char as you mentioned. From the link, it looks like I should be able to use something like [101;93m to print in Yellow on a Red BG. But how exactly would I use that with the lua print function? – bigE Aug 22 '19 at 14:08
  • 2
    `print("\27[101;93m YOUR TEXT HERE \27[0m")` – Egor Skriptunoff Aug 22 '19 at 14:46

2 Answers2

0

You cannot use colored output on Windows console cmd.exe. It's not Lua dependent.

Starting with Windows 10, you can use ANSI colors escape sequences on cmd.exe or with the Windows Terminal application (available on the Windows Store).

Another option is to use a Lua binary Module that deals with the Windows API to use colored output on the console.

TSam
  • 270
  • 1
  • 2
  • 6
0

if you are on windows, use os.execute('color') for the color command read the color command Microsoft docs