Utils/Console: Console UDPServer
[senf.git] / Utils / Console / LineEditor.cc
index 95f1153..df9d065 100644 (file)
@@ -65,6 +65,12 @@ prefix_ void senf::console::detail::LineEditorSwitcher::v_write(std::string cons
     reader_->write(data);
 }
 
+prefix_ unsigned senf::console::detail::LineEditorSwitcher::v_width()
+    const
+{
+    return reader_->width();
+}
+
 ///////////////////////////////////////////////////////////////////////////
 // senf::console::detail::LineEditorClientReader
 
@@ -109,6 +115,12 @@ prefix_ void senf::console::detail::LineEditorClientReader::v_write(std::string
     BaseTelnetProtocol::write(data);
 }
 
+prefix_ unsigned senf::console::detail::LineEditorClientReader::v_width()
+    const
+{
+    return editor_.width();
+}
+
 prefix_ void
 senf::console::detail::LineEditorClientReader::executeLine(std::string const & text)
 {
@@ -144,11 +156,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->followLink().isDirectory() ? "/" : " "));
         return;
     }
     
@@ -169,20 +178,24 @@ 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<LinkNode*>(node)->follow();
-                    if (!node->isDirectory())
+                    GenericNode & node (cs.begin()->second->followLink());
+                    if (!node.isDirectory())
                         return;
-                    dir = static_cast<DirectoryNode*>(node);
+                    dir = static_cast<DirectoryNode*>(&node);
                     basePath += cs.begin()->first + "/";
                 }
                 else
@@ -191,11 +204,9 @@ 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->followLink().isDirectory() ? "/" : " "));
 }
 
 ///////////////////////////////cc.e////////////////////////////////////////