Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/console.cc58
-rw-r--r--src/client/console.h6
2 files changed, 62 insertions, 2 deletions
diff --git a/src/client/console.cc b/src/client/console.cc
index 71f3d5a..01f90da 100644
--- a/src/client/console.cc
+++ b/src/client/console.cc
@@ -4,13 +4,15 @@
the terms and conditions of the GNU General Public License version 2
*/
+#include "filesystem/filesystem.h"
+#include "core/core.h"
+#include "render/render.h"
#include "client/console.h"
#include "client/video.h"
#include "client/keyboard.h"
-#include "core/core.h"
-#include "render/render.h"
#include <iostream>
+#include <fstream>
#include <cmath>
namespace client {
@@ -79,12 +81,16 @@ void init()
history.push_back("");
history_pos = history.rbegin();
input_pos = 0;
+
+ load_history();
}
void shutdown()
{
con_print << "Shutting down console..." << std::endl;
+ save_history();
+
// remove engine functions
core::func::remove("con_toggle");
@@ -282,6 +288,54 @@ bool visible()
return console_visible;
}
+void save_history()
+{
+
+ if (history.size() <= 1)
+ return;
+
+ std::string filename(filesystem::writedir);
+ filename.append("history.txt");
+ std::ofstream ofs(filename.c_str());
+
+ if (!ofs.is_open()) {
+ con_warn << "Could not write " << filename << std::endl;
+ return;
+ }
+ std::deque<std::string>::iterator it;
+ size_t l = 1;
+ for (it = history.begin(); it != history.end(); it++) {
+ if (l < history.size())
+ ofs << (*it) << std::endl;
+ l++;
+ }
+
+ ofs.close();
+}
+
+void load_history()
+{
+ std::string filename(filesystem::writedir);
+ filename.append("history.txt");
+ std::ifstream ifs(filename.c_str(), std::ifstream::in);
+
+ if (!ifs.is_open()) {
+ con_warn << "Could not read " << filename << std::endl;
+ return;
+ }
+
+ history.clear();
+ char line[MAXCMDSIZE];
+ while (ifs.getline(line, MAXCMDSIZE-1)) {
+ history.push_back(line);
+ }
+
+ ifs.close();
+
+ history.push_back("");
+ history_pos = history.rbegin();
+ input_pos = 0;
+}
//--- private -----------------------------------------------------
std::ostream & Console::messagestream()
diff --git a/src/client/console.h b/src/client/console.h
index e848720..e96c0d4 100644
--- a/src/client/console.h
+++ b/src/client/console.h
@@ -47,6 +47,12 @@ void keypressed(const SDL_keysym &keysym);
/// true of the console is visible
bool visible();
+/// load input history
+void load_history();
+
+/// save input history
+void save_history();
+
}
}