Skip to content

Fixes #4191 Make v2 true color on by default (i.e. opt out) #4195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: v2_develop
Choose a base branch
from

Conversation

tznind
Copy link
Collaborator

@tznind tznind commented Jul 17, 2025

Fixes

Proposed Changes/Todos

We now assume SupportsTrueColor is true unless user explicitly sets false themselves.

Pull Request checklist:

  • I've named my PR in the form of "Fixes #issue. Terse description."
  • My code follows the style guidelines of Terminal.Gui - if you use Visual Studio, hit CTRL-K-D to automatically reformat your files before committing.
  • My code follows the Terminal.Gui library design guidelines
  • I ran dotnet test before commit
  • I have made corresponding changes to the API documentation (using /// style comments)
  • My changes generate no new warnings
  • I have checked my code and corrected any poor grammar or misspellings
  • I conducted basic QA to assure all features are working

@tznind tznind requested a review from tig as a code owner July 17, 2025 02:05
@tznind tznind mentioned this pull request Jul 17, 2025
8 tasks
@BDisp
Copy link
Collaborator

BDisp commented Jul 17, 2025

Still not the best option. This is from your branch using Alacritty.

alacritty_4c8Nqk7Bca

@tznind
Copy link
Collaborator Author

tznind commented Jul 17, 2025

That's right, I fixed this in #4193 but that makes worse for cmd.exe

@BDisp
Copy link
Collaborator

BDisp commented Jul 17, 2025

In cmd.exe or conhost.exe, when virtual terminal is disabled you need avoid sending escape sequence at all.

@tznind
Copy link
Collaborator Author

tznind commented Jul 18, 2025

There is no cross terminal solution for wide characters using the kernel32 api WriteConsoleOutputW (the one we are using for 16 colors).

I created this repro:
https://github.com/tznind/16-color-console-tests

The test cases are as follows

Test Case Written
' ' ['你', ' ', 'c','d']
'\0' ['你', '\0', 'c','d']
<none> ['你', 'c','d']

Here is a comparison of various terminals. Notice that there is no column that works for all 3.

Terminal ' ' '\0' <none>
Alacritty image image image
Windows Terminal image image image
cmd.exe (NSimSun font) image image image

@tznind tznind changed the title Fixes #4191 Make v2 true color 'opt in' Fixes #4191 Make v2 true color on by default (i.e. opt out) Jul 18, 2025
@BDisp
Copy link
Collaborator

BDisp commented Jul 19, 2025

Alacritty is who rendering correctly. It's impossible to use WriteConsoleOutputW to render all surrogate pairs codepoints correctly, because, some has a width of 1 and others a width of 2. For wide char in the bmp range From: U+0000. To: U+FFFF, it handle more or less, but not for non-bmp (surrogate pairs), which need other library to output correctly.

@tznind
Copy link
Collaborator Author

tznind commented Jul 20, 2025

Ok seems the correct way to handle this is to switch to the newer APIs (WriteConsoleW and SetConsoleTextAttribute (for 16 color)

Test Case Written
' ' ['你', ' ', 'c','d']
'\0' ['你', '\0', 'c','d']
<none> ['你', 'c','d']
modern Uses WriteConsoleW and SetConsoleTextAttribute instead (write as string)

Results:

Terminal ' ' '\0' <none> modern
Alacritty image image image image
Windows Terminal image image image image
cmd.exe (NSimSun font) image image image image

@tznind
Copy link
Collaborator Author

tznind commented Jul 21, 2025

Based on the above I have started a rewrite of 16 color mode in WindowsOutput (v2).

Here is WIP:
#4193

I think I can declutter some of this class while I am at it.

@tig
Copy link
Collaborator

tig commented Jul 21, 2025

A thot I had long ago was we'd eventually have 3 drivers:

  • ansi
  • net
  • win (legacy)

What are your thoughts on moving in this direction?

@tznind
Copy link
Collaborator Author

tznind commented Jul 21, 2025 via email

@tig
Copy link
Collaborator

tig commented Jul 21, 2025

What's the difference between ansi and net?

Both use pure escape sequences I think

On Mon, 21 Jul 2025, 13:42 Tig, @.***> wrote:

tig left a comment (#4195)

#4195 (comment)

A thot I had long ago was we'd eventually have 3 drivers:

  • ansi
  • net
  • win (legacy)

What are your thoughts on moving in this direction?

Reply to this email directly, view it on GitHub

#4195 (comment),

or unsubscribe

https://github.com/notifications/unsubscribe-auth/AHO3C5CBYNA2GKDQ733PAR33JTN4NAVCNFSM6AAAAACBWOWA7WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTAOJWGYYDEMZYHA

.

You are receiving this because you authored the thread.Message ID:

@.***>

Good question. I haven't looked at your code closely in a while. If it is in fact how we do "pure ansi that works xplat" then it fits.

Pure ansi, to me, means the ONLY ansi sequences emitted are sequences WE emit btw.

If v2net fits this, then

  • It should be the default
  • It should have a name that indicates its pure ansi
  • v2win should either go away or be named something that indicates "for stupid legacy Windows legacy cases where users can only use conhost"

Right?

@tznind
Copy link
Collaborator Author

tznind commented Jul 21, 2025

Yes v2net works almost exclusively with standard csharp dotnet methods and escape sequences.

There is some dll import stuff in NetWinVTConsole that is used in windows to turn on support for these sequences

Modern Windows 10+ consoles can support ANSI, but you must explicitly enable it using:
SetConsoleMode(handle, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);

  • All input mouse events come in as escape sequences
  • Many key combinations (e.g. arrow keys, Function keys) also come in as escape sequences

Input is read as ConsoleKeyInfo using Console.ReadKey (true) (core dotnet method).

Input sequences are detected and processed by AnsiResponseParser (including AnsiMouseParser and AnsiKeyboardParser).

It is called 'net' because it uses only core dotnet methods.

Output primarily uses escape sequences for color, style etc. It does mix in some dotnet calls e.g. Console.SetCursorPosition and of course Console.Out.Write but no dll imports.

I agree v2net should be default - It does seem there is anecdotal evidence of people having issues with it on windows. This is probably because of the wide range of versions of terminals out there fore windows, some with known bugs.

v2win has 2 modes

  • 16 color mode (which really is just - don't send terminal sequences)
  • 'Normal' mode. Which is primarily terminal sequences but also some native methods like buffer switching etc.

@tig
Copy link
Collaborator

tig commented Jul 22, 2025

@tznind super important that we view all this through 3 lenses:

  1. Output (which essentially boils down to emitting ANSI sequences)
  2. Mouse Input
  3. Keyboard Input

The discussion above is mostly about 1.

The dotnet console API is VERY broken relative to 3 on Windows (but, oddly, not Linux). See dotnet/runtime#96490

Until that issue is fixed, I'm afraid v2net will never work correctly for keyboard input. But there may be a way around it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CJK Characters doesn't render correctly on Alacritty (v2_develop) Windows drivers are forcing 16 color mode by default on some terminals
3 participants