feat(tui): restore 'ttyfast' to control tty requests #38699

Problem:
When running nvim on a remote machine over SSH, if there is high ping,
then bg detection may not complete in time. This results in a warning
every time nvim is started. #38648

Solution:
Restore 'ttyfast' option and allow it to control whether or not bg
detection is performed. Because this is during startup and before any
user config or commands, we use the environment variable
`NVIM_NOTTYFAST` to allow disabling `ttyfast` during initialization.
This commit is contained in:
Kyle
2026-04-24 13:45:20 -05:00
committed by GitHub
parent 393f687503
commit 66149ca668
11 changed files with 53 additions and 9 deletions

View File

@@ -164,6 +164,8 @@ the same range instances now compare equal.
OPTIONS
• 'ttyfast' can be disabled during startup by setting the environment variable
`NVIM_NOTTYFAST` to disable automatic background detection.
• 'scrolloffpad' allows vertically centering cursor at the end of file.
• 'winpinned' prevents window from closing unless specifically targeted.

View File

@@ -7010,6 +7010,16 @@ A jump table for the options with a short description can be found at |Q_op|.
used for CTRL-\ CTRL-N and CTRL-\ CTRL-G when part of a command has
been typed.
*'ttyfast'* *'tf'* *'nottyfast'* *'notf'*
'ttyfast' 'tf' boolean (default on)
global
Assume that the underlying terminal can respond quickly to queries
required by features such as 'background' detection.
Nvim issues terminal queries before reading the user's |config| file,
so disabling this option there will not work. Set $NVIM_NOTTYFAST
before starting Nvim to disable terminal queries.
*'undodir'* *'udir'* *E5003*
'undodir' 'udir' string (default "$XDG_STATE_HOME/nvim/undo//")
global

View File

@@ -88,7 +88,9 @@ Defaults *defaults* *nvim-defaults*
host terminal
- 'ttimeout' is enabled
- 'ttimeoutlen' defaults to 50
- 'ttyfast' is always set
- 'ttyfast' is set by default, but it can be unset during startup by setting
the environment variable `NVIM_NOTTYFAST` to adjust the startup sequence for
slow environments.
- 'undodir' defaults to ~/.local/state/nvim/undo// (|xdg|), auto-created
- 'viewoptions' includes "unix,slash", excludes "options"
- 'viminfo' includes "!"
@@ -877,7 +879,6 @@ Options:
- *'toolbar'* *'tb'*
- *'toolbariconsize'* *'tbis'*
- *'ttybuiltin'* *'tbi'* *'nottybuiltin'* *'notbi'*
- *'ttyfast'* *'tf'* *'nottyfast'* *'notf'*
- *'ttymouse'* *'ttym'*
- *'ttyscroll'* *'tsl'*
- *'ttytype'* *'tty'*

View File

@@ -847,7 +847,10 @@ do
--- ignored in the calculations.
---
--- [1] https://en.wikipedia.org/wiki/Luma_%28video%29
do
---
--- In slow environments (e.g. SSH with high latency), this will increase
--- startup time and produce a warning, so users may want to disable it.
if vim.o.ttyfast then
--- Parse a string of hex characters as a color.
---
--- The string can contain 1 to 4 hex characters. The returned value is
@@ -999,7 +1002,7 @@ do
and os.getenv('NVIM_TEST') == nil
then
vim.notify(
'defaults.lua: Did not detect DSR response from terminal. This results in a slower startup time.',
"defaults.lua: Did not detect DSR response from terminal for 'background' detection. This results in a slower startup time. To disable this and other 'ttyfast' features during startup, set the environment variable NVIM_NOTTYFAST",
vim.log.levels.WARN,
{ _truncate = true }
)
@@ -1017,7 +1020,7 @@ do
-- The TUI was able to determine truecolor support or $COLORTERM explicitly indicates
-- truecolor support
setoption('termguicolors', true)
elseif colorterm == nil or colorterm == '' then
elseif (colorterm == nil or colorterm == '') and vim.o.ttyfast then
-- Neither the TUI nor $COLORTERM indicate that truecolor is supported, so query the
-- terminal
local caps = {} ---@type table<string, boolean>

