aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/main.c11
-rw-r--r--src/nvim/os/pty_process_unix.c21
2 files changed, 28 insertions, 4 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c
index aa57913f7c..0346414697 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -73,6 +73,9 @@
#include "nvim/api/private/helpers.h"
#include "nvim/api/private/handle.h"
#include "nvim/api/private/dispatch.h"
+#ifndef WIN32
+# include "nvim/os/pty_process_unix.h"
+#endif
/* Maximum number of commands from + or -c arguments. */
#define MAX_ARG_CMDS 10
@@ -1247,6 +1250,14 @@ static void check_and_set_isatty(mparm_T *paramp)
stdout_isatty
= paramp->output_isatty = os_isatty(fileno(stdout));
paramp->err_isatty = os_isatty(fileno(stderr));
+ int tty_fd = paramp->input_isatty
+ ? OS_STDIN_FILENO
+ : (paramp->output_isatty
+ ? OS_STDOUT_FILENO
+ : (paramp->err_isatty ? OS_STDERR_FILENO : -1));
+#ifndef WIN32
+ pty_process_save_termios(tty_fd);
+#endif
TIME_MSG("window checked");
}
diff --git a/src/nvim/os/pty_process_unix.c b/src/nvim/os/pty_process_unix.c
index e39f837c1a..53301e4b53 100644
--- a/src/nvim/os/pty_process_unix.c
+++ b/src/nvim/os/pty_process_unix.c
@@ -36,13 +36,26 @@
# include "os/pty_process_unix.c.generated.h"
#endif
+/// termios saved at startup (for TUI) or initialized by pty_process_spawn().
+static struct termios termios_default;
+
+/// Saves the termios properties associated with `tty_fd`.
+///
+/// @param tty_fd TTY file descriptor, or -1 if not in a terminal.
+void pty_process_save_termios(int tty_fd)
+{
+ if (tty_fd == -1 || tcgetattr(tty_fd, &termios_default) != 0) {
+ return;
+ }
+}
+
/// @returns zero on success, or negative error code
int pty_process_spawn(PtyProcess *ptyproc)
FUNC_ATTR_NONNULL_ALL
{
- static struct termios termios;
- if (!termios.c_cflag) {
- init_termios(&termios);
+ if (!termios_default.c_cflag) {
+ // TODO(jkeyes): We could pass NULL to forkpty() instead ...
+ init_termios(&termios_default);
}
int status = 0; // zero or negative error code (libuv convention)
@@ -52,7 +65,7 @@ int pty_process_spawn(PtyProcess *ptyproc)
ptyproc->winsize = (struct winsize){ ptyproc->height, ptyproc->width, 0, 0 };
uv_disable_stdio_inheritance();
int master;
- int pid = forkpty(&master, NULL, &termios, &ptyproc->winsize);
+ int pid = forkpty(&master, NULL, &termios_default, &ptyproc->winsize);
if (pid < 0) {
status = -errno;