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

Document the Win32 API for using 24-bit colors in the new console host #1118

Closed
be5invis opened this issue Sep 23, 2016 · 12 comments
Closed
Assignees

Comments

@be5invis
Copy link

So we can use this function either.

@fpqc
Copy link

fpqc commented Sep 23, 2016

@bitcrazed left a blogpost on the console team blog promising documentation.

@zadjii-msft
Copy link
Member

We're not planning on expanding the Win32 API surface for this feature. Every function we add to the Console API just creates another point of incompatibility with linux terminal applications.

If you want to use the new color support in your application, you'll have to use VT sequences. Support can be enabled with SetConsoleMode (see https://msdn.microsoft.com/en-us/library/windows/desktop/mt638032(v=vs.85).aspx#Output_Sequences).

The sequences to emit actual colors are as follows

Pm = 3 8 ; 2 ; Pr; Pg; Pb -> Set foreground color to the closest match in xterm's palette for the given RGB Pr/Pg/Pb.
Pm = 3 8 ; 5 ; Ps -> Set foreground color to Ps.
Pm = 4 8 ; 2 ; Pr; Pg; Pb -> Set background color to the closest match in xterm's palette for the given RGB Pr/Pg/Pb.
Pm = 4 8 ; 5 ; Ps -> Set background color to Ps.

(from http://invisible-island.net/xterm/ctlseqs/ctlseqs.html)

We're not going to be adding any API for reading the colors back out with 24-bit color, and as far as I know there are no VT sequences for reading the buffer or it's attributes.

@fpqc
Copy link

fpqc commented Sep 23, 2016

Ha, that's really really cool. I just opened powershell for work, and it's doing dynamic text coloring? Was that added in this build? It looks like FiSH almost (at least when I typed in exit?)

@benhillis benhillis removed the backlog label Sep 24, 2016
@fpqc
Copy link

fpqc commented Sep 24, 2016

@zadjii-msft Was looking over that documentation. I tried the naïve thing and tried entering those escapes inside of a console window with bash.exe running (since it has VT processing enabled), and as I am sure you know, I learned that lots of those escapes don't work like that, sitting down typing them directly in like that (I'm sure it's the same if you just sit down and do it in xterm).

Is there like an escape sequence "sandbox" (or a setting or program in WSL or something) that you can sit down in front of and just type escape sequences to see what they do?

@therealkenc
Copy link
Collaborator

Try something like the following in bash (I might be misunderstanding the question):

printf "\x1b[38;2;255;0;0mRED \x1b[0m\x1b[38;2;0;255;0mGREEN \x1b[0m\x1b[38;2;0;0;255mBLUE \x1b[0m\x1b[38;2;255;255;0mYELLOW \x1b[0m\x1b[38;2;255;0;255mMAGENTA \x1b[0m\x1b[38;2;0;255;255mCYAN\x1b[0m\n"

@fpqc
Copy link

fpqc commented Sep 25, 2016

@therealkenc I was sitting there pressing the escape key then some keys following it. I was able to insert an uparrow with Esc [ A, and I found that Esc [ is the same as Alt+[ and also Ctrl+[ [

But when I tried typing in the escape sequence to say, underline text, Esc [ 4 m, it didn't do anything. (And in general was screwy with longer sequences, not keeping them escaped).

Also, when I tried the manual cursor move escapes (the first ones in the docs), it didn't do much (Esc A being movecursor up, which should I assume move the caret up into previous lines of entry?)

@jcotton42
Copy link

@fpqc that's the PSReadline module

@fpqc
Copy link

fpqc commented Sep 25, 2016

@jcotton42 I guess it comes stock now? That's cool!

@zadjii-msft
Copy link
Member

@fpqc Okay, so this isn't the prettiest code in the world, but it should provide a base for what you're looking for. Just stick this in any old python file and run it. Type in whatever characters you want for your CSI sequence and hit enter.

import sys

def csi(seq):
    sys.stdout.write('\x1b[{}'.format(seq))

def main(argv):
    while(True):
        user_input = str(raw_input('Enter sequence to emit'))
        csi(user_input)


if __name__ == '__main__':
    main(sys.argv)

So, for example, if you want to test the sequence ^[[A, you'd type in A and it would emit ^[[A to the terminal.

It's not great, but it is a playground. Also good to know is that cmd.exe has support for VT sequences enabled by default, so you can test some of the effects right from the prompt, using Ctrl-[ to input the escape character.
image

@fpqc
Copy link

fpqc commented Sep 26, 2016

@zadjii-msft Cool! By the way, I was messing around trying to get some of the powerline-patched fonts working in conhost, and they actually do work fine, but the trick is that you have to use the .ttf versions (many of which you have to manually re-patch yourself. Is there any reason Conhost won't use .otf? I thought MS and Adobe developed OTF as a replacement for .ttf, but for some reason conhost can't use them. Don't know if it would be difficult to implement, but something worth taking a quick glance at! Anyway, nice work!

@bitcrazed
Copy link
Contributor

Closing as by-design.

@bitcrazed bitcrazed self-assigned this Jan 13, 2017
@determin1st
Copy link

determin1st commented Mar 3, 2024

so which sequence determines color mode for the "new conhost"?

OSC 10/11 is empty in the older, means 4 bits (okay)
OSC 10/11 is empty in the new (ran on win10 recently), means 24 bits?

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

No branches or pull requests

8 participants