提交 7fc39611 编写于 作者: A Alexey Milovidov

Implemented #2877 in another way

上级 8ca2eed7
......@@ -90,6 +90,7 @@ namespace ErrorCodes
extern const int UNEXPECTED_PACKET_FROM_SERVER;
extern const int CLIENT_OUTPUT_FORMAT_SPECIFIED;
extern const int LOGICAL_ERROR;
extern const int CANNOT_SET_SIGNAL_HANDLER;
}
......@@ -1516,6 +1517,29 @@ public:
}
}
#if USE_READLINE
auto clear_prompt_or_exit = [](int)
{
/// This is signal safe. Error code is not checked.
(void) write(STDOUT_FILENO, "\n", 1);
if (rl_line_buffer[0])
{
rl_replace_line("", 0);
rl_forced_update_display();
}
else
{
/// A little dirty, but we struggle to find better way to correctly
/// force readline to exit after returning from the signal handler.
exit(0);
}
};
if (signal(SIGINT, clear_prompt_or_exit) == SIG_ERR)
throwFromErrno("Cannot set signal handler.", ErrorCodes::CANNOT_SET_SIGNAL_HANDLER);
#endif
ioctl(0, TIOCGWINSZ, &terminal_size);
namespace po = boost::program_options;
......
......@@ -387,6 +387,7 @@ namespace ErrorCodes
extern const int EXTERNAL_SERVER_IS_NOT_RESPONDING = 410;
extern const int PTHREAD_ERROR = 411;
extern const int NETLINK_ERROR = 412;
extern const int CANNOT_SET_SIGNAL_HANDLER = 413;
extern const int KEEPER_EXCEPTION = 999;
extern const int POCO_EXCEPTION = 1000;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册