Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-02-09 10:08:30 +0000
committerStijn Buys <ingar@osirion.org>2008-02-09 10:08:30 +0000
commit2b6208917e92d93f94ad6620c5135d1bcd237ea8 (patch)
tree63f16813ecfaf6ea3ab8ee709b843a6ae65188f3 /src/core/commandbuffer.cc
parent74031d8f7d91fe70d0ae447d74a12c5206ea9b62 (diff)
command completion (single match)
Diffstat (limited to 'src/core/commandbuffer.cc')
-rw-r--r--src/core/commandbuffer.cc43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc
index eaa8504..a46863c 100644
--- a/src/core/commandbuffer.cc
+++ b/src/core/commandbuffer.cc
@@ -10,6 +10,7 @@
// C++ headers
#include <string>
#include <sstream>
+#include <list>
namespace core
{
@@ -73,6 +74,48 @@ void clear()
while (core::cmd.getline(line, MAXCMDSIZE-1));
}
+void complete(std::string &input, size_t &pos)
+{
+ std::list<std::string> match;
+
+ std::string partial = input.substr(0, pos);
+ if (!partial.size())
+ return;
+
+ // search function registry for matches
+ std::map<std::string, Func>::iterator f;
+ for (f = func::registry.begin(); f != func::registry.end(); f++) {
+ if (partial == (*f).first.substr(0, partial.size())) {
+ match.push_back((*f).first);
+ //con_print << " " << (*f).first << std::endl;
+ }
+ }
+
+ // search cvar registry for matches
+ std::map<std::string, Cvar>::iterator c;
+ for (c = cvar::registry.begin(); c != cvar::registry.end(); c++) {
+ if (partial == (*c).first.substr(0, partial.size())) {
+ match.push_back((*c).first);
+ //con_print << " " << (*c).first << std::endl;
+ }
+ }
+
+ if (!match.size())
+ return;
+
+ if (match.size() == 1) {
+ std::list<std::string>::iterator l;
+ l = match.begin();
+ input.replace(0, pos, (*l));
+ pos = (*l).size();
+ } else {
+ std::list<std::string>::iterator l;
+ for (l = match.begin(); l !=match.end(); l++)
+ con_print << " " << (*l) << std::endl;
+ }
+
+}
+
} // namespace commandbuffer
} // namespace core