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

Cursor color escape codes #184

Closed
sibomots opened this issue Nov 15, 2020 · 4 comments
Closed

Cursor color escape codes #184

sibomots opened this issue Nov 15, 2020 · 4 comments

Comments

@sibomots
Copy link

sibomots commented Nov 15, 2020

I'm interested in finding the escape codes to send to a Console (think: win32 console application) that will change the color of the cursor

Environment:

  • Windows 10
  • Visual Studio 2019.
  • C++
  • Win32 Console Application. Plain old console app.

I've read through:
terminal sequences

I've examined other documents such as:
Wikipedia ANSI Codes

I've looked at the Properties panel of the Console App itself and under Terminal >> There's a setting for Cursor Color!

But, what I'm looking for is the exact escape codes to send to the stdout of my Win32 console application.

Eg:
To change the shape of the cursor (Windows environment as listed above):

#define CSI "\x1b["
// ...

// Make block cursor.
printf(CSI "2 q");

Another example of what does work fairly cross-platform:

// Modify the text color... (snagged off Wikipedia)
int stuff(void)
{
	int i, j, n;
	for (i = 0; i < 11; i++) {
		for (j = 0; j < 10; j++) {
			n = 10 * i + j;
			if (n > 108) break;
			printf("\033[%dm %3d\033[m", n, n);
		}
		printf("\n");
	}
	return (0);
}

Modifying the text color is fine. I'm actually interested in modifying the cursor color.

To change Cursor color, this works, albeit on Cygwin/Linux:

// codes to set cursor color red.
printf("\e]12;red\a");

But this doesn't work in the Win32 Console Application. I wasn't all that surprised. I just don't know what the right sequence Windows Console (Terminal) expects.

I've searched high and low and cannot find the documentation on what (ESC+ stuff ) to send to the Win32 Console stdout to render a cursor color.

Care to share some guidance on where those codes are to render a specific cursor color?

Thanks.

Edit:

I must have been tired. But, I realized a work-around. I cannot change the color of the cursor, but I can change the color of the text.. Not that exciting, I know.. But.. it means since the default behavior is to invert the color of the text when rendering the cursor, I can (sort of) force the cursor color by choosing a text color (actually background color to think of it) that is the inverted color. Not ideal. Though, but for the purposes I have, it will be a work-around.

Terminal-Cursor-Color hits --more--
Terminal-Cursor-Color hits --more--

Anyway -- if the Doc team for Terminal (Console terminal, aka Win32 Console App, etc.. Properties) ever decide to document the ESC code that I can emit to cause the cursor color rendering, that would be great.

And... it looks like Cursor color has no alpha channel behavior -- Eg., if you get a Cursor color (manually selected), the character underneath is masked. Not a worry. Maybe later, maybe not.

@DHowett
Copy link
Contributor

DHowett commented Nov 25, 2020

Hey, sorry about missing this. There's a couple issues here!

We just got support for named colors in Terminal 1.4 (or 1.5? I've lost track). The escape you identified actually does work!

image

On older versions you'll need to use rgb:RR/GG/BB (hex); this syntax will also work on the Windows Console

We're trying to make sure we support the xterm appearance OSCs, but we definitely should document that. 😄

@mattwojo
Copy link
Collaborator

Closing - chatted with Kayla and we don't currently have a place in these Terminal docs for this sort of xterm appearance shell content. Let's identify a more appropriate place to doc this if it needs to be covered.

@damnskippy
Copy link

@DHowett @mattwojo sorry to dig this old thread up, but if I do a printf %b '\e]12;red\a', should I expect the cursor color to change to red? Using terminal preview version 1.16.2641.0, doing the above in wsl, I don't see the cursor color changing. It retains the original color specified via the color theme in the settings.
image

@damnskippy
Copy link

damnskippy commented Dec 5, 2022

Maybe this is actually an issue that is tracked via microsoft/terminal#11522, but I"m not so sure since I'm not changing input method or anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants