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()returnstrue- the timeout fires (and
opts.on_timeoutis called, if given) - the caller explicitly deletes the returned autocmd id
payloadstringSequence 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_timeoutoptional fn called when the timeout fires.group: augroup for the TermResponse autocmd.chan: only handle responses from this channel.
on_responsefun(resp: string) -> nil | booleanCalled for each TermResponse. Return
trueto stop listening.
- 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.
function M.query(caps: table | string, on_response: fun(cap: string, found: boolean, seq: nil | string) -> nil) -> nilcapstable | stringA terminal capability or list of capabilities to query
opts{ chan: integer?, group: (string|integer)?, on_timeout: (fun())?, timeout: integer? } | nilon_responsefun(cap: string, found: boolean, seq: nil | string) -> nilCalled for each capability in
caps.foundis true if the capability was found, else false.seqis the control sequence if found, or nil for boolean capabilities.
- 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.
function M.query_apc(payload: string, on_response: fun(resp: string) -> nil | boolean) -> nilpayloadstringAPC 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 | booleanCallback invoked for each APC TermResponse
- nil
function M._get_termdefs() -> nil | table
Get user overrides for terminfo entries as a table. See |$NVIM_TERMDEFS|