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

Implement TermResponse auto command for certain terminal response sequences #25856

Closed
gpanders opened this issue Oct 31, 2023 · 1 comment · Fixed by #25868
Closed

Implement TermResponse auto command for certain terminal response sequences #25856

gpanders opened this issue Oct 31, 2023 · 1 comment · Fixed by #25868
Assignees
Labels
enhancement feature request events events, autocommands tui

Comments

@gpanders
Copy link
Member

Problem

The TermResponse autocommand is documented but not implemented. This is ported from Vim, which does implement it.

The documentation states that this autocommand fires when v:termresponse is set, which is in turn set when the Neovim receives a primary device attributes response. None of this is actually true (today).

Expected behavior

We can repurpose this event to provide plugins access to certain terminal response sequences. Of particular interest are OSC 52 and OSC 4.

OSC 52 allows Neovim to read the system clipboard. A plugin can write the sequence OSC 52 ; ; ? ST and the terminal will respond with OSC 52 ; ; <base64 encoded contents of clipboard> ST. We can store this response in v:termresponse and fire a TermResponse autocommand so that plugins can receive the clipboard contents.

Similarly, OSC 4 allows plugins to request the current terminal palette colors.

The autocommand will fire anytime v:termresponse is updated. v:termresponse only contains the most recent value, so plugins must read it in a TermResponse handler before it is overridden by another response sequence.

@gpanders gpanders added the enhancement feature request label Oct 31, 2023
@gpanders gpanders self-assigned this Oct 31, 2023
@zeertzjq zeertzjq added tui events events, autocommands labels Oct 31, 2023
gpanders added a commit to gpanders/neovim that referenced this issue Nov 1, 2023
When the terminal emulator sends an OSC sequence to Nvim (as a response
to another OSC sequence that was first sent by Nvim), populate the OSC
sequence in the v:termresponse variable and fire the TermResponse event.

This makes use of the already documented but unimplemented TermResponse
event. This event exists in Vim but is only fired when Vim receives a
primary device attributes response.

Fixes: neovim#25856
gpanders added a commit to gpanders/neovim that referenced this issue Nov 1, 2023
When the terminal emulator sends an OSC sequence to Nvim (as a response
to another OSC sequence that was first sent by Nvim), populate the OSC
sequence in the v:termresponse variable and fire the TermResponse event.

This makes use of the already documented but unimplemented TermResponse
event. This event exists in Vim but is only fired when Vim receives a
primary device attributes response.

Fixes: neovim#25856
gpanders added a commit to gpanders/neovim that referenced this issue Nov 1, 2023
When the terminal emulator sends an OSC sequence to Nvim (as a response
to another OSC sequence that was first sent by Nvim), populate the OSC
sequence in the v:termresponse variable and fire the TermResponse event.

This makes use of the already documented but unimplemented TermResponse
event. This event exists in Vim but is only fired when Vim receives a
primary device attributes response.

Fixes: neovim#25856
gpanders added a commit to gpanders/neovim that referenced this issue Nov 1, 2023
When the terminal emulator sends an OSC sequence to Nvim (as a response
to another OSC sequence that was first sent by Nvim), populate the OSC
sequence in the v:termresponse variable and fire the TermResponse event.
The escape sequence is also included in the "data" field of the
autocommand callback when the autocommand is defined in Lua.

This makes use of the already documented but unimplemented TermResponse
event. This event exists in Vim but is only fired when Vim receives a
primary device attributes response.

Fixes: neovim#25856
gpanders added a commit to gpanders/neovim that referenced this issue Nov 2, 2023
When the terminal emulator sends an OSC sequence to Nvim (as a response
to another OSC sequence that was first sent by Nvim), populate the OSC
sequence in the v:termresponse variable and fire the TermResponse event.
The escape sequence is also included in the "data" field of the
autocommand callback when the autocommand is defined in Lua.

This makes use of the already documented but unimplemented TermResponse
event. This event exists in Vim but is only fired when Vim receives a
primary device attributes response.

Fixes: neovim#25856
gpanders added a commit to gpanders/neovim that referenced this issue Nov 2, 2023
When the terminal emulator sends an OSC sequence to Nvim (as a response
to another OSC sequence that was first sent by Nvim), populate the OSC
sequence in the v:termresponse variable and fire the TermResponse event.
The escape sequence is also included in the "data" field of the
autocommand callback when the autocommand is defined in Lua.

This makes use of the already documented but unimplemented TermResponse
event. This event exists in Vim but is only fired when Vim receives a
primary device attributes response.

Fixes: neovim#25856
gpanders added a commit that referenced this issue Nov 6, 2023
When the terminal emulator sends an OSC sequence to Nvim (as a response
to another OSC sequence that was first sent by Nvim), populate the OSC
sequence in the v:termresponse variable and fire the TermResponse event.
The escape sequence is also included in the "data" field of the
autocommand callback when the autocommand is defined in Lua.

This makes use of the already documented but unimplemented TermResponse
event. This event exists in Vim but is only fired when Vim receives a
primary device attributes response.

Fixes: #25856
@justinmk
Copy link
Member

We can repurpose this event to provide plugins access to certain terminal response sequences. Of particular interest are OSC 52 and OSC 4.

Also "request version" to decide if we can use 8-bit key sequences:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feature request events events, autocommands tui
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants