mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
test: Extract code to spawn nvim into the "spawn" helper function
This is can be used for spawning nvim outside a test context. Also refactor screen.lua to use this function when loading the color map(It is better because the GDB/VALGRIND environment variables are ignored)
This commit is contained in:
parent
5874bc28ea
commit
47e90ea1c5
@ -162,15 +162,20 @@ local function rawfeed(...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function spawn(argv)
|
||||||
|
local loop = Loop.new()
|
||||||
|
local msgpack_stream = MsgpackStream.new(loop)
|
||||||
|
local async_session = AsyncSession.new(msgpack_stream)
|
||||||
|
local session = Session.new(async_session)
|
||||||
|
loop:spawn(argv)
|
||||||
|
return session
|
||||||
|
end
|
||||||
|
|
||||||
local function clear()
|
local function clear()
|
||||||
if session then
|
if session then
|
||||||
session:exit(0)
|
session:exit(0)
|
||||||
end
|
end
|
||||||
local loop = Loop.new()
|
session = spawn(nvim_argv)
|
||||||
local msgpack_stream = MsgpackStream.new(loop)
|
|
||||||
local async_session = AsyncSession.new(msgpack_stream)
|
|
||||||
session = Session.new(async_session)
|
|
||||||
loop:spawn(nvim_argv)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function insert(...)
|
local function insert(...)
|
||||||
@ -275,6 +280,7 @@ clear()
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
clear = clear,
|
clear = clear,
|
||||||
|
spawn = spawn,
|
||||||
dedent = dedent,
|
dedent = dedent,
|
||||||
source = source,
|
source = source,
|
||||||
rawfeed = rawfeed,
|
rawfeed = rawfeed,
|
||||||
@ -292,6 +298,7 @@ return {
|
|||||||
expect = expect,
|
expect = expect,
|
||||||
ok = ok,
|
ok = ok,
|
||||||
nvim = nvim,
|
nvim = nvim,
|
||||||
|
nvim_prog = nvim_prog,
|
||||||
nvim_dir = nvim_dir,
|
nvim_dir = nvim_dir,
|
||||||
buffer = buffer,
|
buffer = buffer,
|
||||||
window = window,
|
window = window,
|
||||||
|
@ -123,16 +123,26 @@ if os.getenv('CI_TARGET') then
|
|||||||
default_screen_timeout = default_screen_timeout * 3
|
default_screen_timeout = default_screen_timeout * 3
|
||||||
end
|
end
|
||||||
|
|
||||||
local colors = request('vim_get_color_map')
|
do
|
||||||
local colornames = {}
|
local spawn, nvim_prog = helpers.spawn, helpers.nvim_prog
|
||||||
for name, rgb in pairs(colors) do
|
local session = spawn({nvim_prog, '-u', 'NONE', '-N', '--embed'})
|
||||||
|
local status, rv = session:request('vim_get_color_map')
|
||||||
|
if not status then
|
||||||
|
print('failed to get color map')
|
||||||
|
os.exit(1)
|
||||||
|
end
|
||||||
|
local colors = rv
|
||||||
|
local colornames = {}
|
||||||
|
for name, rgb in pairs(colors) do
|
||||||
-- we disregard the case that colornames might not be unique, as
|
-- we disregard the case that colornames might not be unique, as
|
||||||
-- this is just a helper to get any canonical name of a color
|
-- this is just a helper to get any canonical name of a color
|
||||||
colornames[rgb] = name
|
colornames[rgb] = name
|
||||||
|
end
|
||||||
|
session:exit(0)
|
||||||
|
Screen.colors = colors
|
||||||
|
Screen.colornames = colornames
|
||||||
end
|
end
|
||||||
|
|
||||||
Screen.colors = colors
|
|
||||||
|
|
||||||
function Screen.debug(command)
|
function Screen.debug(command)
|
||||||
if not command then
|
if not command then
|
||||||
command = 'pynvim -n -c '
|
command = 'pynvim -n -c '
|
||||||
@ -497,8 +507,8 @@ function pprint_attrs(attrs)
|
|||||||
for f, v in pairs(attrs) do
|
for f, v in pairs(attrs) do
|
||||||
local desc = tostring(v)
|
local desc = tostring(v)
|
||||||
if f == "foreground" or f == "background" then
|
if f == "foreground" or f == "background" then
|
||||||
if colornames[v] ~= nil then
|
if Screen.colornames[v] ~= nil then
|
||||||
desc = "Screen.colors."..colornames[v]
|
desc = "Screen.colors."..Screen.colornames[v]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.insert(items, f.." = "..desc)
|
table.insert(items, f.." = "..desc)
|
||||||
|
Loading…
Reference in New Issue
Block a user