mirror of
https://github.com/neovim/neovim.git
synced 2025-09-11 05:48:17 +00:00

Old behaviour: termopen('cmd') would run `&shell &shcf "cmd"`, which caused the functional tests to fail on some systems due to the process not "owning" the terminal. Also, it is inconsistent with jobstart(). Modify termopen() so that &shell is not invoked, but maintain the old behaviour with :terminal. Factor the common code for building the argument vector from jobstart() and modify the functional tests to call termopen() instead of :terminal (fixes #2354). Also: * Add a 'name' option for termopen() so that `:terminal {cmd}` produces a buffer named "term//{cwd}/{cmd}" and termopen() users can customize the name. * Update the documentation. * Add functional tests for `:terminal` sinse its behaviour now differs from termopen(). Add "test/functional/fixtures/shell-test.c" and move "test/functional/job/tty-test.c" there, too. Helped-by: Justin M. Keyes <@justinmk>
164 lines
5.6 KiB
Lua
164 lines
5.6 KiB
Lua
local helpers = require('test.functional.helpers')
|
|
local Screen = require('test.functional.ui.screen')
|
|
local thelpers = require('test.functional.terminal.helpers')
|
|
local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim
|
|
local nvim_dir, execute = helpers.nvim_dir, helpers.execute
|
|
|
|
|
|
describe('terminal window highlighting', function()
|
|
local screen
|
|
|
|
before_each(function()
|
|
clear()
|
|
screen = Screen.new(50, 7)
|
|
screen:set_default_attr_ids({
|
|
[1] = {foreground = 45},
|
|
[2] = {background = 46},
|
|
[3] = {foreground = 45, background = 46},
|
|
[4] = {bold = true, italic = true, underline = true}
|
|
})
|
|
screen:set_default_attr_ignore({
|
|
[1] = {bold = true},
|
|
[2] = {foreground = 12},
|
|
[3] = {bold = true, reverse = true},
|
|
[5] = {background = 11},
|
|
[6] = {foreground = 130},
|
|
[7] = {reverse = true},
|
|
[8] = {background = 11}
|
|
})
|
|
screen:attach(false)
|
|
execute('enew | call termopen(["'..nvim_dir..'/tty-test"]) | startinsert')
|
|
screen:expect([[
|
|
tty ready |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- TERMINAL -- |
|
|
]])
|
|
end)
|
|
|
|
function descr(title, attr_num, set_attrs_fn)
|
|
local function sub(s)
|
|
return s:gsub('NUM', attr_num)
|
|
end
|
|
|
|
describe(title, function()
|
|
before_each(function()
|
|
set_attrs_fn()
|
|
thelpers.feed_data('text')
|
|
thelpers.clear_attrs()
|
|
thelpers.feed_data('text')
|
|
end)
|
|
|
|
local function pass_attrs()
|
|
local s = sub([[
|
|
tty ready |
|
|
{NUM:text}text |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- TERMINAL -- |
|
|
]])
|
|
screen:expect(s)
|
|
end
|
|
|
|
it('will pass the corresponding attributes', pass_attrs)
|
|
|
|
it('will pass the corresponding attributes on scrollback', function()
|
|
pass_attrs()
|
|
local lines = {}
|
|
for i = 1, 8 do
|
|
table.insert(lines, 'line'..tostring(i))
|
|
end
|
|
table.insert(lines, '')
|
|
thelpers.feed_data(lines)
|
|
screen:expect([[
|
|
line4 |
|
|
line5 |
|
|
line6 |
|
|
line7 |
|
|
line8 |
|
|
|
|
|
-- TERMINAL -- |
|
|
]])
|
|
feed('<c-\\><c-n>gg')
|
|
local s = sub([[
|
|
^tty ready |
|
|
{NUM:text}textline1 |
|
|
line2 |
|
|
line3 |
|
|
line4 |
|
|
line5 |
|
|
|
|
|
]])
|
|
screen:expect(s)
|
|
end)
|
|
end)
|
|
end
|
|
|
|
descr('foreground', 1, function() thelpers.set_fg(45) end)
|
|
descr('background', 2, function() thelpers.set_bg(46) end)
|
|
descr('foreground and background', 3, function()
|
|
thelpers.set_fg(45)
|
|
thelpers.set_bg(46)
|
|
end)
|
|
descr('bold, italics and underline', 4, function()
|
|
thelpers.set_bold()
|
|
thelpers.set_italic()
|
|
thelpers.set_underline()
|
|
end)
|
|
end)
|
|
|
|
|
|
describe('terminal window highlighting with custom palette', function()
|
|
local screen
|
|
|
|
before_each(function()
|
|
clear()
|
|
screen = Screen.new(50, 7)
|
|
screen:set_default_attr_ids({
|
|
[1] = {foreground = 1193046}
|
|
})
|
|
screen:set_default_attr_ignore({
|
|
[1] = {bold = true},
|
|
[2] = {foreground = 12},
|
|
[3] = {bold = true, reverse = true},
|
|
[5] = {background = 11},
|
|
[6] = {foreground = 130},
|
|
[7] = {reverse = true},
|
|
[8] = {background = 11}
|
|
})
|
|
screen:attach(true)
|
|
nvim('set_var', 'terminal_color_3', '#123456')
|
|
execute('enew | call termopen(["'..nvim_dir..'/tty-test"]) | startinsert')
|
|
screen:expect([[
|
|
tty ready |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- TERMINAL -- |
|
|
]])
|
|
end)
|
|
|
|
it('will use the custom color', function()
|
|
thelpers.set_fg(3)
|
|
thelpers.feed_data('text')
|
|
thelpers.clear_attrs()
|
|
thelpers.feed_data('text')
|
|
screen:expect([[
|
|
tty ready |
|
|
{1:text}text |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- TERMINAL -- |
|
|
]])
|
|
end)
|
|
end)
|