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

detect kitty default background color at runtime for workaround #1292

Closed
dankamongmen opened this issue Jan 15, 2021 · 9 comments · Fixed by #1779
Closed

detect kitty default background color at runtime for workaround #1292

dankamongmen opened this issue Jan 15, 2021 · 9 comments · Fixed by #1779
Assignees
Labels
bug Something isn't working
Milestone

Comments

@dankamongmen
Copy link
Owner

As discussed in #1117, kitty treats a setbf that equals the default background color as background, in order to e.g. provide transparent backgrounds for apps that don't explicitly use the default background color.

We work around this by changing the background color by 1 when it is 0x000000. If the default background color isn't 0x000000, though, this isn't going to work. We need to detect the default background color at runtime to handle this fully generally.

@kovidgoyal, you mentioned in that bug that you would implement the xterm sequences corresponding to this. I am unaware of any such XTerm sequence (AFAIK, XTerm implements OSC 4 ; N; ? ST s.t. 0 ≤ N ≤ 255). ITerm2 implements:

OSC 4 ; -2; ? ST (get default background)
OSC 4 ; -1 ; ? ST (get default foreground)

did Kitty ever get support for these, or something else? Testing with the current head (0.19.3+) seems to indicate support for palette lookup (0..255), but not -1/-2.

@dankamongmen dankamongmen added the bug Something isn't working label Jan 15, 2021
@dankamongmen dankamongmen self-assigned this Jan 15, 2021
@kovidgoyal
Copy link

You want OSC 6 not OSC 4 see https://invisible-island.net/xterm/ctlseqs/ctlseqs.html

@kovidgoyal
Copy link

And the escape codes i was talking about were for the color stack, i.e. saving the current color table and dynamic colors on a stack so that you can change them. OSC 6 which is used to set and report the dynamic colors (bg, fg, selection ,etc) has been supported in kitty since forever.

@dankamongmen dankamongmen added this to the 3.0.0 milestone May 10, 2021
@dnkl
Copy link
Contributor

dnkl commented May 10, 2021

Perhaps I don't have the full context here, and is misreading what is being said here. If so, I apologize.

But it sounds like it's being suggested here that OSC 6 can be used to set and retrieve default fg/bg/selection colors. That's not true, at least not in XTerm.

OSC 6 is related to OSC 5. OSC 5 sets XTerm's Special colors:

              Pc = 0  ⇐  resource colorBD (BOLD).
              Pc = 1  ⇐  resource colorUL (UNDERLINE).
              Pc = 2  ⇐  resource colorBL (BLINK).
              Pc = 3  ⇐  resource colorRV (REVERSE).
              Pc = 4  ⇐  resource colorIT (ITALIC).

The user can enable modes where XTerm renders e.g. underline text, not with underlines, but with a custom color. OSC 5 sets the color, and OSC 6 enables/disables the mode.

I.e. if you do

echo -e '\e]5;1;rgb:ff/00/00\e\\`
echo -e '\e]6;1;1\e\\`

Then

echo -e '\e[4mhello\e[m'

will be rendered in red, but not underlined.

To set/get fg/bg/selection colors, use OSC 10-19:

            Ps = 1 0  ⇒  Change VT100 text foreground color to Pt.
            Ps = 1 1  ⇒  Change VT100 text background color to Pt.
            Ps = 1 2  ⇒  Change text cursor color to Pt.
            Ps = 1 3  ⇒  Change pointer foreground color to Pt.
            Ps = 1 4  ⇒  Change pointer background color to Pt.
            Ps = 1 5  ⇒  Change Tektronix foreground color to Pt.
            Ps = 1 6  ⇒  Change Tektronix background color to Pt.
            Ps = 1 7  ⇒  Change highlight background color to Pt.
            Ps = 1 8  ⇒  Change Tektronix cursor color to Pt.
            Ps = 1 9  ⇒  Change highlight foreground color to Pt.

Granted, the documentation is perhaps not structured in the best possible way, and is easy to misread.

@kovidgoyal
Copy link

kovidgoyal commented May 10, 2021

yes, sorry, OSC 10-19 and 110-119, not OSC 6

@dankamongmen
Copy link
Owner Author

we're now sending the query along with our other ones at initialization, and getting a response from at least Kitty and Alacritty:

[schwarzgerat](0) $ grep background .config/kitty/kitty.conf 
background_opacity 0.7
background #002211
[schwarzgerat](0) $ 

and

