Make lineedit() fail sooner when another lineedit() call is active

Before, calling `dfhack.run_command('tiletypes')` from a `dfhack.timeout` callback would leave the console in a broken state, since raw mode was enabled but never disabled.

Only tested on Linux with a supported terminal.
develop
lethosor 2020-12-03 22:04:00 -05:00
parent 6ceaf77b38
commit fe0cd9a939
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
2 changed files with 6 additions and 2 deletions

@ -405,6 +405,8 @@ namespace DFHack
/// A simple line edit (raw mode)
int lineedit(const std::string& prompt, std::string& output, recursive_mutex * lock, CommandHistory & ch)
{
if(state == con_lineedit)
return Console::FAILURE;
output.clear();
reset_color();
this->prompt = prompt;
@ -414,7 +416,9 @@ namespace DFHack
fflush(dfout_C);
// FIXME: what do we do here???
//SDL_recursive_mutexV(lock);
state = con_lineedit;
std::getline(std::cin, output);
state = con_unclaimed;
//SDL_recursive_mutexP(lock);
return output.size();
}
@ -422,8 +426,6 @@ namespace DFHack
{
int count;
if (enable_raw() == -1) return 0;
if(state == con_lineedit)
return Console::FAILURE;
state = con_lineedit;
count = prompt_loop(lock,ch);
state = con_unclaimed;

@ -376,6 +376,8 @@ namespace DFHack
}
int lineedit(const std::string & prompt, std::string & output, recursive_mutex * lock, CommandHistory & ch)
{
if(state == con_lineedit)
return Console::FAILURE;
output.clear();
reset_color();
int count;