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 |SwapExists| detected an existing swap file
|TermOpen| when a terminal buffer is starting |TermOpen| when a terminal buffer is starting
|TermClose| when a terminal buffer ends
Options Options
|FileType| when the 'filetype' option has been set |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 for re-loading the syntax file to update the
colors, fonts and other terminal-dependent colors, fonts and other terminal-dependent
settings. Executed for all loaded buffers. settings. Executed for all loaded buffers.
{Nvim} *TermClose*
TermClose When a terminal buffer ends.
{Nvim} *TermOpen* {Nvim} *TermOpen*
TermOpen When a terminal buffer is starting. This can TermOpen When a terminal buffer is starting. This can
be used to configure the terminal emulator by 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 is why it needs to be done with the |TermOpen| autocmd or setting global
variables before the terminal is started. variables before the terminal is started.
There is also a corresponding |TermClose| event.
The terminal cursor can be highlighted via |hl-TermCursor| and The terminal cursor can be highlighted via |hl-TermCursor| and
|hl-TermCursorNC|. |hl-TermCursorNC|.

View File

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

View File

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

View File

@@ -21781,8 +21781,10 @@ static void on_process_exit(Process *proc, int status, void *d)
TerminalJobData *data = d; TerminalJobData *data = d;
if (data->term && !data->exited) { if (data->term && !data->exited) {
data->exited = true; data->exited = true;
terminal_close(data->term, char msg[22];
_("\r\n[Program exited, press any key to close]")); 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) { if (data->status_ptr) {

View File

@@ -22,7 +22,7 @@ describe(':terminal', function()
wait() wait()
screen:expect([[ screen:expect([[
ready $ | ready $ |
[Program exited, press any key to close] | [Process exited 0] |
| |
| |
| |
@@ -37,7 +37,7 @@ describe(':terminal', function()
screen:expect([[ screen:expect([[
ready $ echo hi | ready $ echo hi |
| |
[Program exited, press any key to close] | [Process exited 0] |
| |
| |
| |
@@ -51,7 +51,7 @@ describe(':terminal', function()
screen:expect([[ screen:expect([[
ready $ echo 'hello' \ "world" | 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 | line8 |
line9 | line9 |
| |
[Program exited, press any key to close] | [Process exited 0] |
-- TERMINAL -- | -- TERMINAL -- |
]]) ]])
feed('<cr>') feed('<cr>')

View File

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