Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
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
parent74031d8f7d91fe70d0ae447d74a12c5206ea9b62 (diff)
command completion (single match)
Diffstat (limited to 'src/core')
-rw-r--r--src/core/commandbuffer.cc43
-rw-r--r--src/core/commandbuffer.h3
-rw-r--r--src/core/cvar.h4
-rw-r--r--src/core/func.h5
4 files changed, 55 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
diff --git a/src/core/commandbuffer.h b/src/core/commandbuffer.h
index c18acd0..6f5b324 100644
--- a/src/core/commandbuffer.h
+++ b/src/core/commandbuffer.h
@@ -26,6 +26,9 @@ void execute();
/// flush the command buffer
void clear();
+/// tab completion
+void complete(std::string &input, size_t &pos);
+
}
}
diff --git a/src/core/cvar.h b/src/core/cvar.h
index 660f03e..205a416 100644
--- a/src/core/cvar.h
+++ b/src/core/cvar.h
@@ -8,6 +8,7 @@
#define __INCLUDED_CORE_CVAR_H__
#include <string>
+#include <map>
namespace core {
@@ -77,6 +78,9 @@ Cvar find(const char *name);
/// list the cvar registry
void list();
+/// the Cvar registry
+extern std::map<std::string, Cvar> registry;
+
} // namespace cvar
} // namespace core
diff --git a/src/core/func.h b/src/core/func.h
index ad189b8..3a58295 100644
--- a/src/core/func.h
+++ b/src/core/func.h
@@ -10,6 +10,8 @@
#include "sys/sys.h"
#include <sstream>
+#include <string>
+#include <map>
namespace core
{
@@ -34,6 +36,9 @@ Func find(const std::string &functionname);
/// list the function registry
void list();
+/// the function registry
+extern std::map<std::string, Func> registry;
+
} // namespace func
} // namespace core