///////////////////////////////////////////////////////////////////////////
prefix_ senf::term::LineEditor::LineEditor(AbstractTerminal & terminal, AcceptCallback cb)
- : BaseEditor(terminal), enabled_ (true), prompt_ ("$"), promptWidth_ (1u), editWidth_ (0u),
+ : BaseEditor(terminal), enabled_ (false), prompt_ ("$"), promptWidth_ (1u), editWidth_ (0u),
text_ (""), point_ (0u), displayPos_ (0u), lastKey_ (0u), callback_ (cb), historyPoint_ (0u)
{
defineKey(KeyParser::Return, &bindings::accept);
if (enabled_)
newline();
hide();
- pushHistory(text_);
+ pushHistory(text_, true);
callback_(text_);
clear();
}
redisplay();
}
-prefix_ void senf::term::LineEditor::pushHistory(std::string const & text)
+prefix_ void senf::term::LineEditor::pushHistory(std::string const & text, bool accept)
{
if (! text.empty()
- && (historyPoint_ == history_.size() || history_[historyPoint_] != text)
+ && (accept || historyPoint_ == history_.size() || history_[historyPoint_] != text)
&& (history_.empty() || history_.back() != text)) {
history_.push_back(text);
while (history_.size() > MAX_HISTORY_SIZE)
history_.erase(history_.begin());
- historyPoint_ = history_.size() - 1;
+ if (accept)
+ historyPoint_ = history_.size() - 1;
}
}
if (!BaseEditor::cb_init())
return false;
prompt(prompt_);
- forceRedisplay();
+ show();
return true;
}