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 3 months, 2 weeks ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #13375

    Hezkore
    Participant

    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/getstdhandle

    I’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?

    #13376

    Simon Armstrong
    Participant

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

    https://docs.microsoft.com/en-us/windows/console/reading-and-writing-blocks-of-characters-and-attributes

    #13378

    Hezkore
    Participant
    #13380

    Mark Sibly
    Keymaster

    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…

    #13387

    Hezkore
    Participant

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

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

    #13400

    Hezkore
    Participant

    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.