Welcome!

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

SignUp Now!

Does %$ contain CSI (<ESC>[)?

May
13,802
211
I'd like a function, say @CSI, that will be 1 if %$ contains a control sequence initiator and 0 otherwise. Given its intended use, I should be looking for "^e[". I've spent hours struggling with @REGEX with no satisfaction.

I think I can get @REGEX to do the right thing. Note: \^ and \[ remove the regex-special meanings of ^ and [.

Code:
v:\> echo %@regex["\^e\[",^e[0m]
1

v:\> echo %@regex["\^e\[","^e[0m"]
1

v:\> echo %@regex["\^e\[","^e0m"]
0

But it fails (why?) when I try to wrap that up in @CSI.

Code:
v:\> function CSI `%@regex["\^e\[",%$]`

v:\> echo %@csi[^e[0m]
0

v:\> echo %@csi[`^e[0m`]
0

v:\> echo %@csi["^e[0m"]
0

Any ideas?
 
Are you looking for strings containing that particular sequence of two characters, or are you looking for strings that TCC will expand into strings containing the sequence? It seems to me that the first is much simpler; use %@index.

Trying to second-guess what TCC's parser will do with a string is much more complicated. The ASCII ESC alone could be ^e or ^E or %@char[27] or %@char[0x1b].... Better to let TCC expand it for you, and then look for a CSI. If you're using TCC internal functions, ExpandVariables() has already been done for you. EscapeLine() maybe or maybe not, depending.
 
EscapeLine() maybe or maybe not, depending.

That's one problem. I don't know if that's happening or not.

If I do come up with a function I'll want to use it in an alias, and that's problematic. See this thread for a simplified version of that problem.
 
I gave up (too frustrating) but I'd still like to see a UDF that does with this plugin does.

Code:
INT WINAPI f_CSI(LPWSTR psz)
{
    if ( stristr(psz, L"^e[") != nullptr || stristr(psz, L"\x1B[") != nullptr )
        psz[0] = L'1';
    else
        psz[0] = L'0';
    psz[1] = UNICODE_NULL;
    return 0;
}
 
Back
Top