diff options
author | Gregory Anders <greg@gpanders.com> | 2021-08-20 11:45:28 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-20 10:45:28 -0700 |
commit | 50b30de2007961718cc11811a30f6b0f35c3c793 (patch) | |
tree | 5bef15d7394ec3ccef0ced4c7e93d68bb11fa015 /src/nvim/terminal.c | |
parent | 599af74514d0d7083c0565005f255e59ecd7e2ad (diff) | |
download | rneovim-50b30de2007961718cc11811a30f6b0f35c3c793.tar.gz rneovim-50b30de2007961718cc11811a30f6b0f35c3c793.tar.bz2 rneovim-50b30de2007961718cc11811a30f6b0f35c3c793.zip |
feat(terminal): TermClose: set exit code in v:event.status #15406
Closes #4713
Diffstat (limited to 'src/nvim/terminal.c')
-rw-r--r-- | src/nvim/terminal.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index c07a956dde..45419b8247 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -260,7 +260,7 @@ Terminal *terminal_open(buf_T *buf, TerminalOptions opts) return rv; } -void terminal_close(Terminal *term, char *msg) +void terminal_close(Terminal *term, int status) { if (term->closed) { return; @@ -278,8 +278,8 @@ void terminal_close(Terminal *term, char *msg) buf_T *buf = handle_get_buffer(term->buf_handle); term->closed = true; - if (!msg || exiting) { - // If no msg was given, this was called by close_buffer(buffer.c). Or if + if (status == -1 || exiting) { + // If status is -1, this was called by close_buffer(buffer.c). Or if // exiting, we must inform the buffer the terminal no longer exists so that // close_buffer() doesn't call this again. term->buf_handle = 0; @@ -291,11 +291,16 @@ void terminal_close(Terminal *term, char *msg) term->opts.close_cb(term->opts.data); } } else { + char msg[sizeof("\r\n[Process exited ]") + NUMBUFLEN]; + snprintf(msg, sizeof msg, "\r\n[Process exited %d]", status); terminal_receive(term, msg, strlen(msg)); } - if (buf) { + if (buf && !is_autocmd_blocked()) { + dict_T *dict = get_vim_var_dict(VV_EVENT); + tv_dict_add_nr(dict, S_LEN("status"), status); apply_autocmds(EVENT_TERMCLOSE, NULL, NULL, false, buf); + tv_dict_clear(dict); } } |