Allow "stealing" unfinished input. Enables resetting as a side-effect.

This commit is contained in:
Axel Naumann 2016-04-06 10:02:03 +02:00
parent 7cffe5e49b
commit e43f5dbaa5
2 changed files with 7 additions and 5 deletions

View File

@ -49,8 +49,8 @@ namespace textinput {
}
void
TextInput::TakeInput(std::string &input) {
if (fLastReadResult != kRRReadEOLDelimiter
TextInput::TakeInput(std::string &input, bool force) {
if (!force && fLastReadResult != kRRReadEOLDelimiter
&& fLastReadResult != kRREOF) {
input.clear();
return;
@ -67,12 +67,14 @@ namespace textinput {
ReleaseInputOutput();
if (fLastReadResult == kRRReadEOLDelimiter) {
if (force || fLastReadResult == kRRReadEOLDelimiter) {
// Input has been taken, we can continue reading.
fLastReadResult = kRRNone;
// We will have to redraw the prompt, even if unchanged.
fNeedPromptRedraw = true;
} // else keep EOF.
} else {
fLastReadResult = kRREOF;
}
}
bool

View File

@ -69,7 +69,7 @@ namespace textinput {
EReadResult GetReadState() const { return fLastReadResult; }
char GetLastKey() const { return fLastKey; }
const std::string& GetInput();
void TakeInput(std::string& input); // Take and reset input
void TakeInput(std::string& input, bool force = false); // Take and reset input
bool AtEOL() const { return fLastReadResult == kRRReadEOLDelimiter || AtEOF(); }
bool AtEOF() const { return fLastReadResult == kRREOF; }
bool HavePendingInput() const;