cronvel / terminal-kit

Terminal utilities for node.js
MIT License
3.09k stars 200 forks source link

color test not working in kitty #139

Closed zcaudate closed 3 years ago

zcaudate commented 3 years ago

Hi, I was directed to file a bug from the issue here:

https://github.com/kovidgoyal/kitty/issues/3205

cronvel commented 3 years ago

Hi @zcaudate

The comment of @kovidgoyal is right, I'm not using terminfo. Last time I checked, there was multiple things that stopped me from doing that: terminfo has nowhere enough information that what I need, implementing it would need some dependencies I didn't like (maybe need some native code, and that's a big no-go, but I can't remember for sure), and so on...

Also on kitty side, we have to confirm that it set the COLORTERM env variable to truecolor like modern terminal are doing.

Can you run sample/detect-terminal-test.js so I can check that?

kovidgoyal commented 3 years ago

Just FYI you cannot use COLORTERM for color support detection. It is not forwarded over ssh. And yes, kitty does set it. If you cant read terminfo, then I suggest you just unconditionally turn on color support, all modern terminal support it. Maybe blick list the few that dont based on the value TERM.

zcaudate commented 3 years ago

This is the output from running the test

> node sample/detect-terminal-test.js 

== OS and Environment Variables ==

Node version: v15.5.0
OS platform: darwin
OS type: Darwin
OS release: 19.6.0
OS version: Darwin Kernel Version 19.6.0: Thu Jun 18 20:49:00 PDT 2020; root:xnu-6153.141.1~1/RELEASE_X86_64
$TERM: xterm-kitty
$COLORTERM: truecolor
$VTE_VERSION: (undefined)
$TERM_PROGRAM: (undefined)

== Using simple terminal guessing ==

.guessTerminal(): {"isTTY":true,"isSSH":false,"appId":"xterm-kitty","safe":true,"generic":"xterm-kitty"}
Terminal name: (undefined)
Terminal app ID: xterm-kitty
Generic terminal: xterm-kitty
Config file: xterm.generic.js

Support for delta escape sequence: OK
Support for 256 colors: NO
Support for true colors: NO
Support for cursor location request: OK (x: 38, y: 42)
Support for palette request: OK
Issue #116 CURSOR_LOCATION keymap: OK
Issue #116 cursorLocation handler: OK

== Using advanced terminal detection ==

Can't get parent terminal info: Error [Error]: Terminal not found, app names: bash, kitty, launchd
    at Object.exports.getParentTerminalInfo (/Users/chris/Development/react/terminal-kit/lib/detectTerminal.js:303:13)
    at processTicksAndRejections (node:internal/process/task_queues:93:5)
    at async detect (/Users/chris/Development/react/terminal-kit/sample/detect-terminal-test.js:102:10)
Terminal name: (undefined)
Terminal app ID: xterm-kitty
Generic terminal: xterm-kitty
Config file: xterm.generic.js

Support for delta escape sequence: OK
Support for 256 colors: NO
Support for true colors: NO
Support for cursor location request: OK (x: 38, y: 50)
Support for palette request: OK
Issue #116 CURSOR_LOCATION keymap: OK
Issue #116 cursorLocation handler: OK
zcaudate commented 3 years ago

and

❯  echo $COLORTERM
truecolor
NuSkooler commented 3 years ago

Question: Is terminal-kit querying device attributes at all? Many terminals will ID themselves. It appears kitty supports DA responses: https://github.com/kovidgoyal/kitty/blob/ca65ad6fa387745ffdaa9fd5b361bae8a0dfb464/kitty/screen.c#L1400

cronvel commented 3 years ago

@kovidgoyal I know that COLORTERM is not forwarded with SSH, but most of time you are running local app. Furthermore, most terminal advertise themself as xterm anyway because terminfo are not shared between host and client, and all system have terminfo for xterm. E.g. if the server does not have kitty, the app (that is running server-side) could not find terminfo for it...

I just added a config for kitty, as of v1.45.3. It should be fine know. But it's not fine-tuned, it's fully based on xterm with true-color support.

cronvel commented 3 years ago

@NuSkooler You seem to be very knowledgeable about terminal, can you tell me if there is a reliable way to detect 256/true color support by directly asking the terminal? My only resource for ESC seq is invisible island, but the doc is pretty harsh. CSI c seems to be the ESC seq to send, but I don't know what to do with the response.

Also I fear that sending such request on backward terminals (e.g. most windows terminals) would just end up outputting bad chars or crashing the whole thing (also I could skip this test if windows is detected).

cronvel commented 3 years ago

@NuSkooler @kovidgoyal My gnome-terminal responds to CSI>c with CSI>65;6201;1c. But I don't know what to do with it. 65 means it support VT525, 6201 is the same as the env variable VTE_VERSION, and the final 1? Is this for VT100? Kitty responds with CSI>1;4000;19c, again, I don't know what 4000 is for.

kovidgoyal commented 3 years ago

DA is useless, it denotes VT terminal compliance. VT terminals never had true color, compliance levels are pointless. Not to mention that no terminal emulator actually fully simulates a hardware VT terminal. Doing so would be both pointless and actually counterproductive.

If you want to detect the terminal name use XTGETCAP (search for it on the xterm ctl seqs page). kitty even comes with a nice kitten so you can do

kitty +kitten query_terminal name: Terminal name (xterm-kitty) version: Terminal version, for e.g.: 0.19.2 allow_hyperlinks: yes, no or ask

cronvel commented 3 years ago

Now I remember what was wrong with terminfo, the only lib doing that on Node.js is deprecated and only works with the old/legacy terminfo format. I'm checking if I can fix it easily...

NuSkooler commented 3 years ago

@cronvel Ironically DA is often not super helpful for features but many terminals identify themselves (vs TERM which is very often just "xterm" or something even more generic). With a concrete ID you can ignore TERM and map to the appropriate .js rule set / terminfo.

As far as asking a terminal directly if it supports various color modes, no I don't know of a nice way (besides what is described above and inspecting e.g. -truecolor suffixes).

NuSkooler commented 3 years ago

@kovidgoyal I don't see "XTGETCAP" mentioned on Xterm's sequence. In fact a Google of "XTGETCAP" yields no results. Can you link what you're referring to?

cronvel commented 3 years ago

@NuSkooler It's XTGETTCAP with two 'T'. I tested it, but I can't make it work.

NuSkooler commented 3 years ago

Ah OK yes, it should return a full terminfo string. https://xtermjs.org/docs/api/vtfeatures/

cronvel commented 3 years ago

Erf... Even xterm does not respond to XTGETTCAP (with "TN" as the name, or whatever). I'm always surprised that even xterm does not support most of its own standard -_-' Aside from kitty, is there any term supporting this? Too bad, it would be super useful for SSH...

NuSkooler commented 3 years ago

@cronvel I have a spreadsheet of terminal support. I'll do some testing on this as well and see what I come up with. It does seem odd that Xterm would not support it.

cronvel commented 3 years ago

@NuSkooler DA (tertiary) is not well supported too, tested 7 or 8 terminals, xterm reports a lot of "0", gnome-terminal and terminal derived from it report "~VTE", others don't respond anything.

NuSkooler commented 3 years ago

@cronvel Yep, I have a list of some that do support it, but the majority do not.

Detecting terminals and features is not a easy task (and in many is impossible -- you just have to ask the user). There is certainly no single way to do it.