• Set Console Mode

    From Boondock@VERT/ELGATO to All on Monday, March 01, 2021 18:39:42
    Hi,
    Asking the gurus on here. I've posted a question on Stack Overflow (https://stackoverflow.com/questions/66427281/vb-net-console-use-ansi-sequences -console-virtual-terminal-sequences) but figured I would repost it here.

    I am trying to write a console app in VB.NET (VS Studio Community 2019 & .Net framework 4.8)
    I cannot get it to display ANSI Escape sequences correctly.
    I am aware of [this suggestion](https://stackoverflow.com/questions/16755142/how-to-make-win32-cons ole-recognize-ansi-vt100-escape-sequences "Especially the Registry Hack") and have applied it. (Makes no difference)

    I am able to set colour using
    ``` vb.net
    Console.ResetColor()
    Console.ForegroundColor = ConsoleColor.Red
    ```
    and cursor positioning, using
    ``` vb.net
    Console.SetCursorPosition(origCol + x, origRow + y)
    Console.Write(s)
    ```

    When I try to do this
    ```vb.net
    Console.WriteLine("\u001b[31mHello World!\u001b[0m")
    ```

    It just prints it out raw without interpreting the ANSI Sequences.

    `Console.OutputEncoding = Text.Encoding.XXX` only gives me limited options for XXX, including Ascii, UTF8, 16, 32 and Unicode.

    I have gone over [This](https://docs.microsoft.com/en-us/windows/console/console-virtual-termina l-sequences) article on "Console Virtual Terminal Sequences", which seems to be Microsoft's term for ANSI Codes. This article refers to [setConsoleMode](https://docs.microsoft.com/en-us/windows/console/setconsolemod e).

    There is also this snippet of C, for which I can find no equivalent in vb.net

    ``` C
    // Set output mode to handle virtual terminal sequences
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    if (hOut == INVALID_HANDLE_VALUE)
    {
    return GetLastError();
    }

    DWORD dwMode = 0;
    if (!GetConsoleMode(hOut, &dwMode))
    {
    return GetLastError();
    }

    dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
    if (!SetConsoleMode(hOut, dwMode))
    {
    return GetLastError();
    }
    ```
    I'm guessing that one of these two might be the answer to my problem, but I have no idea how to do anything with this info in VB.net.

    Help! Please?

    Boondock

    BoonDock
    Pedasi/Panama


    ... Documentation - The worst part of programming.

    ---
    þ Synchronet þ Sent from El Gato de Fuego * The Fire Cat * elgato.synchronetbbs.org