[schwarzgerat](0) $ ./notcurses-info 
\\state:  0 char:    27 1b
state:  1 char: ]  93 5d
state:  1 char: 1  49 31
state:  1 char: 1  49 31
state:  1 char: ;  59 3b
state:  1 char: r 114 72
state:  1 char: g 103 67
state:  1 char: b  98 62
state:  1 char: :  58 3a
state:  1 char: 0  48 30
state:  1 char: 0  48 30
state:  1 char: 0  48 30
state:  1 char: 0  48 30
state:  1 char: /  47 2f
state:  1 char: 2  50 32
state:  1 char: 2  50 32
state:  1 char: 2  50 32
state:  1 char: 2  50 32
state:  1 char: /  47 2f
state:  1 char: 1  49 31
state:  1 char: 1  49 31
state:  1 char: 1  49 31
state:  1 char: 1  49 31
state:  1 char:    27 1b
state:  1 char: \  92 5c
state:  0 char:    27 1b

@dankamongmen
Copy link
Owner Author

 notcurses 2.3.4 by nick black et al on Kitty
  70 rows (20px) 107 cols (10px) (117.03KiB) 48B crend 256 colors+RGB
  compiled with gcc-10.2.1 20210110, 16B little-endian cells
  terminfo from ncurses 6.2.20201114
  avformat 58.79.100 avutil 56.74.100 swscale 5.10.100

 Colors: 256 rgb: y ccc: y setaf: y setab: y
 sgr: y sgr0: y op: y fgop: y bgop: y
 rows: 70 cols: 107 rpx: 20 cpx: 10 (1400x1070)
 rgba pixel graphics supported
 utf8: y quad: y sex: y braille: y images: y videos: y
 { ▀▄█} { ▘▝▀▖▌▞▛▗▚▐▜▄▙▟█} ⎧ 🬀🬁🬂🬃🬄🬅🬆🬇🬈🬊🬋🬌🬍🬎🬏🬐🬑🬒🬓▌🬔🬕🬖🬗🬘🬙🬚🬛🬜🬝⎫ ⎧┌┐─⎫ ⎧┏┓━⎫ ⎧█ ⎫ 🯰🯱
                           ⎩🬟🬠🬡🬢🬣🬤🬥🬦🬧▐🬨🬩🬪🬫🬬🬭🬮🬯🬰🬱🬲🬳🬴🬵🬶🬷🬸🬹🬺🬻█⎭ ⎩└┘│⎭ ⎩┗┛┃⎭ ⎪🮋▏⎪ 🯲🯳
                                                             ⎧╭╮─⎫ ⎧╔╗═⎫ ⎪🮊▎⎪ 🯴🯵
                                                             ⎩╰╯│⎭ ⎩╚╝║⎭ ⎪🮉▍⎪ 🯶🯷
 ⎡⠀⠁⠈⠉⠂⠃⠊⠋⠐⠑⠘⠙⠒⠓⠚⠛⠄⠅⠌⠍⠆⠇⠎⠏⠔⠕⠜⠝⠖⠗⠞⠟⠠⠡⠨⠩⠢⠣⠪⠫⠰⠱⠸⠹⠲⠳⠺⠻⠤⠥⠬⠭⠦⠧⠮⠯⠴⠵⠼⠽⠶⠷⠾⠿⎤      ⎪🮉▍⎪ 🯸🯹
 ⎢⡀⡁⡈⡉⡂⡃⡊⡋⡐⡑⡘⡙⡒⡓⡚⡛⡄⡅⡌⡍⡆⡇⡎⡏⡔⡕⡜⡝⡖⡗⡞⡟⡠⡡⡨⡩⡢⡣⡪⡫⡰⡱⡸⡹⡲⡳⡺⡻⡤⡥⡬⡭⡦⡧⡮⡯⡴⡵⡼⡽⡶⡷⡾⡿⎥      ⎨▐▌⎬
 ⎢⢀⢁⢈⢉⢂⢃⢊⢋⢐⢑⢘⢙⢒⢓⢚⢛⢄⢅⢌⢍⢆⢇⢎⢏⢔⢕⢜⢝⢖⢗⢞⢟⢠⢡⢨⢩⢢⢣⢪⢫⢰⢱⢸⢹⢲⢳⢺⢻⢤⢥⢬⢭⢦⢧⢮⢯⢴⢵⢼⢽⢶⢷⢾⢿⎥      ⎪🮈▋⎪
 ⎣⣀⣁⣈⣉⣂⣃⣊⣋⣐⣑⣘⣙⣒⣓⣚⣛⣄⣅⣌⣍⣆⣇⣎⣏⣔⣕⣜⣝⣖⣗⣞⣟⣠⣡⣨⣩⣢⣣⣪⣫⣰⣱⣸⣹⣲⣳⣺⣻⣤⣥⣬⣭⣦⣧⣮⣯⣴⣵⣼⣽⣶⣷⣾⣿⎦      ⎪🮇▊⎪
  ⎛ ▁▂▃▄▅▆▇█⎞ ▔🭶🭷🭸🭹🭺🭻▁                                                   ⎪▕▉⎪
  ⎝█🮆🮅🮄▀🮃🮂▔ ⎠ ▏🭰🭱🭲🭳🭴🭵▕                                                   ⎩ █⎭
 background of 0x002211 is considered transparent  <---------------------------------------------------------
 cup: y vpa: y hpa: y
