Console terminal sequences

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, 4 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #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:
    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:

    I’ve tried to get this working in Monkey2, but nothing really seems to be happening…
    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?


    Simon Armstrong

    I suspect you may need a screen buffer handle using CreateConsoleScreenBuffer, check this example:



    Mark Sibly

    You 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…



    Hmm 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:

    Not in “normal” nor Legacy console.
    Can’t figure out what I’m doing wrong…



    Alright, 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.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.