mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 08:18:17 +00:00
terminal: New module that implements a terminal emulator
This commit integrates libvterm with Neovim and implements a terminal emulator with nvim buffers as the display mechanism. Terminal buffers can be created using any of the following methods: - Opening a file with name following the "term://[${cwd}//[${pid}:]]${cmd}" URI pattern where: - cwd is the working directory of the process - pid is the process id. This is just for use in session files where a pid would have been assigned to the saved buffer title. - cmd is the command to run - Invoking the `:terminal` ex command - Invoking the `termopen` function which returns a job id for automating the terminal window. Some extra changes were also implemented to adapt with terminal buffers. Here's an overview: - The `main` function now sets a BufReadCmd autocmd to intercept the term:// URI and spawn the terminal buffer instead of reading the file. - terminal buffers behave as if the following local buffer options were set: - `nomodifiable` - `swapfile` - `undolevels=-1` - `bufhidden=hide` - All commands that delete buffers(`:bun`, `:bd` and `:bw`) behave the same for terminal buffers, but only work when bang is passed(eg: `:bwipeout!`) - A new "terminal" mode was added. A consequence is that a new set of mapping commands were implemented with the "t" prefix(tmap, tunmap, tnoremap...) - The `edit` function(which enters insert mode) will actually enter terminal mode if the current buffer is a terminal - The `put` operator was adapted to send data to the terminal instead of modifying the buffer directly. - A window being resized will also trigger a terminal resize if the window displays the terminal.
This commit is contained in:
@@ -62,6 +62,7 @@
|
||||
#include "nvim/strings.h"
|
||||
#include "nvim/syntax.h"
|
||||
#include "nvim/tag.h"
|
||||
#include "nvim/terminal.h"
|
||||
#include "nvim/ui.h"
|
||||
#include "nvim/undo.h"
|
||||
#include "nvim/version.h"
|
||||
@@ -71,6 +72,8 @@
|
||||
#include "nvim/os/time.h"
|
||||
#include "nvim/ex_cmds_defs.h"
|
||||
#include "nvim/mouse.h"
|
||||
#include "nvim/os/rstream.h"
|
||||
#include "nvim/os/wstream.h"
|
||||
|
||||
static int quitmore = 0;
|
||||
static int ex_pressedreturn = FALSE;
|
||||
@@ -1510,7 +1513,9 @@ static char_u * do_one_cmd(char_u **cmdlinep,
|
||||
errormsg = (char_u *)_(e_sandbox);
|
||||
goto doend;
|
||||
}
|
||||
if (!MODIFIABLE(curbuf) && (ea.argt & MODIFY)) {
|
||||
if (!MODIFIABLE(curbuf) && (ea.argt & MODIFY)
|
||||
// allow :put in terminals
|
||||
&& (!curbuf->terminal || ea.cmdidx != CMD_put)) {
|
||||
/* Command not allowed in non-'modifiable' buffer */
|
||||
errormsg = (char_u *)_(e_modifiable);
|
||||
goto doend;
|
||||
@@ -2610,7 +2615,7 @@ set_one_cmd_context (
|
||||
xp->xp_context = EXPAND_FILES;
|
||||
|
||||
/* For a shell command more chars need to be escaped. */
|
||||
if (usefilter || ea.cmdidx == CMD_bang) {
|
||||
if (usefilter || ea.cmdidx == CMD_bang || ea.cmdidx == CMD_terminal) {
|
||||
#ifndef BACKSLASH_IN_FILENAME
|
||||
xp->xp_shell = TRUE;
|
||||
#endif
|
||||
@@ -5126,8 +5131,10 @@ static void ex_quit(exarg_T *eap)
|
||||
|| (only_one_window() && check_changed_any(eap->forceit))) {
|
||||
not_exiting();
|
||||
} else {
|
||||
if (only_one_window()) /* quit last window */
|
||||
if (only_one_window()) {
|
||||
// quit last window
|
||||
getout(0);
|
||||
}
|
||||
/* close window; may free buffer */
|
||||
win_close(curwin, !P_HID(curwin->w_buffer) || eap->forceit);
|
||||
}
|
||||
@@ -8060,7 +8067,9 @@ makeopens (
|
||||
/*
|
||||
* Wipe out an empty unnamed buffer we started in.
|
||||
*/
|
||||
if (put_line(fd, "if exists('s:wipebuf')") == FAIL)
|
||||
if (put_line(fd, "if exists('s:wipebuf') "
|
||||
"&& getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'")
|
||||
== FAIL)
|
||||
return FAIL;
|
||||
if (put_line(fd, " silent exe 'bwipe ' . s:wipebuf") == FAIL)
|
||||
return FAIL;
|
||||
@@ -8269,7 +8278,7 @@ put_view (
|
||||
* Load the file.
|
||||
*/
|
||||
if (wp->w_buffer->b_ffname != NULL
|
||||
&& !bt_nofile(wp->w_buffer)
|
||||
&& (!bt_nofile(wp->w_buffer) || wp->w_buffer->terminal)
|
||||
) {
|
||||
/*
|
||||
* Editing a file in this buffer: use ":edit file".
|
||||
@@ -8857,3 +8866,12 @@ static void ex_folddo(exarg_T *eap)
|
||||
global_exe(eap->arg);
|
||||
ml_clearmarked(); /* clear rest of the marks */
|
||||
}
|
||||
|
||||
static void ex_terminal(exarg_T *eap)
|
||||
{
|
||||
char cmd[512];
|
||||
snprintf(cmd, sizeof(cmd), ":enew%s | call termopen('%s') | startinsert",
|
||||
eap->forceit==TRUE ? "!" : "",
|
||||
strcmp((char *)eap->arg, "") ? (char *)eap->arg : (char *)p_sh);
|
||||
do_cmdline_cmd((uint8_t *)cmd);
|
||||
}
|
||||
|
Reference in New Issue
Block a user