Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

When a control sequence stuffs info into stdin?

May
13,828
211
[At least I think that's how it works]. A control sequence like OSC 4 ; 0 ; ? ST is supposed to write to stdin the appropriate sequence for setting palette color 0 (in this example). That works in CMD (though the result looks a little screwy, 0c0c instead of just 0c).

Code:
Microsoft Windows [Version 10.0.19045.5131]
(c) Microsoft Corporation. All rights reserved.

v:\> echo %esc%]4;0;?%esc%\

v:\> ^[]4;0;rgb:0c0c/0c0c/0c0c^[\

Are there any tricks to getting it to work in TCC? I just get garbage.

1732153636920.webp
 
TCC has no control over this; the escape processing is being done by Windows and TCC never sees it.
In this case the sequence I send is a query sequence. The answer to the query is a plain-text rendition of the sequence necessary to effect the queried setting; this answer is "stuffed" into stdin. Below (in CMD), I typed the query at the first prompt; what appears after the second prompt was poked into stdin as the answer to my query. This particular query is for the selection background color spec.

1732199448723.webp
 
I don't need to do this at the command line (but I still wonder if any tricks would make it work).

In a plugin, querying and grabbing the response is pretty easy. After adding ENABLE_VIRTUAL_TERMINAL_INPUT to and removing ENABLE_LINE_INPUT from the console input mode, I write the query with WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),...) and immediately read the response with ReadConsole(GetStdHandle(STD_INPUT_HANDLE),...).

As for the response numbers not looking right (0c0c vs. 0c), they're actually correct! It goes something like this (thanks to the guys in the WT forum).

Think of the amount of a color as a fraction (0~1) of the max, and consider how many bits you're going to use to represent that amount using an integer. In a nutshell, these fractions are all the same, and the responses from OSC queries choose to use 16 bits (the second one).

Code:
0x0c / 0xff
0x0c0c / 0xffff
0x0c0c0c / 0xffffff
0x0c0c0c0c / 0xffffffff
 
There's a lot of different ways to "stuff" input into STDIN. And unlike CMD (which gets its stdin from a line input API), TCC gets its from character input.

But TCC never, ever, ever does ANSI escape sequence processing. That is done by Windows long before anything arrives in TCC's stdin (or in the case of stdout, after TCC sends the string to the Windows output API).
 
Back
Top