Skip to content
Permalink
Browse files

console, bugfix: do not reset the terminal outside of console.readLine.

  • Loading branch information...
xicilion committed Jul 9, 2019
1 parent 0fee0ea commit ce4af53d0024a6970ae3959ba0dfb827d98b0db0
Showing with 8 additions and 1 deletion.
  1. +4 −0 fibjs/src/console/console.cpp
  2. +4 −1 fibjs/src/process/process.cpp
@@ -539,6 +539,8 @@ char* read_line(bool no_echo)
return NULL;
}

bool g_in_readline = false;

result_t readInput(exlib::string msg, exlib::string& retVal, AsyncEvent* ac, bool no_echo)
{
if (ac->isSync())
@@ -552,11 +554,13 @@ result_t readInput(exlib::string msg, exlib::string& retVal, AsyncEvent* ac, boo
const char* lfptr = qstrrchr(msg.c_str(), '\n');

el_no_echo = no_echo;
g_in_readline = true;
if (lfptr != NULL) {
puts(msg.substr(0, lfptr - msg.c_str()).c_str());
line = readline(lfptr + 1);
} else
line = readline(msg.c_str());
g_in_readline = false;

if (!line)
return CHECK_ERROR(LastError());
@@ -266,6 +266,8 @@ result_t process_base::get_stderr(obj_ptr<File_base>& retVal)
return 0;
}

extern bool g_in_readline;

result_t process_base::exit()
{
Isolate* isolate = Isolate::current();
@@ -287,7 +289,8 @@ result_t process_base::exit()
#ifdef _WIN32
TerminateProcess(GetCurrentProcess(), code);
#else
rl_deprep_terminal();
if (g_in_readline && isatty(fileno(stdin)))
rl_deprep_terminal();
::_exit(code);
#endif

0 comments on commit ce4af53

Please sign in to comment.
You can’t perform that action at this time.