Skip to content

Support XTGETTCAP sequence #17735

Open
Open

Description

@moetayuko

Description of the new feature/enhancement

neovim uses XTGETTCAP sequence to query osc52 support and enables copying over ssh via osc52 if positive. wt supports osc52 but does not report via XTGETTCAP, so neovim is not aware of it and won't enable osc52 for wt.

Proposed technical implementation details (optional)

neovim/neovim#29504 (comment)

Activity

  1. added
    Issue-Feature
    on Aug 18, 2024
  2. added
    Needs-Tag-Fix
    Needs-Triage
    on Aug 18, 2024
  3. added
    Area-VT
    Product-Terminal
    and removed
    Needs-Triage
    Needs-Tag-Fix
    on Aug 21, 2024
  4. carlos-zamora commented on Aug 21, 2024

    @carlos-zamora

    Depends on #2958 and #1040

  5. cavanaug commented on Feb 18, 2025

    @cavanaug
    Contributor

    Depends on #2958 and #1040

    Why does this depend on [#2958] shouldnt support XTGETTCAP return dynamically what is supported?? Depending on registering a terminfo would also cause all systems connecting to via ssh to have it also.

  6. DHowett commented on Feb 18, 2025

    @DHowett
    Member

    I rather think it means "depends on the part of that issue which requires producing a terminfo" :)

  7. zadjii-msft commented on Nov 23, 2026

    @zadjii-msft
    Member

    Docs:
    https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h4-Device-Control-functions:DCS-plus-q-Pt-ST.F95

    Doesn't really depend on us "registering" one, but we do need a way to author it and have it kept up to date.
    Honestly, it also sounds like doing this would be the right solution to #1040. Probably not good enough for all use cases, but it's strictly better than terminfos

    <conjecture>
    Historically, probably added around 2019?

    image
  8. j4james commented on Nov 24, 2026

    @j4james
    Collaborator

    Note that XTGETTCAP doesn't actually report the terminfo and termcap capabilities that you might expect it to. It's mostly for reporting key sequences. Quoting the Xterm documention:

    The string following the "q" is a list of names ... which correspond to termcap or terminfo capability names for special keyboard keys. other capabilities ... are intentionally not part of this interface.

    Then it goes on to say:

    A few more terminal capabilities are recognized, which are not names of special keys:

    • Co for termcap colors
    • TN for termcap name
    • RGB for the ncurses direct-color extension

    It's basically those three properties and a bunch of key sequences. It's not particularly useful for detecting a terminal's capabilities.

    As for the original justification in the issue description, neovim now detects clipboard support via a DA1 extension (see neovim/neovim#34860), so it's definitely not needed for that.

  9. krobelus commented on Nov 24, 2026

    @krobelus
  10. lhecker commented on Nov 24, 2026

    @lhecker
    Member

    I do think it's enticing for XTGETTCAP to expose all keys. The locally installed terminfo may be a version-mismatch to the terminal that is connecting via e.g. SSH. With this we could expose all sorts of things in a somewhat safe manner, including something that has been absent on Windows for too long: TERM (we are separately looking into fixing that fwiw; no promises).

  11. j4james commented on Nov 24, 2026

    @j4james
    Collaborator

    Leonard Hecker (@lhecker) Just bear in mind that if you want to expose all keys, you can't remain compatible with xterm. As Johannes Altmanninger (@krobelus) noted, a number of terminals have done that, but it's not so much an extension as a hijack of xterm's protocol with their own incompatible variant (and they aren't always compatible with each other).

    And on the subject of TERM, if you're planning on changing the default from xterm-256color, be aware that you're setting yourself up for a life time of bug reports. If you want an idea of what that will look like, just browse the issue trackers of terminals like alacritty (#2838, #3932, #3962, #8677) and ghostty (#896, #3348, #12319, #14342). I've just linked a few examples, but this comes up a lot.

    And they're at least in a position where they can install their terminfo as part of the terminal's installation, and provide shell scripts for installing over ssh, but that hasn't really helped them.

  12. lhecker commented on Nov 24, 2026

    @lhecker
    Member

    As Johannes Altmanninger (@krobelus) noted, a number of terminals have done that, but it's not so much an extension as a hijack of xterm's protocol with their own incompatible variant (and they aren't always compatible with each other).

    I considered it enticing, because we'll otherwise always have the issue of "how do we ship an up-to-date terminfo". I do think having a protocol like that is a nice idea, since it finally ensures terminal and terminfo are in sync. How bad is it to extend the xterm protocol like that?

    And on the subject of TERM, if you're planning on changing the default from xterm-256color, be aware that you're setting yourself up for a life time of bug reports.

    Are you referring to TERM via XTGETTCAP or to my (comment in parenthesis)? For the latter, I was indeed thinking of changing it to ms-terminal, for long-term profit. But that's not something I intend to pursue eagerly. Instead, what I meant was that Dustin was looking into setting env vars in already launched console processes (during handoff). This requires driver changes and so there's some hesitation.

    If you meant TERM via XTGETTCAP, I was assuming the issues would not apply as a client would have to fetch it with XTGETTCAP and then look up keys in its terminfo with the returned value. That seems rather odd to me.
    (I do realize that if we introduce this, applications will immediately use it to write ""workarounds"" for Windows Terminal's behavior, which would be rather sad too.)

  13. j4james commented on Nov 24, 2026

    @j4james
    Collaborator

    it finally ensures terminal and terminfo are in sync

    But how? Nobody is going to use XTGETTCAP to download a full terminfo database. Or so I would hope, because that would be insane. Before you even start you've got to assume: 1. The terminal is ANSI compliant; 2. It supports the DCS control without leaking the content; 3. It supports the XTGETTCAP sequence, and not even the standard form of it, but some undefined extension that will respond in the way that you're hoping. And after assuming all of that, you're still unsure whether you can use an ANSI standard CUP to position the cursor, so you need to look that up in terminfo!?

    All of the places I've seen XTGETTCAP being used have been for a handful of caps at most - and typically non-standard caps like Ms or Smulx. And they often aren't even looking at the response - just treating it like a boolean indication of support, and assuming the sequence format. In most cases there is a standard query you could use to get the same information more reliably, which is what I would advise.

    That said, if you think there is value in trying to support those use cases, feel free. But don't kid yourself that this is some kind of runtime terminfo. It's a giant hack built on top of a sequence that was never intended to do the thing that these people are using it for.

    How bad is it to extend the xterm protocol like that?

    Well the risk is that anyone trying to use XTGETTCAP for its original purpose will break when querying a terminal that doesn't respond in the standard way. This will depend on how you decide to handle things like escaping, multipart queries, unrecognised keys, etc. It might be possible to implement it in a way that is still backwards compatible, but I don't think it will be simple.

    Are you referring to TERM via XTGETTCAP or to my (comment in parenthesis)?

    I was assuming you were planning to change the environment variable, but the XTGETTCAP value would likely have the same effect if apps are using it in the same way (i.e. like a browser user-agent). Incidentally, this is why terminals like ghostty and kitty include xterm in their TERM name. Without that, a lot of apps just won't work properly.

    And yes, once you have a unique TERM name, apps are guaranteed to start using it in the same way as they are now using WT_SESSION. If that's something we want to endorse, we should just go ahead and implement XTVERSION and set the TERM_PROGRAM environment variable instead. That will at least cause less breakage than changing the TERM name.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-VTIssue-FeatureProduct-Terminal

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions