From 4590204701232f3bee50daf69a0d3e62b026c648 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Sun, 26 Dec 2021 15:57:13 -0500 Subject: goldfishterm: Don’t hard-code std::cout/STDOUT_FILENO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/ui/terminal/line.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') 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 #include +#include #include #include #include @@ -78,7 +79,14 @@ TerminalLine::TerminalLine() { } EnterRawMode(); - tty_ = std::make_unique(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( + terminal_name, current_termios_, std::cout); sigwinch_watcher_ = std::thread([this] { sigset_t sigwinch = SigsetContaining(SIGWINCH); -- cgit v1.2.3