nvim_runtime_lua

vim.tty

Methods4

function M.request(payload: string, opts: sub<{ chan: integer?, group: (string|integer)?, on_timeout: (fun())?, timeout: integer? },unknown> | nil, on_response: fun(resp: string) -> nil | boolean) -> integer

Send payload to the host terminal and listen for TermResponse, calling on_response for each response. Cleans up after opts.timeout ms if the callback never returns true.

The autocommand is removed when:

  • on_response() returns true
  • the timeout fires (and opts.on_timeout is called, if given)
  • the caller explicitly deletes the returned autocmd id
Parameters
payloadstring

Sequence to send via nvimuisend(). Use empty string ('') to just register a listener (no sending).

optssub<{ chan: integer?, group: (string|integer)?, on_timeout: (fun())?, timeout: integer? },unknown> | nil

(default: 1000) ms to wait before giving up, or 0 for never (caller must remove the autocmd).

  • on_timeout optional fn called when the timeout fires.
  • group: augroup for the TermResponse autocmd.
  • chan: only handle responses from this channel.
on_responsefun(resp: string) -> nil | boolean

Called for each TermResponse. Return true to stop listening.

Returns
integer

autocmd id of the TermResponse handler.

function M.query(caps: table | string, opts: { chan: integer?, group: (string|integer)?, on_timeout: (fun())?, timeout: integer? } | nil, on_response: fun(cap: string, found: boolean, seq: nil | string) -> nil) -> nil

Query the host terminal emulator for terminfo capabilities.

This function sends the XTGETTCAP DCS sequence to the host terminal emulator asking the terminal to send us its terminal capabilities. These are strings that are normally taken from a terminfo file, however an up to date terminfo database is not always available (particularly on remote machines), and many terminals continue to misidentify themselves or do not provide their own terminfo file, making the terminfo database unreliable.

Querying the terminal guarantees that we get a truthful answer, but only if the host terminal emulator supports the XTGETTCAP sequence.

Overloads
function M.query(caps: table | string, on_response: fun(cap: string, found: boolean, seq: nil | string) -> nil) -> nil
Parameters
capstable | string

A terminal capability or list of capabilities to query

opts{ chan: integer?, group: (string|integer)?, on_timeout: (fun())?, timeout: integer? } | nil
on_responsefun(cap: string, found: boolean, seq: nil | string) -> nil

Called for each capability in caps. found is true if the capability was found, else false. seq is the control sequence if found, or nil for boolean capabilities.

Returns
nil
function M.query_apc(payload: string, opts: { chan: integer?, timeout: integer? }, on_response: fun(resp: string) -> nil | boolean) -> nil

Send an APC sequence to the terminal and call on_response for each APC response received. Cleans up after {timeout} milliseconds if no response is received.

on_response receives the full APC sequence including the \027_ prefix. Return true from on_response to stop listening.

Overloads
function M.query_apc(payload: string, on_response: fun(resp: string) -> nil | boolean) -> nil
Parameters
payloadstring

APC sequence to send (full escape sequence including prefix/suffix)

opts{ chan: integer?, timeout: integer? }

Options table (timeout in milliseconds, default 1000)

on_responsefun(resp: string) -> nil | boolean

Callback invoked for each APC TermResponse

Returns
nil
function M._get_termdefs() -> nil | table

Get user overrides for terminfo entries as a table. See |$NVIM_TERMDEFS|