# Change color of text output to the console window?

**URL:** <https://swi-prolog.discourse.group/t/change-color-of-text-output-to-the-console-window/973>\
**Category:** Help!\
**Created:** [July 19, 2019, 9:00pm UTC](https://swi-prolog.discourse.group/t/change-color-of-text-output-to-the-console-window/973 "2019-07-19T21:00:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![prodog](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@prodog](https://swi-prolog.discourse.group/u/prodog)\
**Post date:** [July 19, 2019, 9:00pm UTC](https://swi-prolog.discourse.group/t/change-color-of-text-output-to-the-console-window/973/1 "2019-07-19T21:00:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [July 19, 2019, 10:20pm UTC](https://swi-prolog.discourse.group/t/change-color-of-text-output-to-the-console-window/973/2 "2019-07-19T22:20:13Z")

</div>

I don’t know exactly how to do it with [write/1](https://www.swi-prolog.org/pldoc/man?predicate=write/1) but take a look at

[library(ansi\_term)](https://www.swi-prolog.org/pldoc/man?section=ansiterm): 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](https://en.wikipedia.org/wiki/ANSI_escape_code).

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](http://comptypo.decontextualize.com/ansi-terminal/)

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [July 19, 2019, 10:35pm UTC](https://swi-prolog.discourse.group/t/change-color-of-text-output-to-the-console-window/973/3 "2019-07-19T22:35:22Z")

</div>

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?](https://swi-prolog.discourse.group/t/how-to-get-rid-of-colorization-when-compiling-under-emacs/444)

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [July 20, 2019, 8:09am UTC](https://swi-prolog.discourse.group/t/change-color-of-text-output-to-the-console-window/973/4 "2019-07-20T08:09:18Z")

</div>

> [@peter.ludemann](#):
>
> Additional background can be found in the documentation for `ncurses` and `terminfo` .

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.

> [@peter.ludemann](#):
>
> How to get rid of colorization when compiling under Emacs?

Figuring out that the output does **not** support ANSI sequences is not so easy ☹ 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.
