Skip to content
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

LVB Gridlines do not transit ConPTY (Win32 "underline", overline, left/right) #8037

Open
Tracked by #13392
mnefedov opened this issue Oct 25, 2020 · 9 comments
Open
Tracked by #13392
Labels
Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Help Wanted We encourage anyone to jump in on these. Issue-Task It's a feature request, but it doesn't really need a major design. Priority-2 A description (P2) Product-Conpty For console issues specifically related to conpty
Milestone

Comments

@mnefedov
Copy link

Windows 10, Windows Terminal, Version: 1.3.2651.0

Windows build number: [run `[Environment]::OSVersion` for powershell, or `ver` for cmd]
Windows Terminal version (if applicable):

Any other software?

I use

-- SetConsoleMode(hStdin, ENABLE_WINDOW_INPUT | ENABLE_LVB_GRID_WORLDWIDE )
-- I do "| COMMON_LVB_UNDERSCORE' on the attributes of CHAR_INFO 'line'
-- WriteConsoleOutput(... line );

I am 95% sure the rest of the code is valid -- because I can do colors, etc.

Expected behavior

-- characters should be underlined.

Actual behavior

-- no underline

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Oct 25, 2020
@j4james
Copy link
Collaborator

j4james commented Oct 25, 2020

The problem is that the console APIs don't have a way to set the real underline attribute. COMMON_LVB_UNDERSCORE is actually a separate concept - it's a grid line rendered at the very bottom of the character cell, and grid lines are not currently supported in Windows Terminal.

If you want your text to be properly underlined, you'd need to have the Virtual Terminal mode enabled, and use a VT escape sequence (\e[4m) to enable the underline attribute before writing out your text. You can then use another sequence (\e[24m) to turn the underline off.

If you really do need support for the COMMON_LVB_UNDERSCORE grid line in Windows Terminal, we'd have to come up with a way of forwarding that attribute over the conpty connection, and that's a bit complicated.

