About Monkey 2 › Forums › Monkey 2 Programming Help › Console terminal sequences
This topic contains 5 replies, has 3 voices, and was last updated by
Hezkore
1 year, 2 months ago.
-
AuthorPosts
-
January 31, 2018 at 1:15 am #13375
I’m trying to get some colour into my console window via ANSI codes.
It works on every platform but Windows.I looked things up and it turns out you need to set the console mode to “ENABLE_VIRTUAL_TERMINAL_PROCESSING” in Windows.
Here’s some info on that: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
Example at the bottom of the link as well.Enabling that mode seems to be as easy as SetConsoleMode( GetStdHandle(STD_OUTPUT_HANDLE), ENABLE_VIRTUAL_TERMINAL_PROCESSING) at least according to the example.
Some info on GetStdHandle: https://docs.microsoft.com/en-us/windows/console/getstdhandleI’ve tried to get this working in Monkey2, but nothing really seems to be happening…
REMOVED
You’ll have to run this via the ‘products’ folder as Ted2Go won’t show colours even if it was working.
Other than that, this works well on all other platforms.Anyone know what I’m doing wrong on Windows?
January 31, 2018 at 1:34 am #13376I suspect you may need a screen buffer handle using CreateConsoleScreenBuffer, check this example:
January 31, 2018 at 1:43 am #13378I shouldn’t need that much.
Check this example out: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#span-idsamplesspanspan-idsamplesspanspan-idsamplesspansamplesHere’s the output of that:
January 31, 2018 at 5:12 am #13380You need to turn off ‘Use legacy console’ in ‘Command prompt properties’ (right click on shell drag bar).
With this off, you don’t even need SetConsoleMode. In fact, your SetConsoleMode isn’t doing anything due to incorrect stdout const (should be -11) and use of Varptr hOut (should just be hOut).
Or you could use something like the mighty conemu…
January 31, 2018 at 9:01 am #13387Hmm even with Legacy Console mode off I can’t get it to work heh.
Nothing seems to work…And this updated code with your fixes doesn’t work either:
REMOVEDNot in “normal” nor Legacy console.
Can’t figure out what I’m doing wrong…January 31, 2018 at 5:38 pm #13400Alright, I seem to have gotten it working.
Thanks everyone!Legacy Console in general doesn’t seem to be able to display colors. (correct me if I’m wrong)
And the not-legacy console CAN show colors, but it has to be enabled via the function I posted above.
In older Windows 10 version it was enabled by default, but not any more.I’m removing the code so it doesn’t cause any confusion!
It’ll be part of my m2libcext module. -
AuthorPosts
You must be logged in to reply to this topic.