X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FTermlib%2FEditor.cc;h=ce6a3fb140dc5a7719b2a2de3d5a3f4fc19fe00c;hb=61dc3812717cdc89fa2402006d4009236b72dc8f;hp=e8291a2e9f1530f9ed11f5ef331324638671353c;hpb=567f66452149cfe6d5e909901901e50e1bf1fbd1;p=senf.git diff --git a/Utils/Termlib/Editor.cc b/Utils/Termlib/Editor.cc index e8291a2..ce6a3fb 100644 --- a/Utils/Termlib/Editor.cc +++ b/Utils/Termlib/Editor.cc @@ -276,7 +276,7 @@ prefix_ void senf::term::BaseEditor::write(std::string const & s) /////////////////////////////////////////////////////////////////////////// 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); @@ -346,7 +346,7 @@ prefix_ void senf::term::LineEditor::accept() if (enabled_) newline(); hide(); - pushHistory(text_); + pushHistory(text_, true); callback_(text_); clear(); } @@ -430,15 +430,16 @@ prefix_ void senf::term::LineEditor::insert(std::string const & text) 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; } } @@ -465,7 +466,7 @@ prefix_ void senf::term::LineEditor::nextHistory() } } -prefix_ void senf::term::LineEditor::auxDisplay(int line, std::string const & text) +prefix_ void senf::term::LineEditor::auxDisplay(unsigned line, std::string const & text) { toLine(line+1); clearLine(); @@ -521,7 +522,7 @@ prefix_ bool senf::term::LineEditor::cb_init() if (!BaseEditor::cb_init()) return false; prompt(prompt_); - forceRedisplay(); + show(); return true; } @@ -663,18 +664,9 @@ prefix_ void senf::term::bindings::complete(LineEditor & editor, Completer compl didComplete = true; } - // If completion is already unique, make sure completion is followed by a space and place cursor - // after that space - if (completions.size() == 1u) { - if (text.size() <= commonStart || text[commonStart] != ' ') - text.insert(commonStart, " "); - editor.set(text, commonStart + 1); - return; - } - - // Otherwise place cursor directly after the partial completion + // Otherwise place cursor directly after the (possibly partial) completion editor.set(text, commonStart); - if (didComplete) + if (didComplete || completions.size() == 1) return; // Text was not changed, show list of possible completions