View File

@@ -7555,6 +7555,19 @@ vim.o.ttm = vim.o.ttimeoutlen
vim.go.ttimeoutlen = vim.o.ttimeoutlen
vim.go.ttm = vim.go.ttimeoutlen
--- Assume that the underlying terminal can respond quickly to queries
--- required by features such as 'background' detection.
---
--- Nvim issues terminal queries before reading the user's `config` file,
--- so disabling this option there will not work. Set $NVIM_NOTTYFAST
--- before starting Nvim to disable terminal queries.
---
--- @type boolean
vim.o.ttyfast = true
vim.o.tf = vim.o.ttyfast
vim.go.ttyfast = vim.o.ttyfast
vim.go.tf = vim.go.ttyfast
--- List of directory names for undo files, separated with commas.
--- See 'backupdir' for details of the format.
--- "." means using the directory of the file. The undo file name for

View File

@@ -455,6 +455,7 @@ local options_list = {
{ 'busy', N_ 'buffer is busy' },
{ 'termpastefilter', N_ 'characters removed when pasting into terminal window' },
{ 'scrollback', N_ 'number of lines kept beyond the visible screen in terminal buffer' },
{ 'ttyfast', N_ 'assume terminal responds quickly, enabling more features' },
},
}

View File

@@ -407,6 +407,12 @@ void set_init_1(bool clean_arg)
// Expand environment variables and things like "~" for the defaults.
set_init_expand_env();
// Allow disabling ttyfast during startup to disable features such as
// automatic background detection over slow connections.
if (os_env_exists("NVIM_NOTTYFAST", false)) {
set_option_value_give_err(kOptTtyfast, BOOLEAN_OPTVAL(false), 0);
}
save_file_ff(curbuf); // Buffer is unchanged
// Detect use of mlterm.

View File

@@ -553,6 +553,7 @@ EXTERN char *p_tsr; ///< 'thesaurus'
EXTERN int p_tgc; ///< 'termguicolors'
EXTERN int p_ttimeout; ///< 'ttimeout'
EXTERN OptInt p_ttm; ///< 'ttimeoutlen'
EXTERN int p_tf; ///< 'ttyfast'
EXTERN char *p_udir; ///< 'undodir'
EXTERN int p_udf; ///< 'undofile'
EXTERN OptInt p_ul; ///< 'undolevels'

View File

@@ -9777,12 +9777,20 @@ local options = {
{
abbreviation = 'tf',
defaults = true,
desc = [=[
Assume that the underlying terminal can respond quickly to queries
required by features such as 'background' detection.
Nvim issues terminal queries before reading the user's |config| file,
so disabling this option there will not work. Set $NVIM_NOTTYFAST
before starting Nvim to disable terminal queries.
]=],
full_name = 'ttyfast',
no_mkrc = true,
scope = { 'global' },
short_desc = N_('Deprecated'),
short_desc = N_('assume terminal responds quickly, enabling more features'),
type = 'boolean',
immutable = true,
varname = 'p_tf',
},
{
abbreviation = 'udir',

View File

@@ -80,7 +80,6 @@ describe('optwin.lua', function()
'pastetoggle',
'langnoremap',
'opendevice',
'ttyfast',
'remap',
'hkmap',
'hkmapp',

View File

@@ -3326,7 +3326,7 @@ describe('TUI', function()
end)
local child_session = n.connect(child_server)
local expected_msg =
'defaults.lua: Did not detect DSR response from terminal. This results in a slower startup time.'
"defaults.lua: Did not detect DSR response from terminal for 'background' detection. This results in a slower startup time. To disable this and other 'ttyfast' features during startup, set the environment variable NVIM_NOTTYFAST"
retry(nil, 4000, function()
eq({ true, { mode = 'n', blocking = false } }, { child_session:request('nvim_get_mode') })
if not is_os('win') then -- ConPTY provides DSR response on Windows?