# QT color console on MacOS - lost default foreground colour

**URL:** <https://swi-prolog.discourse.group/t/qt-color-console-on-macos-lost-default-foreground-colour/2429>\
**Category:** Help!\
**Tags:** how-to\
**Created:** [May 29, 2020, 4:28pm UTC](https://swi-prolog.discourse.group/t/qt-color-console-on-macos-lost-default-foreground-colour/2429 "2020-05-29T16:28:59Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![ridgeworks](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ridgeworks/32/886_2.png) [@ridgeworks](https://swi-prolog.discourse.group/u/ridgeworks)\
**Post date:** [May 29, 2020, 4:28pm UTC](https://swi-prolog.discourse.group/t/qt-color-console-on-macos-lost-default-foreground-colour/2429/1 "2020-05-29T16:28:59Z")

</div>

MacOS `10.13.6`, SWIP `8.2.0`

On one of my computers the default foreground colour for the QT console seems to have been set to white making it invisible on the white background. Selecting it makes it visible. It wasn’t originally this way - the release worked fine for some time - and it isn’t occurring on my other computer. In addition, previously installed releases (e.g., `8.1.32`) now have the same issue.

Workarounds:

1. In `init.pl` set the `color_term` environment flag to `false` and restart.
2. Load `library(themes/dark)`.

I’ve tried digging into the `ansi_term` library without much success. For example, the doc says I should be able to query the foreground colour using alias `foreground` but:

```prolog
?- ansi_get_color(foreground,RGB).
false.

```

Not really sure how all this is supposed to work, so hoping I’m just missing something obvious. Any suggestions of how to get out of this welcome.

---

<div class="post-metadata">

**Author:** ![ridgeworks](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ridgeworks/32/886_2.png) [@ridgeworks](https://swi-prolog.discourse.group/u/ridgeworks)\
**Post date:** [May 29, 2020, 8:12pm UTC](https://swi-prolog.discourse.group/t/qt-color-console-on-macos-lost-default-foreground-colour/2429/2 "2020-05-29T20:12:56Z")

</div>

Further digging seems to indicate that some color table is broken. `black`, and `red` both output as `white`. So `print_message(query,halt)` isn’t visible while `print_message(information,halt)` is (in green with a `% ` prefix).

Is the color picker (menu item `Settings/Colors …`) relevant to this? I’ve never figured out what this is for.

---

<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:** [May 30, 2020, 7:28am UTC](https://swi-prolog.discourse.group/t/qt-color-console-on-macos-lost-default-foreground-colour/2429/3 "2020-05-30T07:28:31Z")

</div>

> [@ridgeworks](#):
>
> Is the color picker (menu item `Settings/Colors …` ) relevant to this? I’ve never figured out what this is for.

There have been similar issues in the past. The color picker menu can re-arrange the mapping for the 16 ANSI color palette. Somehow that can get mixed up. Possibly remove the config file in ~/.config/swi-prolog (think it is called pqConsole.plist or something like that).

> [@ridgeworks](#):
>
> `ansi_get_color(foreground,RGB).`

This predicate performs a handshake with normal terminals to find the color mapping. This doesn’t work for pqConsole. It also makes little sense as the console doesn’t listen to some sort of system preferences AFAIK. So, normally all should work find as is in light theme and you can load dark theme if you prefer (or define a new theme 🙂 ).

---

<div class="post-metadata">

**Author:** ![ridgeworks](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ridgeworks/32/886_2.png) [@ridgeworks](https://swi-prolog.discourse.group/u/ridgeworks)\
**Post date:** [May 30, 2020, 3:16pm UTC](https://swi-prolog.discourse.group/t/qt-color-console-on-macos-lost-default-foreground-colour/2429/4 "2020-05-30T15:16:07Z")

</div>

> [@jan](#):
>
> There have been similar issues in the past. The color picker menu can re-arrange the mapping for the 16 ANSI color palette. Somehow that can get mixed up. Possibly remove the config file in ~/.config/swi-prolog (think it is called pqConsole.plist or something like that).

This sounds promising. However. the only file in `~/.config/swi-prolog` is `init.pl` (along with directories `dir-history` and `xpce`). Also a search of that name fails.

A search on `swipl-devel` indicates that `pqConsole` is referenced from `library/win_menu.pl` and the menu item is associated with `pqConsole:select_ANSI_term_colors`. But I’m not sure where that reference leads.

---

<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:** [May 30, 2020, 4:00pm UTC](https://swi-prolog.discourse.group/t/qt-color-console-on-macos-lost-default-foreground-colour/2429/5 "2020-05-30T16:00:52Z")

</div>

> [@ridgeworks](#):
>
> This sounds promising. However. the only file in `~/.config/swi-prolog` is `init.pl` (along with directories `dir-history` and `xpce` ). Also a search of that name fails.

Right. It is there in the Linux version of the Qt console, but on in the Mac version. Can’t find this right now ☹

> [@ridgeworks](#):
>
> But I’m not sure where that reference leads.

Into the `packages/swipl-win` code … Don’t ask more …

---

<div class="post-metadata">

**Author:** ![CapelliC](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/capellic/32/17_2.png) [@CapelliC](https://swi-prolog.discourse.group/u/CapelliC)\
**Post date:** [May 30, 2020, 4:32pm UTC](https://swi-prolog.discourse.group/t/qt-color-console-on-macos-lost-default-foreground-colour/2429/6 "2020-05-30T16:32:41Z")

</div>

Sorry for the problem…

Not having a Mac where to debug is making this more difficult than it should be.  
I’tried yesterday on a Linux box, and could not spot the problem.

Today I have only Win10, and Qt + MSVC 2017 cannot even compile the (small) project.  
(@Jan: seems there is an include of SWI-Stream.h missing, or a misplacing of MSVC flags, since it chockes about unknown ssize\_t… will try to solve this…)

The location of the preferences file is handled by [QSettings](https://doc.qt.io/qt-5/qsettings.html), so, according to the [docs](https://doc.qt.io/qt-5/qsettings.html#platform-specific-notes) and the [source](https://github.com/SWI-Prolog/packages-swipl-win/blob/96b8749292b8938d9b8b33956fb11319125e6e05/Preferences.cpp), the path could be  
`$HOME/Library/Preferences/com.swi-prolog.pqConsole.plist`

---

<div class="post-metadata">

**Author:** ![CapelliC](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/capellic/32/17_2.png) [@CapelliC](https://swi-prolog.discourse.group/u/CapelliC)\
**Post date:** [May 30, 2020, 5:22pm UTC](https://swi-prolog.discourse.group/t/qt-color-console-on-macos-lost-default-foreground-colour/2429/7 "2020-05-30T17:22:44Z")

</div>

So many years I didn’t compiled on Windows, now I think MSVC cannot be used…  
Trying with MinGW, if I survive the Qt compiler kit setup…

---

<div class="post-metadata">

**Author:** ![ridgeworks](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ridgeworks/32/886_2.png) [@ridgeworks](https://swi-prolog.discourse.group/u/ridgeworks)\
**Post date:** [May 30, 2020, 5:31pm UTC](https://swi-prolog.discourse.group/t/qt-color-console-on-macos-lost-default-foreground-colour/2429/8 "2020-05-30T17:31:16Z")

</div>

> [@CapelliC](#):
>
> The location of the preferences file is handled by [QSettings](https://doc.qt.io/qt-5/qsettings.html), so, according to the [docs](https://doc.qt.io/qt-5/qsettings.html#platform-specific-notes) and the [source](https://github.com/SWI-Prolog/packages-swipl-win/blob/96b8749292b8938d9b8b33956fb11319125e6e05/Preferences.cpp), the path could be  
> `$HOME/Library/Preferences/com.swi-prolog.pqConsole.plist`

Found it; thanks for the info. I’ve got one working system so I should be able to resolve this one way or the other.

---

<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:** [May 30, 2020, 5:39pm UTC](https://swi-prolog.discourse.group/t/qt-color-console-on-macos-lost-default-foreground-colour/2429/9 "2020-05-30T17:39:57Z")

</div>

> [@CapelliC](#):
>
> MinGW

If you are using Windows, [WSL 2](https://docs.microsoft.com/en-us/windows/wsl/wsl2-index) is releasing/has been released to the public this week. I have it being on the [slow ring](https://insider.windows.com/en-us/), but that should not be needed any more.

See: [How to get the Windows 10 May 2020 Update](https://blogs.windows.com/windowsexperience/2020/05/27/how-to-get-the-windows-10-may-2020-update/)

---

<div class="post-metadata">

**Author:** ![ridgeworks](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ridgeworks/32/886_2.png) [@ridgeworks](https://swi-prolog.discourse.group/u/ridgeworks)\
**Post date:** [May 30, 2020, 5:54pm UTC](https://swi-prolog.discourse.group/t/qt-color-console-on-macos-lost-default-foreground-colour/2429/10 "2020-05-30T17:54:17Z")

</div>

> [@ridgeworks](#):
>
> I’ve got one working system so I should be able to resolve this one way or the other.

The `com.swi-prolog.pqConsole.plist` on the working system matches the on the non-working system except for the `MRU2.path`, `pqMainWindow.pos` and `pqMainWindow.size` values, which is to be expected. So my theory of a corrupted config file doesn’t fit. I’ll keep digging.

---

<div class="post-metadata">

**Author:** ![CapelliC](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/capellic/32/17_2.png) [@CapelliC](https://swi-prolog.discourse.group/u/CapelliC)\
**Post date:** [May 30, 2020, 6:19pm UTC](https://swi-prolog.discourse.group/t/qt-color-console-on-macos-lost-default-foreground-colour/2429/11 "2020-05-30T18:19:13Z")

</div>

You could try to set the environment variable QDEBUG=stderr, or better (since I don’t know where the stderr output could show) an absolute writable path. Then loading the Preferences class should display some info…

---

<div class="post-metadata">

**Author:** ![ridgeworks](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ridgeworks/32/886_2.png) [@ridgeworks](https://swi-prolog.discourse.group/u/ridgeworks)\
**Post date:** [May 30, 2020, 6:36pm UTC](https://swi-prolog.discourse.group/t/qt-color-console-on-macos-lost-default-foreground-colour/2429/12 "2020-05-30T18:36:44Z")

</div>

> [@CapelliC](#):
>
> You could try to set the environment variable QDEBUG=stderr,

Not sure how to do this with a MacOS bundle; any hints?

---

<div class="post-metadata">

**Author:** ![ridgeworks](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ridgeworks/32/886_2.png) [@ridgeworks](https://swi-prolog.discourse.group/u/ridgeworks)\
**Post date:** [May 30, 2020, 6:47pm UTC](https://swi-prolog.discourse.group/t/qt-color-console-on-macos-lost-default-foreground-colour/2429/13 "2020-05-30T18:47:37Z")

</div>

> [@CapelliC](#):
>
> You could try to set the environment variable QDEBUG=stderr

OK. Launched `SWI_Prolog` executable from terminal with QDEBUG=stderr. Just message:  
`Loading preferences from "~/Library/Preferences/com.swi-prolog.pqConsole.plist"`

repeated 4 times. QT console text still invisible.

---

<div class="post-metadata">

**Author:** ![CapelliC](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/capellic/32/17_2.png) [@CapelliC](https://swi-prolog.discourse.group/u/CapelliC)\
**Post date:** [May 30, 2020, 6:52pm UTC](https://swi-prolog.discourse.group/t/qt-color-console-on-macos-lost-default-foreground-colour/2429/14 "2020-05-30T18:52:52Z")

</div>

I guess you already tried to delete the file, as suggested by Jan … sorry I have no better clue …

---

<div class="post-metadata">

**Author:** ![ridgeworks](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ridgeworks/32/886_2.png) [@ridgeworks](https://swi-prolog.discourse.group/u/ridgeworks)\
**Post date:** [May 30, 2020, 7:00pm UTC](https://swi-prolog.discourse.group/t/qt-color-console-on-macos-lost-default-foreground-colour/2429/15 "2020-05-30T19:00:47Z")

</div>

Yes, tried that. I was a bit surprised that the font setting was preserved. It seems like there’s some other persistent data somewhere.

Thanks for the suggestions.

---

<div class="post-metadata">

**Author:** ![ridgeworks](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ridgeworks/32/886_2.png) [@ridgeworks](https://swi-prolog.discourse.group/u/ridgeworks)\
**Post date:** [May 30, 2020, 9:27pm UTC](https://swi-prolog.discourse.group/t/qt-color-console-on-macos-lost-default-foreground-colour/2429/16 "2020-05-30T21:27:41Z")

</div>

I fixed this by experimenting with the custom colour table using the QT Color Picker Dialog. To summarize:

Module `ansi_term` maps 8 color names to numbers:

```prolog
ansi_color(black, 0).
ansi_color(red, 1).
ansi_color(green, 2).
ansi_color(yellow, 3).
ansi_color(blue, 4).
ansi_color(magenta, 5).
ansi_color(cyan, 6).
ansi_color(white, 7).
ansi_color(default, 9).

```

At least numbers `0-7` correspond to custom colours in the picker dialog (2 rows of 8) as follows:

```prolog
0 2 4 6 ? ? ? ?
1 3 5 7 ? ? ? ?

```

Note that `yellow` is currently a rust color, at least on my two systems.

Somehow in my ad hoc testing of the stable release I had re-defined `red` and `black` to be the colour white. My bad. But these definitions seem to have been preserved somewhere but it’s not clear where, since deleting the `pqConsole.plist` didn’t seem to change anything.

Unless I’m missing something, it’s not clear this color picker is very useful and can be problematic, e.g., if black is white, particularly for naive users (like me). `ansi_term` supports many colour formats (8 bit and 24 bit among others), so re-defining the core colour set isn’t something that is needed IMO. I suggest it at least be removed from the menu. As an escape hatch, it can still be invoked as `pqConsole:select_ANSI_term_colors`.
