Change color of text output to the console window?

I’m using: SWI-Prolog version 8.1.9.

How can I change the color of the output to the console window for one particular write/1 statement, and then switch it back to what it was before I did that?

I don’t know exactly how to do it with write/1 but take a look at

library(ansi_term): Print decorated text to ANSI consoles

which has only one predicate ansi_format/3

To do what you specifically want might require sending ANSI escape codes.

Decades ago when I use to work with ANSI terminals this was very common and the common problem was that the escapes codes were as different as each make and model of a terminal.

Here is an interesting article:

The ANSI Terminal

Additional background can be found in the documentation for ncurses and terminfo.

Also, there might still be some latent bugs in SWI-Prolog … see How to get rid of colorization when compiling under Emacs?

1 Like

The old mess is barely necessary anymore. Physical terminals were very diverse. The virtual ones we have now all seem to implement at least the basics of the ANSI sequences.

Figuring out that the output does not support ANSI sequences is not so easy :frowning: The other thing that is remarkably hard is to figure out the current colors of a terminal, so you can adjust the scheme. There is a control sequence for that, but it is not easy to use and I don’t know how widely implemented it is.