Discussions related to Visual Prolog
VPExplorer
Active Member
Posts: 25
Joined: 6 Aug 2012 16:56

Console colors - number reference, and setting background.

Unread post by VPExplorer »

Hi,

2 questions related to colors in the console -

1) Where is the list of colors and intensities? For now, I'm playing with setTextAttribute( 1, 1 ), which is obviously blue. Is there a specific reference in the .chm help, or in the wiki?

So far, from trial & error, I have this:

constants
con_blue : unsigned = 1.
con_green : unsigned = 2.
con_lightblue : unsigned = 3.
con_red : unsigned = 4.
con_white : unsigned = 6.

4 and 5 seem to be both red.

2) Is there a way to change the default background color? I think the answer is no, and that maybe we have to fill the console with spaces, after setting the default text attribute.
User avatar
Thomas Linder Puls
VIP Member
Posts: 1395
Joined: 28 Feb 2000 0:01

Re: Console colors - number reference, and setting background.

Unread post by Thomas Linder Puls »

The colors are defined in console_native:

Code: Select all

constants     cforeground_blue = 0x0001. % text color contains blue.     cforeground_green = 0x0002. % text color contains green.     cforeground_red = 0x0004. % text color contains red.     cforeground_intensity = 0x0008. % text color is intensified.     cbackground_blue = 0x0010. % background color contains blue.     cbackground_green = 0x0020. % background color contains green.     cbackground_red = 0x0040. % background color contains red.     cbackground_intensity = 0x0080. % background color is intensified.
And they are "bit" flags which you will "or" together

Code: Select all

Purple = console_native::cforeground_blue ++ console_native::cforeground_red
The predicate setTextAttributes "maps" to the windows API SetConsoleTextAttribute.

As you can see this technology is no longer part of Microsofts "echosystem roadmap", and we ought to update things to use the "virtual terminal" instead.
Regards Thomas Linder Puls
PDC
User avatar
Thomas Linder Puls
VIP Member
Posts: 1395
Joined: 28 Feb 2000 0:01

Re: Console colors - number reference, and setting background.

Unread post by Thomas Linder Puls »

If you want to use the Virtual Terminal escape sequences instead. Then you can do like this:

Code: Select all

clauses     run() :-         OH = console_api::getStdHandle(console_native::stdOutput_handle),         _ = console_native::getConsoleMode(OH, CMO),         _ = console_native::setConsoleMode(OH, CMO ++ 0x0004 ++ 0x0008),         stdio::write("\u001B[106m", "Some text").
The first three lines enables "Virtual Terminal" escape sequence handling on the output.

The last line first writes one such Virtual Terminal escape sequence to the terminal and then writes "Some text".

This particular escape sequence changes the background color to "Bright Cyan". You can read more about the escape sequences here: Console Virtual Terminal Sequences.

\u001B is the ESC (escape) character.
Regards Thomas Linder Puls
PDC
VPExplorer
Active Member
Posts: 25
Joined: 6 Aug 2012 16:56

Re: Console colors - number reference, and setting background.

Unread post by VPExplorer »

Thanks, Thomas. I'll be able to use some of this right away. Can't thank you enough.

Yeah, I read about the Virtual Terminal plans, earlier in the week. I didn't get that the Console Api would be abandoned anytime soon. It's not only Win32 that uses the console, it's also some .net apps.

For example Gui-cs has been active for a while.
https://github.com/migueldeicaza/gui.cs

There are too many dependencies, I think, to worry about it right now.
User avatar
Thomas Linder Puls
VIP Member
Posts: 1395
Joined: 28 Feb 2000 0:01

Re: Console colors - number reference, and setting background.

Unread post by Thomas Linder Puls »

I think you can safely assume that the console api will not just disappear anytime soon. But it will most likely not receive any updates and subsequently float behind.

The gui.cs looks like our old TURBO Prolog and PDC Prolog programs.

(Amazingly someone has made a demonstration of TURBO Prolog 2.0 and published it on youtube in 2018: Using Turbo Prolog.)
Regards Thomas Linder Puls
PDC
VPExplorer
Active Member
Posts: 25
Joined: 6 Aug 2012 16:56

Re: Console colors - number reference, and setting background.

Unread post by VPExplorer »

Freedos has a respectable following. There are hobbyists who still dabble there, and they work with C or Pascal and other legacy languages. I'll bet there are still some Fortran hobbyists.

There are languages that are almost 100% compatible between the Dos version and the Windows version. Even one specific Prolog language.

In the Windows arena, there are websites that teach Prolog with Visual Prolog 5.

Turbo and PDC Prolog for Dos isn't completely dead. At the least, like Basic, they're still useful for teaching programming concepts in the chosen paradigm.

I don't know why PDC isn't the one that's used in these videos, though. It was a nice incremental improvement over Turbo P. You'd think instructors would want to use the final version, for demonstration & teaching purposes.

I was never able to compile & link anything in PDC. Even simple parent_child( Parent, Child ) relation queries, that worked fine in Turbo P, and also worked in the PDC ide. The executable always returned some stack error. Maybe my environmental settings were off, and PDC pointed to the wrong linker.


Thomas Linder Puls wrote: 2 Feb 2022 21:04 I think you can safely assume that the console api will not just disappear anytime soon. But it will most likely not receive any updates and subsequently float behind.

The gui.cs looks like our old TURBO Prolog and PDC Prolog programs.

(Amazingly someone has made a demonstration of TURBO Prolog 2.0 and published it on youtube in 2018: Using Turbo Prolog.)
Post Reply