(Note to any core devs reading this: I've suggested before that we could possibly use the ECMA ideogram SGR attributes for this, but those attributes aren't very well defined, so I'm not convinced that's a great idea. It's something to consider though.)

@mnefedov
Copy link
Author

Thank you James. I played with the escape seqs, and I got something working, but I have side effects after enabling Virtual Terminal Mode, I feel it is because my current rendering method is centered around WriteConsoleOutput(). I will debug.

@DHowett
Copy link
Member

DHowett commented Oct 26, 2020

aren't very well-defined

Wow, yeah -- "underline or right side", "overline or left side"

I do think we should try to send these over ConPTY, and unfortunately I do think they need to be an SGR (specifically). They're a visual styling and terminals have a very good history of ignoring specifically graphical renditions they don't understand.

@j4james
Copy link
Collaborator

j4james commented Oct 26, 2020

My understanding of the "underline or right side" and "overline or left side" is that those attributes were intended to be used with East Asian scripts when written in a vertical orientation. So an "underline" would be rendered to the right of the glyphs, and an "overline" would be rendered to the left. And that's the way those attributes are rendered by RLogin, so there is at least some precedence for interpreting them that way.

SGR 64 (the "ideogram stress marking") is less clear though. I desperately wanted that to mean a "proper name mark", which is essentially a form of underscore, but typically rendered lower than an underline, so that would make it a perfect alias for our grid line underscore. Unfortunately I think it's probably more likely to have meant an "emphasis point", which is usually rendered as a dot or circle.

That said, an underline is sometimes (rarely) used to indicate stress (at least according to this StackExchange answer), so it wouldn't be that terrible to interpret it that way. We unfortunately can't look to RLogin for precedence here, because they render SGR 64 the same as strike-through, and I don't think that's correct.

The bottom line is we could reasonably translate our right and left grid lines as SGR 60 and SGR 62. It would be more of a stretch to translate the underscore grid line as SGR 64, though, but not unthinkable.

@mnefedov
Copy link
Author

James,

I had to change my code to NOT to use WriteConsoleOutput(), because it seems WriteConsoleOutput() "overrides" the underline. I am now using WriteConsole() in conjunction with SetConsoleCursorPosition(), and doing the ESC sequence when needed. This made the output very slow. I have not played with the cursor enable/disable yet.

@mnefedov
Copy link
Author

... disabling the cursor for the duration of the output improves performance significantly, but it is still far behind the WriteConsoleOutput() performance.

@zadjii-msft
Copy link
Member

I'm gonna re-purpose this thread as "make COMMON_LVB_*" attributes work in the Terminal - we definitely need to come up with something, because I'm sure that most legacy console apps are going to be using COMMON_LVB_UNDERSCORE for their underlines rather than VT.

@zadjii-msft zadjii-msft added Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Issue-Task It's a feature request, but it doesn't really need a major design. Priority-2 A description (P2) Product-Conpty For console issues specifically related to conpty labels Oct 27, 2020
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Oct 27, 2020
@zadjii-msft zadjii-msft added this to the Terminal Backlog milestone Oct 27, 2020
@zadjii-msft zadjii-msft added the Help Wanted We encourage anyone to jump in on these. label Oct 27, 2020
@mnefedov
Copy link
Author

FWIW using *_LVB_UNDERSCORE in CHAR_INFO.Attributes via WriteConsoleOutput() would be the nicest solution in my use case, because:
-- no need to track underscore attr,
-- no need to move the cursor -- performance consideration
-- no need to "touch" the cursor's visibility -- performance consideration
-- no need for a different render strategy for underlined chars -- code complexity consideration.

@zadjii-msft zadjii-msft removed the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Nov 2, 2020
@DHowett DHowett changed the title Unable to get underline output when working with the console buffer. LVB Gridlines are not transited by ConPTY (WIn32 "underline", overline, left/right) Mar 15, 2021
@DHowett DHowett changed the title LVB Gridlines are not transited by ConPTY (WIn32 "underline", overline, left/right) LVB Gridlines do not transit ConPTY (Win32 "underline", overline, left/right) Mar 15, 2021
@zadjii-msft zadjii-msft modified the milestones: Terminal Backlog, Backlog Jan 4, 2022
@j4james
Copy link
Collaborator

j4james commented Sep 22, 2022

I came across something a while ago which I've been meaning to post, which could possibly work as a solution to this issue. I didn't think it was a great solution, but it's worth noting anyway.

Quoting from this site: https://www.cs.auckland.ac.nz/references/unix/digital/AQ0R4CTE/DOCU_006.HTM#I768

Digital UNIX enhancements for Asian languages include additional escape sequences for drawing and removing ruled lines in a specified area of a DECterm window. These additional escape sequences allow applications to construct tables and diagrams. The feature is a market requirement for Japanese

The main escape sequence they're referring to there is DECDRLBR (draws ruled lines on the boundaries of a rectangular area), which sounds like it was intended to meet the same needs as the grid lines in Windows.

If we were suggesting it as a VT sequence people could use in place of the legacy gridlines, it might be reasonable, but using it to forward existing gridline attributes over conpty seems like it would be horribly complicated. You could potentially be having to pass through a separate DECDRLBR sequence for every character you output.

Bottom line is it's probably useless, but I wanted to at least make a note of it.

Edit: The other thing I wanted to say was maybe we should just pass through the LVB_UNDERSCORE gridline as a VT underline, at least as a temporary solution, since that's assumedly the most commonly used. And I suspect nobody would really care that much that if it isn't aligned to the bottom of the cell. It's better than nothing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Help Wanted We encourage anyone to jump in on these. Issue-Task It's a feature request, but it doesn't really need a major design. Priority-2 A description (P2) Product-Conpty For console issues specifically related to conpty
Projects
None yet
Development

No branches or pull requests

4 participants