aboutsummaryrefslogtreecommitdiff
path: root/test/functional/terminal/tui_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/terminal/tui_spec.lua')
-rw-r--r--test/functional/terminal/tui_spec.lua161
1 files changed, 146 insertions, 15 deletions
diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua
index d5f6a21d1d..2f9abfd3f6 100644
--- a/test/functional/terminal/tui_spec.lua
+++ b/test/functional/terminal/tui_spec.lua
@@ -4,13 +4,20 @@ local global_helpers = require('test.helpers')
local uname = global_helpers.uname
local helpers = require('test.functional.helpers')(after_each)
local thelpers = require('test.functional.terminal.helpers')
-local feed_data = thelpers.feed_data
+local Screen = require('test.functional.ui.screen')
+local eq = helpers.eq
local feed_command = helpers.feed_command
+local feed_data = thelpers.feed_data
local clear = helpers.clear
+local command = helpers.command
+local eval = helpers.eval
local nvim_dir = helpers.nvim_dir
local retry = helpers.retry
local nvim_prog = helpers.nvim_prog
local nvim_set = helpers.nvim_set
+local ok = helpers.ok
+local read_file = helpers.read_file
+local wait = helpers.wait
if helpers.pending_win32(pending) then return end
@@ -21,9 +28,6 @@ describe('tui', function()
clear()
screen = thelpers.screen_setup(0, '["'..nvim_prog
..'", "-u", "NONE", "-i", "NONE", "--cmd", "set noswapfile noshowcmd noruler undodir=. directory=. viewdir=. backupdir=."]')
- -- right now pasting can be really slow in the TUI, especially in ASAN.
- -- this will be fixed later but for now we require a high timeout.
- screen.timeout = 60000
screen:expect([[
{1: } |
{4:~ }|
@@ -39,6 +43,28 @@ describe('tui', function()
screen:detach()
end)
+ it('rapid resize #7572 #7628', function()
+ -- Need buffer rows to provoke the behavior.
+ feed_data(":edit test/functional/fixtures/bigfile.txt:")
+ command('call jobresize(b:terminal_job_id, 58, 9)')
+ command('call jobresize(b:terminal_job_id, 62, 13)')
+ command('call jobresize(b:terminal_job_id, 100, 42)')
+ command('call jobresize(b:terminal_job_id, 37, 1000)')
+ -- Resize to <5 columns.
+ screen:try_resize(4, 44)
+ command('call jobresize(b:terminal_job_id, 4, 1000)')
+ -- Resize to 1 row, then to 1 column, then increase rows to 4.
+ screen:try_resize(44, 1)
+ command('call jobresize(b:terminal_job_id, 44, 1)')
+ screen:try_resize(1, 1)
+ command('call jobresize(b:terminal_job_id, 1, 1)')
+ screen:try_resize(1, 4)
+ command('call jobresize(b:terminal_job_id, 1, 4)')
+ screen:try_resize(57, 17)
+ command('call jobresize(b:terminal_job_id, 57, 17)')
+ eq(2, eval("1+1")) -- Still alive?
+ end)
+
it('accepts basic utf-8 input', function()
feed_data('iabc\ntest1\ntest2')
screen:expect([[
@@ -89,16 +115,12 @@ describe('tui', function()
]])
end)
- it('does not mangle unmapped ALT-key chord', function()
- -- Vim represents ALT/META by setting the "high bit" of the modified key;
- -- we do _not_. #3982
- --
- -- Example: for input ALT+j:
- -- * Vim (Nvim prior to #3982) sets high-bit, inserts "ê".
- -- * Nvim (after #3982) inserts "j".
- feed_data('i\027j')
+ it('interprets ESC+key as ALT chord', function()
+ -- Vim represents ALT/META by setting the "high bit" of the modified key:
+ -- ALT+j inserts "ê". Nvim does not (#3982).
+ feed_data('i\022\027j')
screen:expect([[
- j{1: } |
+ <M-j>{1: } |
{4:~ }|
{4:~ }|
{4:~ }|
@@ -125,6 +147,9 @@ describe('tui', function()
end)
it('automatically sends <Paste> for bracketed paste sequences', function()
+ -- Pasting can be really slow in the TUI, specially in ASAN.
+ -- This will be fixed later but for now we require a high timeout.
+ screen.timeout = 60000
feed_data('i\027[200~')
screen:expect([[
{1: } |
@@ -158,6 +183,8 @@ describe('tui', function()
end)
it('can handle arbitrarily long bursts of input', function()
+ -- Need extra time for this test, specially in ASAN.
+ screen.timeout = 60000
feed_command('set ruler')
local t = {}
for i = 1, 3000 do
@@ -174,6 +201,58 @@ describe('tui', function()
{3:-- TERMINAL --} |
]])
end)
+
+ it('allows termguicolors to be set at runtime', function()
+ screen:set_option('rgb', true)
+ screen:set_default_attr_ids({
+ [1] = {reverse = true},
+ [2] = {foreground = 13, special = Screen.colors.Grey0},
+ [3] = {special = Screen.colors.Grey0, bold = true, reverse = true},
+ [4] = {bold = true},
+ [5] = {special = Screen.colors.Grey0, reverse = true, foreground = 4},
+ [6] = {foreground = 4, special = Screen.colors.Grey0},
+ [7] = {special = Screen.colors.Grey0, reverse = true, foreground = Screen.colors.SeaGreen4},
+ [8] = {foreground = Screen.colors.SeaGreen4, special = Screen.colors.Grey0},
+ [9] = {special = Screen.colors.Grey0, bold = true, foreground = Screen.colors.Blue1},
+ })
+
+ feed_data(':hi SpecialKey ctermfg=3 guifg=SeaGreen\n')
+ feed_data('i')
+ feed_data('\022\007') -- ctrl+g
+ feed_data('\028\014') -- crtl+\ ctrl+N
+ feed_data(':set termguicolors?\n')
+ screen:expect([[
+ {5:^}{6:G} |
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {3:[No Name] [+] }|
+ notermguicolors |
+ {4:-- TERMINAL --} |
+ ]])
+
+ feed_data(':set termguicolors\n')
+ screen:expect([[
+ {7:^}{8:G} |
+ {9:~ }|
+ {9:~ }|
+ {9:~ }|
+ {3:[No Name] [+] }|
+ :set termguicolors |
+ {4:-- TERMINAL --} |
+ ]])
+
+ feed_data(':set notermguicolors\n')
+ screen:expect([[
+ {5:^}{6:G} |
+ {2:~ }|
+ {2:~ }|
+ {2:~ }|
+ {3:[No Name] [+] }|
+ :set notermguicolors |
+ {4:-- TERMINAL --} |
+ ]])
+ end)
end)
describe('tui with non-tty file descriptors', function()
@@ -390,7 +469,7 @@ describe("tui 't_Co' (terminal colors)", function()
nvim_set))
feed_data(":echo &t_Co\n")
- helpers.wait()
+ wait()
local tline
if maxcolors == 8 or maxcolors == 16 then
tline = "~ "
@@ -639,6 +718,7 @@ end)
describe("tui 'term' option", function()
local screen
local is_bsd = not not string.find(string.lower(uname()), 'bsd')
+ local is_macos = not not string.find(string.lower(uname()), 'darwin')
local function assert_term(term_envvar, term_expected)
clear()
@@ -664,11 +744,62 @@ describe("tui 'term' option", function()
end)
it('gets system-provided term if $TERM is valid', function()
- if is_bsd then -- BSD lacks terminfo, we always use builtin there.
+ if is_bsd then -- BSD lacks terminfo, builtin is always used.
assert_term("xterm", "builtin_xterm")
+ elseif is_macos then
+ local status, _ = pcall(assert_term, "xterm", "xterm")
+ if not status then
+ pending("macOS: unibilium could not find terminfo", function() end)
+ end
else
assert_term("xterm", "xterm")
end
end)
end)
+
+-- These tests require `thelpers` because --headless/--embed
+-- does not initialize the TUI.
+describe("tui", function()
+ local screen
+ local logfile = 'Xtest_tui_verbose_log'
+ after_each(function()
+ os.remove(logfile)
+ end)
+
+ -- Runs (child) `nvim` in a TTY (:terminal), to start the builtin TUI.
+ local function nvim_tui(extra_args)
+ clear()
+ -- This is ugly because :term/termopen() forces TERM=xterm-256color.
+ -- TODO: Revisit this after jobstart/termopen accept `env` dict.
+ local cmd = string.format(
+ [=[['sh', '-c', 'LANG=C %s -u NONE -i NONE %s --cmd "%s"']]=],
+ nvim_prog,
+ extra_args or "",
+ nvim_set)
+ screen = thelpers.screen_setup(0, cmd)
+ end
+
+ it('-V3log logs terminfo values', function()
+ nvim_tui('-V3'..logfile)
+
+ -- Wait for TUI to start.
+ feed_data('Gitext')
+ screen:expect([[
+ text{1: } |
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {4:~ }|
+ {3:-- INSERT --} |
+ {3:-- TERMINAL --} |
+ ]])
+
+ retry(nil, 3000, function() -- Wait for log file to be flushed.
+ local log = read_file('Xtest_tui_verbose_log') or ''
+ eq('--- Terminal info --- {{{\n', string.match(log, '--- Terminal.-\n'))
+ ok(#log > 50)
+ end)
+ end)
+
+end)