From 8e63aa1548d8158fbccd53ec64057027401e0505 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 9 Nov 2019 08:19:45 +1100 Subject: [PATCH] Check that stdout is a tty in ncurses ui --- src/main.cc | 18 +----------------- src/ncurses_ui.cc | 6 +++++- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/main.cc b/src/main.cc index 1a9c38a4..5fc49b59 100644 --- a/src/main.cc +++ b/src/main.cc @@ -106,11 +106,6 @@ void show_startup_info(Client* local_client, int last_version) } } -struct startup_error : runtime_error -{ - using runtime_error::runtime_error; -}; - inline void write_stdout(StringView str) { try { write(STDOUT_FILENO, str); } catch (runtime_error&) {} } inline void write_stderr(StringView str) { try { write(STDERR_FILENO, str); } catch (runtime_error&) {} } @@ -578,9 +573,6 @@ std::unique_ptr create_local_ui(UIType ui_type) } }; - if (not isatty(1)) - throw startup_error("stdout is not a tty"); - if (not isatty(0)) { // move stdin to another fd, and restore tty as stdin @@ -1104,9 +1096,6 @@ int main(int argc, char* argv[]) for (auto name : files) new_files += format("edit '{}';", escape(real_path(name), "'", '\\')); - if (not isatty(1)) - throw startup_error("stdout is not a tty"); - return run_client(*server_session, {}, new_files + client_init, init_coord, ui_type, false); } else @@ -1137,14 +1126,9 @@ int main(int argc, char* argv[]) generate_switches_doc(param_desc.switches))); return -1; } - catch (startup_error& error) - { - write_stderr(format("Could not start kakoune: {}\n", error.what())); - return -1; - } catch (Kakoune::exception& error) { - write_stderr(format("uncaught exception ({}):\n{}\n", typeid(error).name(), error.what())); + write_stderr(format("Fatal error: {}\n", error.what())); return -1; } catch (std::exception& error) diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index 1489789c..15417ff2 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -2,10 +2,11 @@ #include "display_buffer.hh" #include "event_manager.hh" +#include "exception.hh" +#include "file.hh" #include "keys.hh" #include "ranges.hh" #include "string_utils.hh" -#include "file.hh" #include @@ -336,6 +337,9 @@ NCursesUI::NCursesUI() }}, m_assistant(assistant_clippy) { + if (not isatty(1)) + throw runtime_error("stdout is not a tty"); + tcgetattr(STDIN_FILENO, &m_original_termios); initscr();