Check that stdout is a tty in ncurses ui
This commit is contained in:
parent
9d700344f7
commit
8e63aa1548
18
src/main.cc
18
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_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&) {} }
|
inline void write_stderr(StringView str) { try { write(STDERR_FILENO, str); } catch (runtime_error&) {} }
|
||||||
|
|
||||||
|
@ -578,9 +573,6 @@ std::unique_ptr<UserInterface> create_local_ui(UIType ui_type)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (not isatty(1))
|
|
||||||
throw startup_error("stdout is not a tty");
|
|
||||||
|
|
||||||
if (not isatty(0))
|
if (not isatty(0))
|
||||||
{
|
{
|
||||||
// move stdin to another fd, and restore tty as stdin
|
// move stdin to another fd, and restore tty as stdin
|
||||||
|
@ -1104,9 +1096,6 @@ int main(int argc, char* argv[])
|
||||||
for (auto name : files)
|
for (auto name : files)
|
||||||
new_files += format("edit '{}';", escape(real_path(name), "'", '\\'));
|
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);
|
return run_client(*server_session, {}, new_files + client_init, init_coord, ui_type, false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1137,14 +1126,9 @@ int main(int argc, char* argv[])
|
||||||
generate_switches_doc(param_desc.switches)));
|
generate_switches_doc(param_desc.switches)));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
catch (startup_error& error)
|
|
||||||
{
|
|
||||||
write_stderr(format("Could not start kakoune: {}\n", error.what()));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
catch (Kakoune::exception& error)
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
catch (std::exception& error)
|
catch (std::exception& error)
|
||||||
|
|
|
@ -2,10 +2,11 @@
|
||||||
|
|
||||||
#include "display_buffer.hh"
|
#include "display_buffer.hh"
|
||||||
#include "event_manager.hh"
|
#include "event_manager.hh"
|
||||||
|
#include "exception.hh"
|
||||||
|
#include "file.hh"
|
||||||
#include "keys.hh"
|
#include "keys.hh"
|
||||||
#include "ranges.hh"
|
#include "ranges.hh"
|
||||||
#include "string_utils.hh"
|
#include "string_utils.hh"
|
||||||
#include "file.hh"
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
@ -336,6 +337,9 @@ NCursesUI::NCursesUI()
|
||||||
}},
|
}},
|
||||||
m_assistant(assistant_clippy)
|
m_assistant(assistant_clippy)
|
||||||
{
|
{
|
||||||
|
if (not isatty(1))
|
||||||
|
throw runtime_error("stdout is not a tty");
|
||||||
|
|
||||||
tcgetattr(STDIN_FILENO, &m_original_termios);
|
tcgetattr(STDIN_FILENO, &m_original_termios);
|
||||||
|
|
||||||
initscr();
|
initscr();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user