Skip to content

Commit 2d24427

Browse files
authored
feat: use jobstart for Neovim v0.11+ instead of termopen (#298)
closes #295
1 parent 402a188 commit 2d24427

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

lua/kitty-scrollback/kitty_commands.lua

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,16 @@ M.get_text_term = function(get_text_opts, on_exit_cb)
7474
-- increase the number of columns temporary so that the width is used during the
7575
-- terminal command kitty @ get-text. this avoids hard wrapping lines to the
7676
-- current window size. Note: a larger min_cols appears to impact performance
77-
-- defer is used as a timing workaround because this is expected to be called right before termopen
77+
-- defer is used as a timing workaround because this is expected to be called right before
78+
-- opening the terminal
7879
p.orig_columns = defer_resize_term(300)
7980

80-
-- set the shell used for termopen to sh to avoid imcompatabiliies with other shells (e.g., nushell, fish, etc)
81+
-- set the shell used to sh to avoid imcompatabiliies with other shells (e.g., nushell, fish, etc)
8182
vim.o.shell = 'sh'
82-
local success, error = pcall(vim.fn.termopen, full_cmd, {
83+
84+
local open_term_fn = vim.fn.jobstart
85+
local open_term_options = {
86+
term = true,
8387
stdout_buffered = true,
8488
stderr_buffered = true,
8589
on_stdout = function(_, data)
@@ -112,7 +116,7 @@ M.get_text_term = function(get_text_opts, on_exit_cb)
112116

113117
if error_index > 0 then
114118
ksb_util.display_error(scrollback_cmd, {
115-
entrypoint = 'termopen() :: exit_code = 0 and error_index > 0',
119+
entrypoint = 'open_term_fn() :: exit_code = 0 and error_index > 0',
116120
full_cmd = full_cmd,
117121
code = 1, -- exit code is not returned through pipe but we can assume 1 due to error message
118122
channel_id = id,
@@ -139,23 +143,29 @@ M.get_text_term = function(get_text_opts, on_exit_cb)
139143
:gsub(';k=s', '')
140144
or nil
141145
ksb_util.display_error(full_cmd, {
142-
entrypoint = 'termopen() :: exit_code ~= 0',
146+
entrypoint = 'open_term_fn() :: exit_code ~= 0',
143147
code = exit_code,
144148
channel_id = id,
145149
stdout = out,
146150
stderr = stderr and table.concat(stderr, '\n') or nil,
147151
}, error_header)
148152
end
149153
end,
150-
})
154+
}
155+
if vim.fn.has('nvim-0.11') <= 0 then
156+
open_term_fn = vim.fn.termopen
157+
open_term_options.term = nil
158+
end
159+
160+
local success, error = pcall(open_term_fn, full_cmd, open_term_options)
151161
if not success then
152162
ksb_util.display_error(full_cmd, {
153-
entrypoint = 'termopen() :: pcall(vim.fn.termopen) error returned',
163+
entrypoint = 'open_term_fn() :: pcall(open_term_fn) error returned',
154164
stderr = error or nil,
155165
}, error_header)
156166
end
157167

158-
-- restore the original shell after processing termopen
168+
-- restore the original shell after processing
159169
vim.o.shell = p.orig_options.shell
160170
end
161171

lua/kitty-scrollback/launch.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ M.launch = function()
380380
if no_buf_content then
381381
p.bufid = vim.api.nvim_get_current_buf()
382382
else
383-
-- buffer must be empty for termopen, dashboard plugins may write to the first buffer before kitty-scrollback.nvim loads
383+
-- buffer must be empty for the terminal, dashboard plugins may write to the first buffer before kitty-scrollback.nvim loads
384384
p.bufid = vim.api.nvim_create_buf(true, true)
385385
vim.api.nvim_set_current_buf(p.bufid)
386386
end

0 commit comments

Comments
 (0)