Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pty_no_echo option #10557

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/nvim/channel.c
Expand Up @@ -274,6 +274,7 @@ Channel *channel_job_start(char **argv, CallbackReader on_stdout,
CallbackReader on_stderr, Callback on_exit,
bool pty, bool rpc, bool detach, const char *cwd,
uint16_t pty_width, uint16_t pty_height,
bool pty_echo,
char *term_name, varnumber_T *status_out)
{
assert(cwd == NULL || os_isdir_executable(cwd));
Expand All @@ -299,6 +300,9 @@ Channel *channel_job_start(char **argv, CallbackReader on_stdout,
if (pty_height > 0) {
chan->stream.pty.height = pty_height;
}
if (!pty_echo) {
chan->stream.pty.echo = false;
}
if (term_name) {
chan->stream.pty.term_name = term_name;
}
Expand Down
9 changes: 6 additions & 3 deletions src/nvim/eval.c
Expand Up @@ -12164,6 +12164,7 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv, FunPtr fptr)
bool detach = false;
bool rpc = false;
bool pty = false;
bool pty_echo = true;
CallbackReader on_stdout = CALLBACK_READER_INIT,
on_stderr = CALLBACK_READER_INIT;
Callback on_exit = CALLBACK_NONE;
Expand Down Expand Up @@ -12201,14 +12202,15 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv, FunPtr fptr)
char *term_name = NULL;

if (pty) {
pty_echo = !(tv_dict_get_number(job_opts, "pty_no_echo") != 0);
width = (uint16_t)tv_dict_get_number(job_opts, "width");
height = (uint16_t)tv_dict_get_number(job_opts, "height");
term_name = tv_dict_get_string(job_opts, "TERM", true);
}

Channel *chan = channel_job_start(argv, on_stdout, on_stderr, on_exit, pty,
rpc, detach, cwd, width, height, term_name,
&rettv->vval.v_number);
rpc, detach, cwd, width, height, pty_echo,
term_name, &rettv->vval.v_number);
if (chan) {
channel_create_event(chan, NULL);
}
Expand Down Expand Up @@ -14516,7 +14518,7 @@ static void f_rpcstart(typval_T *argvars, typval_T *rettv, FunPtr fptr)

Channel *chan = channel_job_start(argv, CALLBACK_READER_INIT,
CALLBACK_READER_INIT, CALLBACK_NONE,
false, true, false, NULL, 0, 0, NULL,
false, true, false, NULL, 0, 0, true, NULL,
&rettv->vval.v_number);
if (chan) {
channel_create_event(chan, NULL);
Expand Down Expand Up @@ -17828,6 +17830,7 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr)
Channel *chan = channel_job_start(argv, on_stdout, on_stderr, on_exit,
true, false, false, cwd,
term_width, curwin->w_height_inner,
true,
xstrdup("xterm-256color"),
&rettv->vval.v_number);
if (rettv->vval.v_number <= 0) {
Expand Down
13 changes: 10 additions & 3 deletions src/nvim/os/pty_process_unix.c
Expand Up @@ -56,7 +56,7 @@ int pty_process_spawn(PtyProcess *ptyproc)
{
if (!termios_default.c_cflag) {
// TODO(jkeyes): We could pass NULL to forkpty() instead ...
init_termios(&termios_default);
init_termios(&termios_default, ptyproc);
}

int status = 0; // zero or negative error code (libuv convention)
Expand Down Expand Up @@ -183,7 +183,10 @@ static void init_child(PtyProcess *ptyproc)
_exit(122); // 122 is EXEC_FAILED in the Vim source.
}

static void init_termios(struct termios *termios) FUNC_ATTR_NONNULL_ALL
static void init_termios(
struct termios *termios,
PtyProcess *ptyproc
) FUNC_ATTR_NONNULL_ALL
{
// Taken from pangoterm
termios->c_iflag = ICRNL|IXON;
Expand All @@ -192,7 +195,11 @@ static void init_termios(struct termios *termios) FUNC_ATTR_NONNULL_ALL
termios->c_oflag |= TAB0;
#endif
termios->c_cflag = CS8|CREAD;
termios->c_lflag = ISIG|ICANON|IEXTEN|ECHO|ECHOE|ECHOK;
termios->c_lflag = ISIG|ICANON|IEXTEN|ECHOE|ECHOK;

if (ptyproc->echo) {
termios->c_lflag |= ECHO;
}

cfsetspeed(termios, 38400);

Expand Down
2 changes: 2 additions & 0 deletions src/nvim/os/pty_process_unix.h
Expand Up @@ -11,6 +11,7 @@ typedef struct pty_process {
uint16_t width, height;
struct winsize winsize;
int tty_fd;
bool echo;
} PtyProcess;

static inline PtyProcess pty_process_init(Loop *loop, void *data)
Expand All @@ -21,6 +22,7 @@ static inline PtyProcess pty_process_init(Loop *loop, void *data)
rv.width = 80;
rv.height = 24;
rv.tty_fd = -1;
rv.echo = true;
return rv;
}

Expand Down