Skip to content

Commit c09921c

Browse files
committed
shim
1 parent 3d23696 commit c09921c

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

lua/chadtree.lua

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,21 @@ local job_id = nil
3737
local err_exit = false
3838
local has_05 = vim.api.nvim_call_function("has", {"nvim-0.5"}) == 1
3939

40+
local echo = function(msg, error)
41+
if has_05 then
42+
vim.api.nvim_echo({{msg, error and "ErrorMsg" or nil}}, true, {})
43+
elseif error then
44+
vim.api.nvim_err_write(msg)
45+
else
46+
vim.api.nvim_out_write(msg)
47+
end
48+
end
49+
4050
chad.on_exit = function(args)
4151
local code = unpack(args)
4252
if not (code == 0 or code == 143) then
43-
local msg = "CHADTree EXITED - " .. code
4453
err_exit = true
45-
if has_05 then
46-
vim.api.nvim_echo({{msg, "ErrorMsg"}}, true, {})
47-
else
48-
vim.api.nvim_err_writeln(msg)
49-
end
54+
echo("CHADTree EXITED - " .. code, true)
5055
else
5156
err_exit = false
5257
end
@@ -55,24 +60,12 @@ end
5560

5661
chad.on_stdout = function(args)
5762
local msg = unpack(args)
58-
local lines = table.concat(msg, linesep)
59-
60-
if has_05 then
61-
vim.api.nvim_echo({{lines}}, true, {})
62-
else
63-
vim.api.nvim_out_write(lines)
64-
end
63+
echo(table.concat(msg, linesep), false)
6564
end
6665

6766
chad.on_stderr = function(args)
6867
local msg = unpack(args)
69-
local lines = table.concat(msg, linesep)
70-
71-
if has_05 then
72-
vim.api.nvim_echo({{lines, "ErrorMsg"}}, true, {})
73-
else
74-
vim.api.nvim_err_write(lines)
75-
end
68+
echo(table.concat(msg, linesep), true)
7669
end
7770

7871
local go, _py3 = pcall(vim.api.nvim_get_var, "python3_host_prog")

0 commit comments

Comments
 (0)