mirror of
https://github.com/neovim/neovim.git
synced 2026-04-29 10:44:08 +00:00
feat(terminal): surface exit code via virttext + nvim_get_chan_info #37987
Problem: When a terminal process exits, "[Process Exited]" text is added to the buffer contents. Solution: - Return `exitcode` field from `nvim_get_chan_info`. - Show it in the default 'statusline'. - Show exitcode as virtual text in the terminal buffer.
This commit is contained in:
@@ -81,4 +81,22 @@ function M.source_is_lua(bufnr, line1, line2)
|
||||
return lang_tree:lang() == 'lua'
|
||||
end
|
||||
|
||||
--- Returns the exit code string for the current buffer, given:
|
||||
--- - Channel is attached to the current buffer
|
||||
--- - Current buffer is a terminal buffer
|
||||
---
|
||||
--- @return string
|
||||
function M.term_exitcode()
|
||||
local chan_id = vim.bo.channel
|
||||
if chan_id == 0 or vim.bo.buftype ~= 'terminal' then
|
||||
return ''
|
||||
end
|
||||
|
||||
local info = vim.api.nvim_get_chan_info(chan_id)
|
||||
if info.exitcode and info.exitcode >= 0 then
|
||||
return string.format('[Exit: %d]', info.exitcode)
|
||||
end
|
||||
return ''
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
1
runtime/lua/vim/_meta/api.lua
generated
1
runtime/lua/vim/_meta/api.lua
generated
@@ -1309,6 +1309,7 @@ function vim.api.nvim_get_autocmds(opts) end
|
||||
--- - "buffer" (optional) Buffer connected to |terminal| instance.
|
||||
--- - "client" (optional) Info about the peer (client on the other end of the channel), as set
|
||||
--- by |nvim_set_client_info()|.
|
||||
--- - "exitcode" (optional) Exit code of the |terminal| process.
|
||||
---
|
||||
function vim.api.nvim_get_chan_info(chan) end
|
||||
|
||||
|
||||
2
runtime/lua/vim/_meta/options.lua
generated
2
runtime/lua/vim/_meta/options.lua
generated
@@ -6964,7 +6964,7 @@ vim.wo.stc = vim.wo.statuscolumn
|
||||
---
|
||||
---
|
||||
--- @type string
|
||||
vim.o.statusline = "%<%f %h%w%m%r %=%{% &showcmdloc == 'statusline' ? '%-10.S ' : '' %}%{% exists('b:keymap_name') ? '<'..b:keymap_name..'> ' : '' %}%{% &busy > 0 ? '◐ ' : '' %}%{% luaeval('(package.loaded[''vim.diagnostic''] and #vim.diagnostic.count() ~= 0 and vim.diagnostic.status() .. '' '') or '''' ') %}%{% &ruler ? ( &rulerformat == '' ? '%-14.(%l,%c%V%) %P' : &rulerformat ) : '' %}"
|
||||
vim.o.statusline = "%<%f %h%w%m%r %{% v:lua.require('vim._core.util').term_exitcode() %}%=%{% &showcmdloc == 'statusline' ? '%-10.S ' : '' %}%{% exists('b:keymap_name') ? '<'..b:keymap_name..'> ' : '' %}%{% &busy > 0 ? '◐ ' : '' %}%{% luaeval('(package.loaded[''vim.diagnostic''] and #vim.diagnostic.count() ~= 0 and vim.diagnostic.status() .. '' '') or '''' ') %}%{% &ruler ? ( &rulerformat == '' ? '%-14.(%l,%c%V%) %P' : &rulerformat ) : '' %}"
|
||||
vim.o.stl = vim.o.statusline
|
||||
vim.wo.statusline = vim.o.statusline
|
||||
vim.wo.stl = vim.wo.statusline
|
||||
|
||||
Reference in New Issue
Block a user