summaryrefslogtreecommitdiff
path: root/Shell
diff options
context:
space:
mode:
authorDrew Stratford <drewstratford@outlook.com>2019-10-20 20:02:55 +1300
committerAndreas Kling <awesomekling@gmail.com>2019-10-20 10:51:12 +0200
commit58f67c1ccbe6391aec6508c3f8cd72513220b8ad (patch)
treeee28937fb5775a76adb256cff2559530d0e03447 /Shell
parent4c35c8d7fd4c593e8211d65be9a298ec27dcfa52 (diff)
downloadserenity-58f67c1ccbe6391aec6508c3f8cd72513220b8ad.zip
Shell: Update termios settings to match line discipline.
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.
Diffstat (limited to 'Shell')
-rw-r--r--Shell/GlobalState.h1
-rw-r--r--Shell/main.cpp8
2 files changed, 8 insertions, 1 deletions
diff --git a/Shell/GlobalState.h b/Shell/GlobalState.h
index e92dd8df3e..645652f4ac 100644
--- a/Shell/GlobalState.h
+++ b/Shell/GlobalState.h
@@ -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 };
diff --git a/Shell/main.cpp b/Shell/main.cpp
index 28b4a3519f..2dc62b0702 100644
--- a/Shell/main.cpp
+++ b/Shell/main.cpp
@@ -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;
@@ -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;