[schwarzgerat](0) $ 

w00t!

@dankamongmen
Copy link
Owner Author


 notcurses 2.3.4 by nick black et al on Alacritty
  70 rows (20px) 80 cols (10px) (87.50KiB) 48B crend 256 colors+RGB
  compiled with gcc-10.2.1 20210110, 16B little-endian cells
  terminfo from ncurses 6.2.20201114
  avformat 58.79.100 avutil 56.74.100 swscale 5.10.100

 Colors: 256 rgb: y ccc: y setaf: y setab: y
 sgr: y sgr0: y op: y fgop: y bgop: y
 rows: 70 cols: 80 rpx: 20 cpx: 10 (1400x800)
 max sixel size: 4096x4096 colorregs: 1024
 utf8: y quad: y sex: n braille: y images: y videos: y
 { ▀▄█} { ▘▝▀▖▌▞▛▗▚▐▜▄▙▟█} ⎧ 🬀🬁🬂🬃🬄🬅🬆🬇🬈🬊🬋🬌🬍🬎🬏🬐🬑🬒🬓▌🬔🬕🬖🬗🬘🬙🬚🬛🬜🬝⎫ ⎧┌┐─⎫ ⎧┏┓━⎫ ⎧█ ⎫ 🯰🯱
                           ⎩🬟🬠🬡🬢🬣🬤🬥🬦🬧▐🬨🬩🬪🬫🬬🬭🬮🬯🬰🬱🬲🬳🬴🬵🬶🬷🬸🬹🬺🬻█⎭ ⎩└┘│⎭ ⎩┗┛┃⎭ ⎪🮋▏⎪ 🯲🯳
                                                             ⎧╭╮─⎫ ⎧╔╗═⎫ ⎪🮊▎⎪ 🯴🯵
                                                             ⎩╰╯│⎭ ⎩╚╝║⎭ ⎪🮉▍⎪ 🯶🯷
 ⎡⠀⠁⠈⠉⠂⠃⠊⠋⠐⠑⠘⠙⠒⠓⠚⠛⠄⠅⠌⠍⠆⠇⠎⠏⠔⠕⠜⠝⠖⠗⠞⠟⠠⠡⠨⠩⠢⠣⠪⠫⠰⠱⠸⠹⠲⠳⠺⠻⠤⠥⠬⠭⠦⠧⠮⠯⠴⠵⠼⠽⠶⠷⠾⠿⎤      ⎪🮉▍⎪ 🯸🯹
 ⎢⡀⡁⡈⡉⡂⡃⡊⡋⡐⡑⡘⡙⡒⡓⡚⡛⡄⡅⡌⡍⡆⡇⡎⡏⡔⡕⡜⡝⡖⡗⡞⡟⡠⡡⡨⡩⡢⡣⡪⡫⡰⡱⡸⡹⡲⡳⡺⡻⡤⡥⡬⡭⡦⡧⡮⡯⡴⡵⡼⡽⡶⡷⡾⡿⎥      ⎨▐▌⎬
 ⎢⢀⢁⢈⢉⢂⢃⢊⢋⢐⢑⢘⢙⢒⢓⢚⢛⢄⢅⢌⢍⢆⢇⢎⢏⢔⢕⢜⢝⢖⢗⢞⢟⢠⢡⢨⢩⢢⢣⢪⢫⢰⢱⢸⢹⢲⢳⢺⢻⢤⢥⢬⢭⢦⢧⢮⢯⢴⢵⢼⢽⢶⢷⢾⢿⎥      ⎪🮈▋⎪
 ⎣⣀⣁⣈⣉⣂⣃⣊⣋⣐⣑⣘⣙⣒⣓⣚⣛⣄⣅⣌⣍⣆⣇⣎⣏⣔⣕⣜⣝⣖⣗⣞⣟⣠⣡⣨⣩⣢⣣⣪⣫⣰⣱⣸⣹⣲⣳⣺⣻⣤⣥⣬⣭⣦⣧⣮⣯⣴⣵⣼⣽⣶⣷⣾⣿⎦      ⎪🮇▊⎪
  ⎛ ▁▂▃▄▅▆▇█⎞ ▔🭶🭷🭸🭹🭺🭻▁                                                   ⎪▕▉⎪
  ⎝█🮆🮅🮄▀🮃🮂▔ ⎠ ▏🭰🭱🭲🭳🭴🭵▕                                                   ⎩ █⎭
 background 0x1d1f21 isn't interpreted as transparent <----------------------------------------------
 cup: y vpa: y hpa: y
