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 and have applied it. (Makes no difference)
I am able to set colour using
Console.ResetColor()
Console.ForegroundColor = ConsoleColor.Red
and cursor positioning, using
Console.SetCursorPosition(origCol + x, origRow + y)
Console.Write(s)
When I try to do this
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 article on "Console Virtual Terminal Sequences", which seems to be Microsoft's term for ANSI Codes. This article refers to setConsoleMode.
There is also this snippet of C, for which I can find no equivalent in vb.net
// 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.