aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbarenblat@gmail.com>2021-12-26 15:57:13 -0500
committerGravatar Benjamin Barenblat <bbarenblat@gmail.com>2021-12-26 15:57:13 -0500
commit4590204701232f3bee50daf69a0d3e62b026c648 (patch)
tree5d7ad9da3f97f51b37b6331b8c57d02030c21280 /src
parent56f7d79efdc8ad26f5e8e5508eb616144f04fea3 (diff)
goldfishterm: Don’t hard-code std::cout/STDOUT_FILENOHEADmain
Make terminal-handling code purer by requiring the user pass TERM, a termios struct, and an appropriate ostream rather than querying them from the environment. This eliminates some error-handling code and makes duplicate syscalls less likely.
Diffstat (limited to 'src')
-rw-r--r--src/ui/terminal/line.cc10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/ui/terminal/line.cc b/src/ui/terminal/line.cc
index 962b692..e668b28 100644
--- a/src/ui/terminal/line.cc
+++ b/src/ui/terminal/line.cc
@@ -16,6 +16,7 @@
#include <errno.h>
#include <signal.h>
+#include <stdlib.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <unistd.h>
@@ -78,7 +79,14 @@ TerminalLine::TerminalLine() {
}
EnterRawMode();
- tty_ = std::make_unique<goldfishterm::SimpleTerminalOutput>(current_termios_);
+
+ const char* terminal_name = getenv("TERM");
+ if (terminal_name == nullptr) {
+ // Fall back to a minimal subset of the ANSI capabilities.
+ terminal_name = "ansi-mini";
+ }
+ tty_ = std::make_unique<goldfishterm::SimpleTerminalOutput>(
+ terminal_name, current_termios_, std::cout);
sigwinch_watcher_ = std::thread([this] {
sigset_t sigwinch = SigsetContaining(SIGWINCH);