[schwarzgerat](0) $

@dankamongmen
Copy link
Owner Author

 notcurses 2.3.4 by nick black et al on XTerm
  24 rows (23px) 80 cols (11px) (30.00KiB) 48B crend 256 colors+RGB
  compiled with gcc-10.2.1 20210110, 16B little-endian cells
  terminfo from ncurses 6.2.20201114
  avformat 58.79.100 avutil 56.74.100 swscale 5.10.100

 Colors: 256 rgb: y ccc: y setaf: y setab: y
 sgr: y sgr0: y op: y fgop: y bgop: y
 rows: 24 cols: 80 rpx: 23 cpx: 11 (552x880)
 max sixel size: 552x880 colorregs: 256
 utf8: y quad: n sex: n braille: y images: y videos: y
 { ▀▄█} { ▘▝▀▖▌▞▛▗▚▐▜▄▙▟█} ⎧ 🬀🬁🬂🬃🬄🬅🬆🬇🬈🬊🬋🬌🬍🬎🬏🬐🬑🬒🬓▌🬔🬕🬖🬗🬘🬙🬚🬛🬜🬝⎫ ⎧┌┐─⎫ ⎧┏┓━⎫ ⎧█ ⎫ 🯰🯱
                           ⎩🬟🬠🬡🬢🬣🬤🬥🬦🬧▐🬨🬩🬪🬫🬬🬭🬮🬯🬰🬱🬲🬳🬴🬵🬶🬷🬸🬹🬺🬻█⎭ ⎩└┘│⎭ ⎩┗┛┃⎭ ⎪🮋▏⎪ 🯲🯳
                                                             ⎧╭╮─⎫ ⎧╔╗═⎫ ⎪🮊▎⎪ 🯴🯵
                                                             ⎩╰╯│⎭ ⎩╚╝║⎭ ⎪🮉▍⎪ 🯶🯷
 ⎡⠀⠁⠈⠉⠂⠃⠊⠋⠐⠑⠘⠙⠒⠓⠚⠛⠄⠅⠌⠍⠆⠇⠎⠏⠔⠕⠜⠝⠖⠗⠞⠟⠠⠡⠨⠩⠢⠣⠪⠫⠰⠱⠸⠹⠲⠳⠺⠻⠤⠥⠬⠭⠦⠧⠮⠯⠴⠵⠼⠽⠶⠷⠾⠿⎤      ⎪🮉▍⎪ 🯸🯹
 ⎢⡀⡁⡈⡉⡂⡃⡊⡋⡐⡑⡘⡙⡒⡓⡚⡛⡄⡅⡌⡍⡆⡇⡎⡏⡔⡕⡜⡝⡖⡗⡞⡟⡠⡡⡨⡩⡢⡣⡪⡫⡰⡱⡸⡹⡲⡳⡺⡻⡤⡥⡬⡭⡦⡧⡮⡯⡴⡵⡼⡽⡶⡷⡾⡿⎥      ⎨▐▌⎬
 ⎢⢀⢁⢈⢉⢂⢃⢊⢋⢐⢑⢘⢙⢒⢓⢚⢛⢄⢅⢌⢍⢆⢇⢎⢏⢔⢕⢜⢝⢖⢗⢞⢟⢠⢡⢨⢩⢢⢣⢪⢫⢰⢱⢸⢹⢲⢳⢺⢻⢤⢥⢬⢭⢦⢧⢮⢯⢴⢵⢼⢽⢶⢷⢾⢿⎥      ⎪🮈▋⎪
 ⎣⣀⣁⣈⣉⣂⣃⣊⣋⣐⣑⣘⣙⣒⣓⣚⣛⣄⣅⣌⣍⣆⣇⣎⣏⣔⣕⣜⣝⣖⣗⣞⣟⣠⣡⣨⣩⣢⣣⣪⣫⣰⣱⣸⣹⣲⣳⣺⣻⣤⣥⣬⣭⣦⣧⣮⣯⣴⣵⣼⣽⣶⣷⣾⣿⎦      ⎪🮇▊⎪
  ⎛ ▁▂▃▄▅▆▇█⎞ ▔🭶🭷🭸🭹🭺🭻▁                                                   ⎪▕▉⎪
  ⎝█🮆🮅🮄▀🮃🮂▔ ⎠ ▏🭰🭱🭲🭳🭴🭵▕                                                   ⎩ █⎭
 background of 0x333333 is not considered transparent
 cup: y vpa: y hpa: y
[schwarzgerat](0) $ 

xterm looks good

@dankamongmen
Copy link
Owner Author

foot now works after some quick sscanf fuckery

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants