feat(terminal): don't use deprecated vim.fn.termopen on Neovim >= 0.10

This commit is contained in:
Folke Lemaitre 2025-02-11 12:13:22 +01:00
parent 7da3b6e930
commit 37f6665c48
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -68,6 +68,16 @@ Snacks.config.style("terminal", {
---@type table<string, snacks.win>
local terminals = {}
local function jobstart(cmd, opts)
opts = opts or {}
local fn = vim.fn.jobstart
if vim.fn.has("nvim-0.10") == 0 and opts.term then
opts.term = nil
fn = vim.fn.termopen
end
return fn(cmd, vim.tbl_isempty(opts) and vim.empty_dict() or opts)
end
--- Open a new terminal window.
---@param cmd? string | string[]
---@param opts? snacks.terminal.Opts
@ -142,14 +152,11 @@ function M.open(cmd, opts)
terminal:show()
vim.api.nvim_buf_call(terminal.buf, function()
local term_opts = {
jobstart(cmd or M.parse(opts.shell or vim.o.shell), {
cwd = opts.cwd,
env = opts.env,
}
vim.fn.termopen(
cmd or M.parse(opts.shell or vim.o.shell),
vim.tbl_isempty(term_opts) and vim.empty_dict() or term_opts
)
term = true,
})
end)
vim.cmd("noh")