-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Add support for querying Xterm dynamic colors and palette #17729
Conversation
/* 13 */ { -1, -1 }, | ||
/* 14 */ { -1, -1 }, | ||
/* 15 */ { -1, -1 }, | ||
/* 16 */ { -1, -1 }, | ||
/* 17 */ { -1, -1 }, | ||
/* 18 */ { -1, -1 }, | ||
/* 19 */ { -1, -1 }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will not be filling all of these in, but are technically part of Xterm's supported color complement. We could put TEKTRONIX colors in here if we ever support it (OSC 15, 16, 18). We may never support pointer colors (OSC 13, 14). I intend to support selection colors (OSC 17, 19).
This comment has been minimized.
This comment has been minimized.
{ | ||
_renderSettings.SetColorAliasIndex(ColorAlias::DefaultForeground, TextColor::DEFAULT_FOREGROUND); | ||
return SetColorTableEntry(TextColor::DEFAULT_FOREGROUND, dwColor); | ||
assert(static_cast<size_t>(resource) >= 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This protects the developer. {Set,Request}XtermColorResource
are amply guarded by the switch
in OutputStateMachineEngine
.
@@ -14,6 +14,8 @@ | |||
using namespace Microsoft::Console; | |||
using namespace Microsoft::Console::VirtualTerminal; | |||
|
|||
constexpr COLORREF COLOR_INQUIRY_COLOR = 0xfeffffff; // It's like INVALID_COLOR but special |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I DUNNO ABOUT THIS YALL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's like INVALID_COLOR but special
LMAO
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I reread the issue I linked and learned that I need to report 16-bit colors. I also figured, in halfway there - why not report OSC 4 colors as well? I confirmed with xterm that each reply comes in as a separate OSC, even if they were bundled together in the input |
@DHowett I think so, yes. If an app is querying Also, I'm fairly certain that's what other terminals do that support both |
@DHowett As far as I can tell this doesn't work in Windows Terminal (I'm testing with |
Argh, good catch! Predictably, I've been testing with conhost 😅 |
This pull request consolidates `SetDefaultForeground`, `SetDefaultBackground` and `SetCursorColor` into one function `SetXtermColorResource`. `SetXtermColorResource` maps xterm resource OSC numbers to color table entries and, optionally, color _alias_ entries. The alias mappings are required to support reassigning the default foreground and background to their indexed entries after a `DECAC`. While there are only three real entries in the mapping table right now, I have designs on bringing in selection background (xterm "highlight") and foreground (xterm "highlightText"). Having this mapping will also make color inquiry easier.
ccb10a3
to
99d1979
Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just nits.
Thanks, it works, but why such a requirement though?
|
Ah, I see. That’s one of the decisions we made for ConPTY (and only ConPTY). When the connected terminal sends an escape sequence to the input side of the pty, we need to decide whether the application on the receiving end is expecting it. There is no signal between the connected terminal and the pty host that indicates it is in response to a command (and we could detect it, but we would need to get back into parsing the VT output to figure that out and there would probably be a race condition (since cross-process synchronization is one of our bugbears) and we just got out of that whole frying pan.) Unfortunately, OSC 4/10/11/12 isn’t the first casualty of this implementation detail. |
This was initially done to make sure that applications that weren’t expecting VT mouse input didn’t get it. Lack of ability to differentiate those inputs from replies is at the heart of it, though. @j4james do you think passing OSCs replies over would be fine? By and large, nobody will be generating OSC input in 2024 (gods willing)… so the risk is much smaller of passing through something that is not a reply. |
|
I'm not sure I fully understand what the issue is here, but I was just about to report what I suspect is a similar bug. Usually I could type something like And from what you've just said, I suspect that those cases are also likely failing because |
Oh no, you're totally right. conhost was replying in these cases! Now that Terminal is in charge of replying, we need to pass everything through. @lhecker this could be a big conpty v2 regression. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as the original author of INVALID_COLOR
, i approve of COLOR_INQUIRY_COLOR
@DHowett after 43e8883 WT replies without Code#include <windows.h>
void test(bool VtInput)
{
const auto
In = GetStdHandle(STD_INPUT_HANDLE),
Out = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD InMode;
GetConsoleMode(In, &InMode);
SetConsoleMode(In, (InMode & ~ENABLE_LINE_INPUT) | (VtInput? ENABLE_VIRTUAL_TERMINAL_INPUT : 0));
DWORD OutMode;
GetConsoleMode(Out, &OutMode);
SetConsoleMode(Out, OutMode | ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
const wchar_t Command[] = L"\x1b]4;1;?\x1b\\";
DWORD Written;
WriteConsole(Out, Command, ARRAYSIZE(Command) - 1, &Written, {});
wchar_t Reply[1024]{};
DWORD Read;
ReadConsole(In, Reply, ARRAYSIZE(Reply), &Read, {});
SetConsoleMode(In, InMode);
for (size_t i = 0; i != Read; ++i)
{
if (Reply[i] < 0x20)
Reply[i] += 0x2400;
}
if (VtInput)
WriteConsole(Out, L"VT_INPUT=1: ", 12, &Written, {});
else
WriteConsole(Out, L"VT_INPUT=0: ", 12, &Written, {});
WriteConsole(Out, Reply, Read, &Written, {});
WriteConsole(Out, L"\n", 1, &Written, {});
}
int main()
{
test(true);
test(false);
} Expected:
Actual:
I.e. both ESC are missing. |
@alabuzhev how strange! I got the expected response. I did have to recompile it with In the boxes, incoming requests are in gray and responses are in red. The debug tap pre-converts all control characters to control pictures. |
Right, sorry, it's on by default in Visual Studio so I didn't bother to define it manually.
I debugged it and looks like it's not entering this block: Lines 207 to 215 in 10c97a9
|
Alright. We're dropping the ESC because ~ ~ input modes ~ ~. This is an issue with the new ConPTY infrastructure. We will need to fix it before 1.22 exits preview. |
Thanks. Should I create a new issue or you have it tracked already? Requiring VT input is not only potentially a big conpty v2 regression, but a potential source of new bugs: when I'm querying something, I expect a more or less sensible reply, but when VT input is enabled the user can screw everything up by simply pressing some keys.
Pushing these responses to the front of the input queue might help, but I guess you've been there already: terminal/src/host/outputStream.cpp Lines 44 to 48 in 0a7c258
|
Ugh, it's the same without VT. |
To be fair, I think that is true of any terminal emulator that supports reporting. By its nature as an in-band signaling protocol, it is within some other band ;P |
Just on this point, it's worth noting that there's a mode ( |
I believe this is related - in my project (tcl based) All seems to work fine again in canary - sorry for the noise |
Yay, you beat me to it! Thanks for testing Canary! |
This pull request adds support for querying all of the "dynamic
resource" colors (foreground, background, cursor) as well as the entire
color palette using OSC 4, 10, 11 and 12 with the
?
color specifier.To ease integration and to make it easier to extend later, I have
consolidated
SetDefaultForeground
,SetDefaultBackground
andSetCursorColor
into one functionSetXtermColorResource
, plus itsanalog
RequestXtermColorResource
.Those functions will map xterm resource OSC numbers to color table
entries and optionally color alias entries using a constant table. The
alias mappings are required to support reassigning the default
foreground and background to their indexed entries after a
DECAC
.While there are only three real entries in the mapping table right now,
I have designs on bringing in selection background (xterm "highlight")
and foreground (xterm "highlightText").
We can also extend this to support resetting via OSC 110-119. However,
at the adapter layer we do not have the requisite information to restore
any of the colors (even the cursor color!) to the user's defaults.
OSC 10
andOSC 11
queries report the final values ofDECAC
-reassigned entries, under the assumption that an applicationasking for them wants to make a determination regardless of their
internal meaning to us (that is: they read through the aliased color to
its final destination in the color palette.)
I've tested this with lsix, which detects the background color before
generating sixel previews. It works great!
ConPTY does not currently pass OSC sequences received on the input
handle, so work was required to make it do so.
Closes #3718