2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2015-03-25 05:14:47 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
2024-09-15 03:28:14 -07:00
|
|
|
local tt = require('test.functional.testterm')
|
2024-04-20 08:44:13 -07:00
|
|
|
|
|
|
|
local clear, eq = n.clear, t.eq
|
|
|
|
local feed, testprg = n.feed, n.testprg
|
|
|
|
local eval = n.eval
|
|
|
|
local command = n.command
|
|
|
|
local poke_eventloop = n.poke_eventloop
|
2024-04-08 02:03:20 -07:00
|
|
|
local retry = t.retry
|
2024-04-20 08:44:13 -07:00
|
|
|
local api = n.api
|
2024-04-08 02:03:20 -07:00
|
|
|
local feed_data = tt.feed_data
|
|
|
|
local pcall_err = t.pcall_err
|
2024-04-20 08:44:13 -07:00
|
|
|
local exec_lua = n.exec_lua
|
|
|
|
local assert_alive = n.assert_alive
|
2024-04-08 02:03:20 -07:00
|
|
|
local skip = t.skip
|
|
|
|
local is_os = t.is_os
|
2015-03-25 05:14:47 -07:00
|
|
|
|
2018-04-28 16:39:21 -07:00
|
|
|
describe(':terminal scrollback', function()
|
2015-03-25 05:14:47 -07:00
|
|
|
local screen
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
2024-09-15 03:28:14 -07:00
|
|
|
screen = tt.setup_screen(nil, nil, 30)
|
2015-03-25 05:14:47 -07:00
|
|
|
end)
|
|
|
|
|
2017-02-21 07:16:48 -07:00
|
|
|
describe('when the limit is exceeded', function()
|
2015-03-25 05:14:47 -07:00
|
|
|
before_each(function()
|
|
|
|
local lines = {}
|
|
|
|
for i = 1, 30 do
|
|
|
|
table.insert(lines, 'line' .. tostring(i))
|
|
|
|
end
|
|
|
|
table.insert(lines, '')
|
|
|
|
feed_data(lines)
|
|
|
|
screen:expect([[
|
2017-02-22 08:10:10 -07:00
|
|
|
line26 |
|
|
|
|
line27 |
|
|
|
|
line28 |
|
|
|
|
line29 |
|
|
|
|
line30 |
|
|
|
|
{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('will delete extra lines at the top', function()
|
|
|
|
feed('<c-\\><c-n>gg')
|
|
|
|
screen:expect([[
|
2017-02-22 08:10:10 -07:00
|
|
|
^line16 |
|
|
|
|
line17 |
|
|
|
|
line18 |
|
|
|
|
line19 |
|
|
|
|
line20 |
|
|
|
|
line21 |
|
|
|
|
|
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2017-08-13 10:54:48 -07:00
|
|
|
describe('with cursor at last row', function()
|
2015-03-25 05:14:47 -07:00
|
|
|
before_each(function()
|
|
|
|
feed_data({ 'line1', 'line2', 'line3', 'line4', '' })
|
|
|
|
screen:expect([[
|
2017-02-22 08:10:10 -07:00
|
|
|
tty ready |
|
|
|
|
line1 |
|
|
|
|
line2 |
|
|
|
|
line3 |
|
|
|
|
line4 |
|
|
|
|
{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('and 1 line is printed', function()
|
|
|
|
before_each(function()
|
|
|
|
feed_data({ 'line5', '' })
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('will hide the top line', function()
|
|
|
|
screen:expect([[
|
2017-02-22 08:10:10 -07:00
|
|
|
line1 |
|
|
|
|
line2 |
|
|
|
|
line3 |
|
|
|
|
line4 |
|
|
|
|
line5 |
|
|
|
|
{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(7, api.nvim_buf_line_count(0))
|
2015-03-25 05:14:47 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
describe('and then 3 more lines are printed', function()
|
|
|
|
before_each(function()
|
|
|
|
feed_data({ 'line6', 'line7', 'line8' })
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('will hide the top 4 lines', function()
|
|
|
|
screen:expect([[
|
2017-02-22 08:10:10 -07:00
|
|
|
line3 |
|
|
|
|
line4 |
|
|
|
|
line5 |
|
|
|
|
line6 |
|
|
|
|
line7 |
|
|
|
|
line8{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
|
|
|
|
feed('<c-\\><c-n>6k')
|
|
|
|
screen:expect([[
|
2017-02-22 08:10:10 -07:00
|
|
|
^line2 |
|
|
|
|
line3 |
|
|
|
|
line4 |
|
|
|
|
line5 |
|
|
|
|
line6 |
|
|
|
|
line7 |
|
|
|
|
|
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
|
|
|
|
feed('gg')
|
|
|
|
screen:expect([[
|
2017-02-22 08:10:10 -07:00
|
|
|
^tty ready |
|
|
|
|
line1 |
|
|
|
|
line2 |
|
|
|
|
line3 |
|
|
|
|
line4 |
|
|
|
|
line5 |
|
|
|
|
|
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
|
|
|
|
feed('G')
|
|
|
|
screen:expect([[
|
2017-02-22 08:10:10 -07:00
|
|
|
line3 |
|
|
|
|
line4 |
|
|
|
|
line5 |
|
|
|
|
line6 |
|
|
|
|
line7 |
|
|
|
|
^line8{2: } |
|
|
|
|
|
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2017-08-13 10:54:48 -07:00
|
|
|
describe('and height decreased by 1', function()
|
2015-03-25 05:14:47 -07:00
|
|
|
local function will_hide_top_line()
|
2019-04-11 04:51:07 -07:00
|
|
|
feed([[<C-\><C-N>]])
|
2017-08-13 10:54:48 -07:00
|
|
|
screen:try_resize(screen._width - 2, screen._height - 1)
|
2017-08-06 05:26:17 -07:00
|
|
|
screen:expect([[
|
2017-08-13 10:54:48 -07:00
|
|
|
line2 |
|
|
|
|
line3 |
|
|
|
|
line4 |
|
|
|
|
rows: 5, cols: 28 |
|
2019-04-11 04:51:07 -07:00
|
|
|
{2:^ } |
|
|
|
|
|
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
end
|
|
|
|
|
|
|
|
it('will hide top line', will_hide_top_line)
|
|
|
|
|
|
|
|
describe('and then decreased by 2', function()
|
|
|
|
before_each(function()
|
|
|
|
will_hide_top_line()
|
2017-08-13 10:54:48 -07:00
|
|
|
screen:try_resize(screen._width - 2, screen._height - 2)
|
2015-03-25 05:14:47 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('will hide the top 3 lines', function()
|
2017-08-06 05:26:17 -07:00
|
|
|
screen:expect([[
|
2017-08-13 10:54:48 -07:00
|
|
|
rows: 5, cols: 28 |
|
|
|
|
rows: 3, cols: 26 |
|
2019-04-11 04:51:07 -07:00
|
|
|
{2:^ } |
|
|
|
|
|
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(8, api.nvim_buf_line_count(0))
|
2019-04-11 04:51:07 -07:00
|
|
|
feed([[3k]])
|
2015-03-25 05:14:47 -07:00
|
|
|
screen:expect([[
|
2017-08-13 10:54:48 -07:00
|
|
|
^line4 |
|
|
|
|
rows: 5, cols: 28 |
|
|
|
|
rows: 3, cols: 26 |
|
|
|
|
|
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('with empty lines after the cursor', function()
|
2017-08-06 15:26:43 -07:00
|
|
|
-- XXX: Can't test this reliably on Windows unless the cursor is _moved_
|
|
|
|
-- by the resize. http://docs.libuv.org/en/v1.x/signal.html
|
|
|
|
-- See also: https://github.com/rprichard/winpty/issues/110
|
2022-11-21 17:13:30 -07:00
|
|
|
if skip(is_os('win')) then
|
|
|
|
return
|
|
|
|
end
|
2017-08-06 05:26:17 -07:00
|
|
|
|
2015-03-25 05:14:47 -07:00
|
|
|
describe('and the height is decreased by 2', function()
|
|
|
|
before_each(function()
|
|
|
|
screen:try_resize(screen._width, screen._height - 2)
|
|
|
|
end)
|
|
|
|
|
|
|
|
local function will_delete_last_two_lines()
|
|
|
|
screen:expect([[
|
2017-02-22 08:10:10 -07:00
|
|
|
tty ready |
|
|
|
|
rows: 4, cols: 30 |
|
|
|
|
{1: } |
|
|
|
|
|
|
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(4, api.nvim_buf_line_count(0))
|
2015-03-25 05:14:47 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
it('will delete the last two empty lines', will_delete_last_two_lines)
|
|
|
|
|
|
|
|
describe('and then decreased by 1', function()
|
|
|
|
before_each(function()
|
|
|
|
will_delete_last_two_lines()
|
|
|
|
screen:try_resize(screen._width, screen._height - 1)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('will delete the last line and hide the first', function()
|
|
|
|
screen:expect([[
|
2017-02-22 08:10:10 -07:00
|
|
|
rows: 4, cols: 30 |
|
|
|
|
rows: 3, cols: 30 |
|
|
|
|
{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(4, api.nvim_buf_line_count(0))
|
2015-03-25 05:14:47 -07:00
|
|
|
feed('<c-\\><c-n>gg')
|
|
|
|
screen:expect([[
|
2017-02-22 08:10:10 -07:00
|
|
|
^tty ready |
|
|
|
|
rows: 4, cols: 30 |
|
|
|
|
rows: 3, cols: 30 |
|
|
|
|
|
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
feed('a')
|
|
|
|
screen:expect([[
|
2017-02-22 08:10:10 -07:00
|
|
|
rows: 4, cols: 30 |
|
|
|
|
rows: 3, cols: 30 |
|
|
|
|
{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('with 4 lines hidden in the scrollback', function()
|
|
|
|
before_each(function()
|
|
|
|
feed_data({ 'line1', 'line2', 'line3', 'line4', '' })
|
|
|
|
screen:expect([[
|
2017-02-22 08:10:10 -07:00
|
|
|
tty ready |
|
|
|
|
line1 |
|
|
|
|
line2 |
|
|
|
|
line3 |
|
|
|
|
line4 |
|
|
|
|
{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
screen:try_resize(screen._width, screen._height - 3)
|
2017-08-06 05:26:17 -07:00
|
|
|
screen:expect([[
|
2017-02-22 08:10:10 -07:00
|
|
|
line4 |
|
|
|
|
rows: 3, cols: 30 |
|
|
|
|
{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(7, api.nvim_buf_line_count(0))
|
2015-03-25 05:14:47 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
describe('and the height is increased by 1', function()
|
2017-08-06 15:26:43 -07:00
|
|
|
-- XXX: Can't test this reliably on Windows unless the cursor is _moved_
|
|
|
|
-- by the resize. http://docs.libuv.org/en/v1.x/signal.html
|
|
|
|
-- See also: https://github.com/rprichard/winpty/issues/110
|
2022-11-21 17:13:30 -07:00
|
|
|
if skip(is_os('win')) then
|
|
|
|
return
|
|
|
|
end
|
2015-03-25 05:14:47 -07:00
|
|
|
local function pop_then_push()
|
|
|
|
screen:try_resize(screen._width, screen._height + 1)
|
2017-08-06 05:26:17 -07:00
|
|
|
screen:expect([[
|
2017-02-22 08:10:10 -07:00
|
|
|
line4 |
|
|
|
|
rows: 3, cols: 30 |
|
|
|
|
rows: 4, cols: 30 |
|
|
|
|
{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
end
|
|
|
|
|
|
|
|
it('will pop 1 line and then push it back', pop_then_push)
|
|
|
|
|
|
|
|
describe('and then by 3', function()
|
|
|
|
before_each(function()
|
|
|
|
pop_then_push()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(8, api.nvim_buf_line_count(0))
|
2015-03-25 05:14:47 -07:00
|
|
|
screen:try_resize(screen._width, screen._height + 3)
|
|
|
|
end)
|
|
|
|
|
|
|
|
local function pop3_then_push1()
|
2017-08-06 05:26:17 -07:00
|
|
|
screen:expect([[
|
2017-02-22 08:10:10 -07:00
|
|
|
line2 |
|
|
|
|
line3 |
|
|
|
|
line4 |
|
|
|
|
rows: 3, cols: 30 |
|
|
|
|
rows: 4, cols: 30 |
|
|
|
|
rows: 7, cols: 30 |
|
|
|
|
{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(9, api.nvim_buf_line_count(0))
|
2015-03-25 05:14:47 -07:00
|
|
|
feed('<c-\\><c-n>gg')
|
|
|
|
screen:expect([[
|
2017-02-22 08:10:10 -07:00
|
|
|
^tty ready |
|
|
|
|
line1 |
|
|
|
|
line2 |
|
|
|
|
line3 |
|
|
|
|
line4 |
|
|
|
|
rows: 3, cols: 30 |
|
|
|
|
rows: 4, cols: 30 |
|
|
|
|
|
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
end
|
|
|
|
|
|
|
|
it('will pop 3 lines and then push one back', pop3_then_push1)
|
|
|
|
|
|
|
|
describe('and then by 4', function()
|
|
|
|
before_each(function()
|
|
|
|
pop3_then_push1()
|
|
|
|
feed('Gi')
|
|
|
|
screen:try_resize(screen._width, screen._height + 4)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('will show all lines and leave a blank one at the end', function()
|
|
|
|
screen:expect([[
|
2017-02-22 08:10:10 -07:00
|
|
|
tty ready |
|
|
|
|
line1 |
|
|
|
|
line2 |
|
|
|
|
line3 |
|
|
|
|
line4 |
|
|
|
|
rows: 3, cols: 30 |
|
|
|
|
rows: 4, cols: 30 |
|
|
|
|
rows: 7, cols: 30 |
|
|
|
|
rows: 11, cols: 30 |
|
|
|
|
{1: } |
|
|
|
|
|
|
|
|
|
{3:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
|
|
|
-- since there's an empty line after the cursor, the buffer line
|
|
|
|
-- count equals the terminal screen height
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(11, api.nvim_buf_line_count(0))
|
2015-03-25 05:14:47 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2018-04-28 16:39:21 -07:00
|
|
|
describe(':terminal prints more lines than the screen height and exits', function()
|
2015-03-25 05:14:47 -07:00
|
|
|
it('will push extra lines to scrollback', function()
|
|
|
|
clear()
|
2017-02-22 08:10:10 -07:00
|
|
|
local screen = Screen.new(30, 7)
|
2016-06-08 02:26:06 -07:00
|
|
|
screen:attach({ rgb = false })
|
2023-07-22 21:46:56 -07:00
|
|
|
command(("call termopen(['%s', '10']) | startinsert"):format(testprg('tty-test')))
|
2015-03-25 05:14:47 -07:00
|
|
|
screen:expect([[
|
2017-02-22 08:10:10 -07:00
|
|
|
line6 |
|
|
|
|
line7 |
|
|
|
|
line8 |
|
|
|
|
line9 |
|
|
|
|
|
|
2024-03-22 03:02:52 -07:00
|
|
|
[Process exited 0]{2: } |
|
|
|
|
{5:-- TERMINAL --} |
|
2015-03-25 05:14:47 -07:00
|
|
|
]])
|
2015-08-21 19:53:48 -07:00
|
|
|
feed('<cr>')
|
|
|
|
-- closes the buffer correctly after pressing a key
|
2024-03-22 03:02:52 -07:00
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
2017-02-22 08:10:10 -07:00
|
|
|
^ |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*5
|
2017-02-22 08:10:10 -07:00
|
|
|
|
|
2024-03-22 03:02:52 -07:00
|
|
|
]],
|
|
|
|
attr_ids = { [1] = { foreground = 12 } },
|
|
|
|
}
|
2015-03-25 05:14:47 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2017-02-21 07:16:48 -07:00
|
|
|
describe("'scrollback' option", function()
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
end)
|
|
|
|
|
2017-03-24 12:21:05 -07:00
|
|
|
local function set_fake_shell()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('shell', string.format('"%s" INTERACT', testprg('shell-test')), {})
|
2017-03-24 12:21:05 -07:00
|
|
|
end
|
|
|
|
|
2017-03-11 06:46:35 -07:00
|
|
|
local function expect_lines(expected, epsilon)
|
|
|
|
local ep = epsilon and epsilon or 0
|
2017-02-21 07:16:48 -07:00
|
|
|
local actual = eval("line('$')")
|
2017-03-11 06:46:35 -07:00
|
|
|
if expected > actual + ep and expected < actual - ep then
|
|
|
|
error('expected (+/- ' .. ep .. '): ' .. expected .. ', actual: ' .. tostring(actual))
|
2017-02-21 07:16:48 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it('set to 0 behaves as 1', function()
|
2017-03-28 02:07:58 -07:00
|
|
|
local screen
|
2022-11-21 17:13:30 -07:00
|
|
|
if is_os('win') then
|
2024-09-15 03:28:14 -07:00
|
|
|
screen = tt.setup_screen(nil, { 'cmd.exe' }, 30)
|
2017-03-28 02:07:58 -07:00
|
|
|
else
|
2024-09-15 03:28:14 -07:00
|
|
|
screen = tt.setup_screen(nil, { 'sh' }, 30)
|
2017-03-28 02:07:58 -07:00
|
|
|
end
|
2017-02-21 07:16:48 -07:00
|
|
|
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('scrollback', 0, {})
|
2022-11-21 17:13:30 -07:00
|
|
|
feed_data(('%s REP 31 line%s'):format(testprg('shell-test'), is_os('win') and '\r' or '\n'))
|
2019-09-04 11:01:38 -07:00
|
|
|
screen:expect { any = '30: line ' }
|
2017-02-21 07:16:48 -07:00
|
|
|
retry(nil, nil, function()
|
|
|
|
expect_lines(7)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('deletes lines (only) if necessary', function()
|
2017-03-28 02:07:58 -07:00
|
|
|
local screen
|
2022-11-21 17:13:30 -07:00
|
|
|
if is_os('win') then
|
2018-10-20 21:56:28 -07:00
|
|
|
command([[let $PROMPT='$$']])
|
2024-09-15 03:28:14 -07:00
|
|
|
screen = tt.setup_screen(nil, { 'cmd.exe' }, 30)
|
2017-03-28 02:07:58 -07:00
|
|
|
else
|
2020-12-01 00:10:09 -07:00
|
|
|
command('let $PS1 = "$"')
|
2024-09-15 03:28:14 -07:00
|
|
|
screen = tt.setup_screen(nil, { 'sh' }, 30)
|
2017-03-28 02:07:58 -07:00
|
|
|
end
|
2017-02-21 07:16:48 -07:00
|
|
|
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('scrollback', 200, {})
|
2017-02-21 07:16:48 -07:00
|
|
|
|
|
|
|
-- Wait for prompt.
|
2017-06-26 05:49:15 -07:00
|
|
|
screen:expect { any = '%$' }
|
2017-02-21 07:16:48 -07:00
|
|
|
|
2022-11-21 17:13:30 -07:00
|
|
|
feed_data(('%s REP 31 line%s'):format(testprg('shell-test'), is_os('win') and '\r' or '\n'))
|
2019-09-04 11:01:38 -07:00
|
|
|
screen:expect { any = '30: line ' }
|
2017-02-21 07:16:48 -07:00
|
|
|
|
2017-03-11 06:46:35 -07:00
|
|
|
retry(nil, nil, function()
|
|
|
|
expect_lines(33, 2)
|
|
|
|
end)
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('scrollback', 10, {})
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2017-02-21 07:16:48 -07:00
|
|
|
retry(nil, nil, function()
|
|
|
|
expect_lines(16)
|
|
|
|
end)
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('scrollback', 10000, {})
|
2017-03-11 06:46:35 -07:00
|
|
|
retry(nil, nil, function()
|
|
|
|
expect_lines(16)
|
|
|
|
end)
|
2017-02-21 07:16:48 -07:00
|
|
|
-- Terminal job data is received asynchronously, may happen before the
|
|
|
|
-- 'scrollback' option is synchronized with the internal sb_buffer.
|
|
|
|
command('sleep 100m')
|
|
|
|
|
2022-11-21 17:13:30 -07:00
|
|
|
feed_data(('%s REP 41 line%s'):format(testprg('shell-test'), is_os('win') and '\r' or '\n'))
|
|
|
|
if is_os('win') then
|
2019-09-16 10:17:07 -07:00
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
|
|
|
37: line |
|
|
|
|
38: line |
|
|
|
|
39: line |
|
|
|
|
40: line |
|
|
|
|
|
|
|
|
|
${1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
|
|
|
]],
|
|
|
|
}
|
|
|
|
else
|
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
|
|
|
36: line |
|
|
|
|
37: line |
|
|
|
|
38: line |
|
|
|
|
39: line |
|
|
|
|
40: line |
|
2019-11-09 23:22:24 -07:00
|
|
|
{MATCH:.*}|
|
2019-09-16 10:17:07 -07:00
|
|
|
{3:-- TERMINAL --} |
|
|
|
|
]],
|
|
|
|
}
|
|
|
|
end
|
|
|
|
expect_lines(58)
|
2017-02-21 07:16:48 -07:00
|
|
|
|
|
|
|
-- Verify off-screen state
|
2023-09-24 07:03:54 -07:00
|
|
|
eq((is_os('win') and '36: line' or '35: line'), eval("getline(line('w0') - 1)->trim(' ', 2)"))
|
|
|
|
eq((is_os('win') and '27: line' or '26: line'), eval("getline(line('w0') - 10)->trim(' ', 2)"))
|
2017-02-21 07:16:48 -07:00
|
|
|
end)
|
|
|
|
|
2022-06-08 17:46:57 -07:00
|
|
|
it('deletes extra lines immediately', function()
|
2024-09-15 03:28:14 -07:00
|
|
|
-- Scrollback is 10 on setup_screen
|
|
|
|
local screen = tt.setup_screen(nil, nil, 30)
|
2022-06-08 17:46:57 -07:00
|
|
|
local lines = {}
|
|
|
|
for i = 1, 30 do
|
|
|
|
table.insert(lines, 'line' .. tostring(i))
|
|
|
|
end
|
|
|
|
table.insert(lines, '')
|
|
|
|
feed_data(lines)
|
|
|
|
screen:expect([[
|
|
|
|
line26 |
|
|
|
|
line27 |
|
|
|
|
line28 |
|
|
|
|
line29 |
|
|
|
|
line30 |
|
|
|
|
{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
|
|
|
]])
|
|
|
|
local term_height = 6 -- Actual terminal screen height, not the scrollback
|
|
|
|
-- Initial
|
2024-01-12 10:59:57 -07:00
|
|
|
local scrollback = api.nvim_get_option_value('scrollback', {})
|
2022-06-08 17:46:57 -07:00
|
|
|
eq(scrollback + term_height, eval('line("$")'))
|
|
|
|
-- Reduction
|
|
|
|
scrollback = scrollback - 2
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('scrollback', scrollback, {})
|
2022-06-08 17:46:57 -07:00
|
|
|
eq(scrollback + term_height, eval('line("$")'))
|
|
|
|
end)
|
|
|
|
|
2018-04-28 16:39:21 -07:00
|
|
|
it('defaults to 10000 in :terminal buffers', function()
|
2017-03-24 12:21:05 -07:00
|
|
|
set_fake_shell()
|
|
|
|
command('terminal')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(10000, api.nvim_get_option_value('scrollback', {}))
|
2017-02-21 07:16:48 -07:00
|
|
|
end)
|
|
|
|
|
2017-03-24 12:21:05 -07:00
|
|
|
it('error if set to invalid value', function()
|
2019-09-06 17:17:37 -07:00
|
|
|
eq('Vim(set):E474: Invalid argument: scrollback=-2', pcall_err(command, 'set scrollback=-2'))
|
|
|
|
eq(
|
|
|
|
'Vim(set):E474: Invalid argument: scrollback=100001',
|
|
|
|
pcall_err(command, 'set scrollback=100001')
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2017-02-21 07:16:48 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('defaults to -1 on normal buffers', function()
|
2017-03-24 12:21:05 -07:00
|
|
|
command('new')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(-1, api.nvim_get_option_value('scrollback', {}))
|
2017-02-21 07:16:48 -07:00
|
|
|
end)
|
|
|
|
|
2019-02-17 00:07:30 -07:00
|
|
|
it(':setlocal in a :terminal buffer', function()
|
|
|
|
set_fake_shell()
|
|
|
|
|
|
|
|
-- _Global_ scrollback=-1 defaults :terminal to 10_000.
|
|
|
|
command('setglobal scrollback=-1')
|
2023-08-13 15:47:09 -07:00
|
|
|
command('terminal')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(10000, api.nvim_get_option_value('scrollback', {}))
|
2019-02-17 00:07:30 -07:00
|
|
|
|
|
|
|
-- _Local_ scrollback=-1 in :terminal forces the _maximum_.
|
|
|
|
command('setlocal scrollback=-1')
|
|
|
|
retry(nil, nil, function() -- Fixup happens on refresh, not immediately.
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(100000, api.nvim_get_option_value('scrollback', {}))
|
2019-02-17 00:07:30 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
-- _Local_ scrollback=-1 during TermOpen forces the maximum. #9605
|
|
|
|
command('setglobal scrollback=-1')
|
|
|
|
command('autocmd TermOpen * setlocal scrollback=-1')
|
|
|
|
command('terminal')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(100000, api.nvim_get_option_value('scrollback', {}))
|
2019-02-17 00:07:30 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it(':setlocal in a normal buffer', function()
|
|
|
|
command('new')
|
|
|
|
-- :setlocal to -1.
|
|
|
|
command('setlocal scrollback=-1')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(-1, api.nvim_get_option_value('scrollback', {}))
|
2019-02-17 00:07:30 -07:00
|
|
|
-- :setlocal to anything except -1. Currently, this just has no effect.
|
|
|
|
command('setlocal scrollback=42')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(42, api.nvim_get_option_value('scrollback', {}))
|
2019-02-17 00:07:30 -07:00
|
|
|
end)
|
|
|
|
|
2017-03-24 12:21:05 -07:00
|
|
|
it(':set updates local value and global default', function()
|
|
|
|
set_fake_shell()
|
2019-02-03 18:53:23 -07:00
|
|
|
command('set scrollback=42') -- set global value
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(42, api.nvim_get_option_value('scrollback', {}))
|
2017-03-24 12:21:05 -07:00
|
|
|
command('terminal')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(42, api.nvim_get_option_value('scrollback', {})) -- inherits global default
|
2017-03-24 12:21:05 -07:00
|
|
|
command('setlocal scrollback=99')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(99, api.nvim_get_option_value('scrollback', {}))
|
2017-03-24 12:21:05 -07:00
|
|
|
command('set scrollback<') -- reset to global default
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(42, api.nvim_get_option_value('scrollback', {}))
|
2017-03-24 12:21:05 -07:00
|
|
|
command('setglobal scrollback=734') -- new global default
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(42, api.nvim_get_option_value('scrollback', {})) -- local value did not change
|
2017-03-24 12:21:05 -07:00
|
|
|
command('terminal')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(734, api.nvim_get_option_value('scrollback', {}))
|
2017-02-21 07:16:48 -07:00
|
|
|
end)
|
|
|
|
end)
|
2021-12-15 08:18:06 -07:00
|
|
|
|
|
|
|
describe('pending scrollback line handling', function()
|
|
|
|
local screen
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
screen = Screen.new(30, 7)
|
|
|
|
screen:attach()
|
|
|
|
screen:set_default_attr_ids {
|
|
|
|
[1] = { foreground = Screen.colors.Brown },
|
|
|
|
[2] = { reverse = true },
|
|
|
|
[3] = { bold = true },
|
|
|
|
}
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("does not crash after setting 'number' #14891", function()
|
|
|
|
exec_lua [[
|
2023-04-05 09:19:53 -07:00
|
|
|
local api = vim.api
|
|
|
|
local buf = api.nvim_create_buf(true, true)
|
|
|
|
local chan = api.nvim_open_term(buf, {})
|
2022-12-19 09:37:45 -07:00
|
|
|
vim.wo.number = true
|
2023-04-05 09:19:53 -07:00
|
|
|
api.nvim_chan_send(chan, ("a\n"):rep(11) .. "a")
|
|
|
|
api.nvim_win_set_buf(0, buf)
|
2021-12-15 08:18:06 -07:00
|
|
|
]]
|
|
|
|
screen:expect [[
|
|
|
|
{1: 1 }^a |
|
2023-12-14 01:08:00 -07:00
|
|
|
{1: 2 }a |
|
|
|
|
{1: 3 }a |
|
|
|
|
{1: 4 }a |
|
|
|
|
{1: 5 }a |
|
|
|
|
{1: 6 }a |
|
2021-12-15 08:18:06 -07:00
|
|
|
|
|
|
|
|
]]
|
|
|
|
feed('G')
|
|
|
|
screen:expect [[
|
2023-12-14 01:08:00 -07:00
|
|
|
{1: 7 }a |
|
|
|
|
{1: 8 }a |
|
|
|
|
{1: 9 }a |
|
|
|
|
{1: 10 }a |
|
|
|
|
{1: 11 }a |
|
|
|
|
{1: 12 }^a |
|
2021-12-15 08:18:06 -07:00
|
|
|
|
|
|
|
|
]]
|
|
|
|
assert_alive()
|
|
|
|
end)
|
|
|
|
|
2023-11-29 19:55:21 -07:00
|
|
|
it('does not crash after nvim_buf_call #14891', function()
|
|
|
|
exec_lua(
|
|
|
|
[[
|
2023-04-05 09:19:53 -07:00
|
|
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
2023-11-29 19:55:21 -07:00
|
|
|
local args = ...
|
2023-04-05 09:19:53 -07:00
|
|
|
vim.api.nvim_buf_call(bufnr, function()
|
2023-11-29 19:55:21 -07:00
|
|
|
vim.fn.termopen(args)
|
2021-12-15 08:18:06 -07:00
|
|
|
end)
|
2023-04-05 09:19:53 -07:00
|
|
|
vim.api.nvim_win_set_buf(0, bufnr)
|
2023-11-29 19:55:21 -07:00
|
|
|
vim.cmd('startinsert')
|
|
|
|
]],
|
|
|
|
is_os('win') and { 'cmd.exe', '/c', 'for /L %I in (1,1,12) do @echo hi' }
|
|
|
|
or { 'printf', ('hi\n'):rep(12) }
|
|
|
|
)
|
2021-12-15 08:18:06 -07:00
|
|
|
screen:expect [[
|
2023-12-09 05:42:00 -07:00
|
|
|
hi |*4
|
2021-12-15 08:18:06 -07:00
|
|
|
|
|
|
|
|
[Process exited 0]{2: } |
|
|
|
|
{3:-- TERMINAL --} |
|
|
|
|
]]
|
|
|
|
assert_alive()
|
|
|
|
end)
|
|
|
|
end)
|