terminal: 'scrollback'

Closes #2637
This commit is contained in:
Justin M. Keyes
2017-02-21 15:16:48 +01:00
parent 300eca3d30
commit e7bbd35c81
15 changed files with 282 additions and 208 deletions

View File

@@ -31,45 +31,40 @@ describe(':edit term://*', function()
eq(termopen_runs[1], termopen_runs[1]:match('^term://.//%d+:$'))
end)
it('runs TermOpen early enough to respect terminal_scrollback_buffer_size', function()
it("runs TermOpen early enough to set buffer-local 'scrollback'", function()
local columns, lines = 20, 4
local scr = get_screen(columns, lines)
local rep = 'a'
meths.set_option('shellcmdflag', 'REP ' .. rep)
local rep_size = rep:byte()
local rep_size = rep:byte() -- 'a' => 97
local sb = 10
local gsb = 20
meths.set_var('terminal_scrollback_buffer_size', gsb)
command('autocmd TermOpen * :let b:terminal_scrollback_buffer_size = '
.. tostring(sb))
command('autocmd TermOpen * :setlocal scrollback='..tostring(sb))
command('edit term://foobar')
local bufcontents = {}
local winheight = curwinmeths.get_height()
-- I have no idea why there is + 4 needed. But otherwise it works fine with
-- different scrollbacks.
local shift = -4
local buf_cont_start = rep_size - 1 - sb - winheight - shift
local bufline = function(i) return ('%d: foobar'):format(i) end
local buf_cont_start = rep_size - sb - winheight + 2
local function bufline (i)
return ('%d: foobar'):format(i)
end
for i = buf_cont_start,(rep_size - 1) do
bufcontents[#bufcontents + 1] = bufline(i)
end
bufcontents[#bufcontents + 1] = ''
bufcontents[#bufcontents + 1] = '[Process exited 0]'
-- Do not ask me why displayed screen is one line *before* buffer
-- contents: buffer starts with 87:, screen with 86:.
local exp_screen = '\n'
local did_cursor = false
for i = 0,(winheight - 1) do
local line = bufline(buf_cont_start + i - 1)
for i = 1,(winheight - 1) do
local line = bufcontents[#bufcontents - winheight + i]
exp_screen = (exp_screen
.. (did_cursor and '' or '^')
.. line
.. (' '):rep(columns - #line)
.. '|\n')
did_cursor = true
end
exp_screen = exp_screen .. (' '):rep(columns) .. '|\n'
exp_screen = exp_screen..'^[Process exited 0] |\n'
exp_screen = exp_screen..(' '):rep(columns)..'|\n'
scr:expect(exp_screen)
eq(bufcontents, curbufmeths.get_lines(1, -1, true))
eq(bufcontents, curbufmeths.get_lines(0, -1, true))
end)
end)