From: g0dil Date: Fri, 9 Jan 2009 08:54:07 +0000 (+0000) Subject: Utils/Console: Better directory name completion X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=2e64ec3584f231af8c4aab0b780046b355ff64ae;p=senf.git Utils/Console: Better directory name completion Utils/Termlib: Fix completiion semantics git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1050 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Utils/Console/LineEditor.cc b/Utils/Console/LineEditor.cc index 95f1153..bf4d869 100644 --- a/Utils/Console/LineEditor.cc +++ b/Utils/Console/LineEditor.cc @@ -144,11 +144,8 @@ completePath(term::LineEditor & editor, unsigned b, unsigned e, ParseCommandInfo::TokensRange path (cmd.commandPath()); if (path.empty()) { DirectoryNode::ChildrenRange cs (client().cwd().children()); - for (DirectoryNode::ChildrenRange::iterator i (cs.begin()); i != cs.end(); ++i) { - completions.push_back(i->first); - if (i->second->isDirectory()) - completions.push_back(i->first + "/"); - } + for (DirectoryNode::ChildrenRange::iterator i (cs.begin()); i != cs.end(); ++i) + completions.push_back(i->first + (i->second->isDirectory() ? "/" : "")); return; } @@ -169,17 +166,21 @@ completePath(term::LineEditor & editor, unsigned b, unsigned e, basePath += "../"; } else if (*i == WordToken(".")) - ; + basePath += "./"; else { if (dir->hasChild(i->value())) { - dir = & dir->getDirectory(i->value()); + try { + dir = & dir->getDirectory(i->value()); + } + catch (std::bad_cast &) { + return; + } basePath += i->value() + "/"; - } else { + } + else { DirectoryNode::ChildrenRange cs (dir->completions(i->value())); if (has_one_elt(cs)) { GenericNode * node (cs.begin()->second.get()); - if (node->isLink()) - node = & static_cast(node)->follow(); if (!node->isDirectory()) return; dir = static_cast(node); @@ -191,11 +192,8 @@ completePath(term::LineEditor & editor, unsigned b, unsigned e, } DirectoryNode::ChildrenRange cs (dir->completions(i->value())); - for (DirectoryNode::ChildrenRange::iterator j (cs.begin()); j != cs.end(); ++j) { - completions.push_back(basePath + j->first); - if (j->second->isDirectory()) - completions.push_back(basePath + j->first + "/"); - } + for (DirectoryNode::ChildrenRange::iterator j (cs.begin()); j != cs.end(); ++j) + completions.push_back(basePath + j->first + (j->second->isDirectory() ? "/" : "")); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Utils/Termlib/Editor.cc b/Utils/Termlib/Editor.cc index e8291a2..8d16f4d 100644 --- a/Utils/Termlib/Editor.cc +++ b/Utils/Termlib/Editor.cc @@ -663,18 +663,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