0

I've been trying to do some complex animations on the console, seeing how far I can push the standard Windows console. I was able to get any color I wanted by following this post: Custom text color in C# console application?, using the second answer involving ENABLE_VIRTUAL_TERMINAL_PROCESSING. However, due to how many characters I was trying to color at once (roughly 2 million), even a single Console.Write was too slow. I then tried to use this process: How can I write fast colored output to Console? This gave me the speed that I was looking for, but I was limited to the 16 color palette that the Windows console uses. Is there anyway to get the exact RGB color specificity that the first post offered, while also still having the speed of writing directly to the console buffer like the second post?

I tried using Console.Write("\x1b[48;2;" + 255 + ";" + 0 + ";" + 0 + "m") before writing directly to the buffer, just to see if the background color would be properly changed. I also made sure not to set the Attributes property of any of the CharInfo as each character was being written into the buf array. Unfortunately, that did not work. All text that was written directly into the buffer still had a black background and black foreground color. I also tried to change the RGB value of one of the 16 standard colors between separate writes to the buffer, but that ended up being too slow.

Filburt
  • 17,626
  • 12
  • 64
  • 115
  • You're mixing *answers* to completely unrelated questions, using different technologies. The entire console/virtual terminal infrastructure was redesigned from scratch in Windows 10. There's a different Win32 API . The question itself is unclear too - what kind of character mode animation are you trying to perform? There may be libraries that already do what you want, eg [Spectre.Console](https://spectreconsole.net/) or [Gui.cs](https://github.com/gui-cs) – Panagiotis Kanavos May 17 '23 at 07:27
  • You should check [Windows Command-Line: Introducing the Windows Pseudo Console (ConPTY)](https://devblogs.microsoft.com/commandline/windows-command-line-introducing-the-windows-pseudo-console-conpty/) and the entire article series to see how the command line architecture changed and how the *new* ConPTY API works (and why). The entire Command Line Team's blog is worth following and contains various articles on how to use color, escape sequences, Unicode etc. Make sure you use the Windows Terminal too, because that's where all investment and perf work go – Panagiotis Kanavos May 17 '23 at 07:43
  • Finally check the [ConPTY](https://github.com/microsoft/terminal/tree/main/samples/ConPTY) samples in Windows Terminal's Github repo. MiniTerm specifically creates a mini terminal in C# using the ConPTY API, so it's worth to check if only to steal the native API declarations – Panagiotis Kanavos May 17 '23 at 07:46
  • @PanagiotisKanavos I'm trying to treat each character in the console window as a pixel on a screen. My plan was to just set the background color to whatever color I needed that pixel to be, and have the character be a space. I would calculate what needed to be rendered, then write it to the console all at once, then repeat for each frame of the animation. This was primarily an experiment to see how much could be done graphically with something as limited as the standard console window. I'll take a look at those links you sent and see if they fit my wants. Thank you for the explanation! – Silver Sensei May 17 '23 at 08:05

0 Answers0