Add TermClose event

A terminal buffer now exits with: [Process exited <return value>]

You can hook into it. E.g.  :au TermClose * call feedkeys('<cr>')

Closes #2293.
This commit is contained in:
Marco Hinz
2015-11-11 04:27:50 +01:00
parent ac4db4b814
commit 9fcd444036
8 changed files with 20 additions and 9 deletions

View File

@@ -251,6 +251,7 @@ Name triggered by ~
|SwapExists| detected an existing swap file
|TermOpen| when a terminal buffer is starting
|TermClose| when a terminal buffer ends
Options
|FileType| when the 'filetype' option has been set
@@ -871,6 +872,8 @@ TermChanged After the value of 'term' has changed. Useful
for re-loading the syntax file to update the
colors, fonts and other terminal-dependent
settings. Executed for all loaded buffers.
{Nvim} *TermClose*
TermClose When a terminal buffer ends.
{Nvim} *TermOpen*
TermOpen When a terminal buffer is starting. This can
be used to configure the terminal emulator by

View File

@@ -105,6 +105,8 @@ The configuration variables are only processed when the terminal starts, which
is why it needs to be done with the |TermOpen| autocmd or setting global
variables before the terminal is started.
There is also a corresponding |TermClose| event.
The terminal cursor can be highlighted via |hl-TermCursor| and
|hl-TermCursorNC|.

View File

@@ -143,6 +143,8 @@ Events:
|TabNew|
|TabNewEntered|
|TabClosed|
|TermOpen|
|TermClose|
Highlight groups:
|hl-EndOfBuffer|

View File

@@ -77,8 +77,9 @@ return {
'TabNew', -- when creating a new tab
'TabNewEntered', -- after entering a new tab
'TermChanged', -- after changing 'term'
'TermResponse', -- after setting "v:termresponse"
'TermClose', -- after the processs exits
'TermOpen', -- after opening a terminal buffer
'TermResponse', -- after setting "v:termresponse"
'TextChanged', -- text was modified
'TextChangedI', -- text was modified in Insert mode
'User', -- user defined autocommand
@@ -98,9 +99,10 @@ return {
-- List of neovim-specific events or aliases for the purpose of generating
-- syntax file
neovim_specific = {
TabClosed=true,
TabNew=true,
TabNewEntered=true,
TabClosed=true,
TermClose=true,
TermOpen=true,
},
}

View File

@@ -21781,8 +21781,10 @@ static void on_process_exit(Process *proc, int status, void *d)
TerminalJobData *data = d;
if (data->term && !data->exited) {
data->exited = true;
terminal_close(data->term,
_("\r\n[Program exited, press any key to close]"));
char msg[22];
snprintf(msg, sizeof msg, "\r\n[Process exited %d]", proc->status);
terminal_close(data->term, msg);
apply_autocmds(EVENT_TERMCLOSE, NULL, NULL, false, curbuf);
}
if (data->status_ptr) {

View File

@@ -22,7 +22,7 @@ describe(':terminal', function()
wait()
screen:expect([[
ready $ |
[Program exited, press any key to close] |
[Process exited 0] |
|
|
|
@@ -37,7 +37,7 @@ describe(':terminal', function()
screen:expect([[
ready $ echo hi |
|
[Program exited, press any key to close] |
[Process exited 0] |
|
|
|
@@ -51,7 +51,7 @@ describe(':terminal', function()
screen:expect([[
ready $ echo 'hello' \ "world" |
|
[Program exited, press any key to close] |
[Process exited 0] |
|
|
|

View File

@@ -340,7 +340,7 @@ describe('terminal prints more lines than the screen height and exits', function
line8 |
line9 |
|
[Program exited, press any key to close] |
[Process exited 0] |
-- TERMINAL -- |
]])
feed('<cr>')

View File

@@ -167,7 +167,7 @@ describe('tui with non-tty file descriptors', function()
:q |
abc |
|
[Program exited, press any key to close] |
[Process exited 0] |
|
-- TERMINAL -- |
]])