mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 10:49:08 +00:00
feat(image): better error handling + option to disable error notifications
This commit is contained in:
parent
5c0607e31a
commit
1adfd29af3
4 changed files with 93 additions and 17 deletions
|
@ -70,6 +70,32 @@ function Proc:failed()
|
|||
return self.code ~= 0 or self.signal ~= 0
|
||||
end
|
||||
|
||||
---@param opts? snacks.debug.cmd|{}
|
||||
function Proc:debug(opts)
|
||||
---@type snacks.debug.cmd
|
||||
opts = Snacks.config.merge({}, opts or {}, {
|
||||
cmd = self.opts.cmd,
|
||||
args = self.opts.args,
|
||||
cwd = self.opts.cwd,
|
||||
})
|
||||
opts.props = opts.props or {}
|
||||
if not self:running() then
|
||||
opts.props.code = ("`%d`"):format(self.code)
|
||||
opts.props.signal = ("`%d`"):format(self.signal)
|
||||
if self.aborted then
|
||||
opts.props.aborted = "`true`"
|
||||
end
|
||||
end
|
||||
if self:failed() then
|
||||
opts.level = "error"
|
||||
end
|
||||
local out = vim.trim(self:out() .. "\n" .. self:err())
|
||||
if out ~= "" then
|
||||
opts.footer = "# Output\n```\n" .. out .. "\n```"
|
||||
end
|
||||
return Snacks.debug.cmd(opts)
|
||||
end
|
||||
|
||||
function Proc:run()
|
||||
assert(not self.handle, "already running")
|
||||
self.stdout = assert(uv.new_pipe())
|
||||
|
@ -77,7 +103,7 @@ function Proc:run()
|
|||
self.data = { [self.stdout] = {}, [self.stderr] = {} }
|
||||
if self.opts.debug then
|
||||
vim.schedule(function()
|
||||
Snacks.debug.cmd({ cmd = self.opts.cmd, args = self.opts.args, cwd = self.opts.cwd })
|
||||
self:debug()
|
||||
end)
|
||||
end
|
||||
local opts = vim.tbl_deep_extend("force", self.opts, {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue