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

Color and Text properties not getting restored properly (READ: Support 256 / RGB color in the Console API) #11160

Closed
rashil2000 opened this issue Sep 6, 2021 · 3 comments
Labels
Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. Area-VT Virtual Terminal sequence support Issue-Question For questions or discussion Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Resolution-Answered Related to questions that have been answered

Comments

@rashil2000
Copy link
Contributor

I'm intentionally ignoring the issue template, as this is a consequence of PowerShell/PowerShell#15484:

Steps to reproduce

This is a bug that was recently discovered through a module - GuiCompletion, in nightroman/PS-GuiCompletion#5.

The premise is that GetBUfferContents and SetBufferContents do not fetch and restore all color and text properties properly. See the attached GIF there for a look.

Environment data

This occurs on both Windows PowerShell and PowerShell Core.

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Name                           Value
----                           -----
PSVersion                      5.1.19041.906
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.906
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

from @SteveL-MSFT

The problem is that GetBufferContents() doesn't understand ANSI. It only works for [ConsoleColor] really. Internally, it's calling GetConsoleScreenBufferInfo() which returns a CONSOLE_SCREEN_BUFFER_INFO which is limited to certain attributes.

The win32 API would need to change to give the full set of attributes supported by ANSI. Best bet would be to ask the https://github.com/Microsoft/Terminal folks (which also owns conhost) to support this.

@zadjii-msft
Copy link
Member

Yea, that's not wrong. I suppose we figured that if you're going to be doing VT things (like RGB colors), then you're not going to be using the legacy API. I'd recommend moving away from the console API and sticking with just VT if you want to support RGB colors and other advanced attributes. For example, draw that menu in nightroman/PS-GuiCompletion#5 below the prompt, so you don't need to worry about restoring the contents there. When you're done with it, you can just clear it out.

@zadjii-msft zadjii-msft added Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. Area-VT Virtual Terminal sequence support Issue-Question For questions or discussion Resolution-Answered Related to questions that have been answered labels Sep 7, 2021
@DHowett
Copy link
Member

DHowett commented Sep 7, 2021

(If we're going to change the API, you won't really be able to use it until Windows 12¹ anyway.)

¹Informative, not normative.

@zadjii-msft zadjii-msft added the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Sep 8, 2021
@zadjii-msft
Copy link
Member

You know what, I'm gonna close this out as rejected. We're EXTREMELY reluctant to making any sort of API changes to the Console API. We'd need pretty serious buisness justification to make changes there. Plus, doing something like GetConsoleScreenBufferInfo isn't going to work correctly on other platforms - I'd rather encourage people to write code that will work across different platforms. This kind of menu won't be possible to draw on a *nix terminal, so the design should ultimately be reconsidered, sorry.

(There's also #10810 which we're vaguely using to track "create a screen buffer which is a copy of the current one ... some custom VT sequence for 'enter the alternate buffer (and initialize the contents of the alt buffer to the contents of the main buffer)'". We'd design that in a way that would be possible x-plat, rather than GetConsoleScreenBufferInfo et. at. I'd follow that thread for better developments.)

@zadjii-msft zadjii-msft closed this as not planned Won't fix, can't repro, duplicate, stale Aug 15, 2022
@zadjii-msft zadjii-msft changed the title Color and Text properties not getting restored properly Color and Text properties not getting restored properly (READ: Support 256 / RGB color in the Console API) Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. Area-VT Virtual Terminal sequence support Issue-Question For questions or discussion Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Resolution-Answered Related to questions that have been answered
Projects
None yet
Development

No branches or pull requests

3 participants