Skip to content

Commit

Permalink
Shell: Update termios settings to match line discipline.
Browse files Browse the repository at this point in the history
Shell.cpp uses its own line discipline which handles
echoing and line editing. Because of this we disable
ICANON and ECHO so that we don't get duplicate characters
or weird line editing errors.

We also revert these settings just before running a command.
This is so that commands may run with proper line editing
and echoing.
  • Loading branch information
DrewStratford authored and awesomekling committed Oct 20, 2019
1 parent 4c35c8d commit 58f67c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions Shell/GlobalState.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct GlobalState {
pid_t sid;
uid_t uid;
struct termios termios;
struct termios default_termios;
bool was_interrupted { false };
bool was_resized { false };
int last_return_code { 0 };
Expand Down
8 changes: 7 additions & 1 deletion Shell/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ static int run_command(const String& cmd)

struct termios trm;
tcgetattr(0, &trm);
tcsetattr(0, TCSANOW, &g.default_termios);

struct SpawnedProcess {
String name;
Expand Down Expand Up @@ -840,7 +841,12 @@ int main(int argc, char** argv)
g.uid = getuid();
g.sid = setsid();
tcsetpgrp(0, getpgrp());
tcgetattr(0, &g.termios);
tcgetattr(0, &g.default_termios);
g.termios = g.default_termios;
// Because we use our own line discipline which includes echoing,
// we disable ICANON and ECHO.
g.termios.c_lflag &= ~(ECHO | ICANON);
tcsetattr(0, TCSANOW, &g.termios);

signal(SIGINT, [](int) {
g.was_interrupted = true;
Expand Down

0 comments on commit 58f67c1

Please sign in to comment.