diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/console.cc | 58 | ||||
-rw-r--r-- | src/client/console.h | 6 | ||||
-rw-r--r-- | src/core/commandbuffer.cc | 28 | ||||
-rw-r--r-- | src/render/tga.cc | 2 |
4 files changed, 84 insertions, 10 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(); + } } diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc index a46863c..965f428 100644 --- a/src/core/commandbuffer.cc +++ b/src/core/commandbuffer.cc @@ -102,16 +102,30 @@ void complete(std::string &input, size_t &pos) if (!match.size()) return; + + std::string maxmatch(*match.begin()); - if (match.size() == 1) { + 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++) + for (l = match.begin(); l !=match.end(); l++) { + if (maxmatch.size()) { + size_t i =0; + while ((i < maxmatch.size() && i < (*l).size()) && (maxmatch[i] == (*l)[i])) { + i++; + } + if (i < maxmatch.size()) + maxmatch.erase(i); + } con_print << " " << (*l) << std::endl; + } + con_print << match.size() << " matches" << std::endl; + + } + + if (maxmatch.size() > partial.size()) { + if (match.size()==1) maxmatch += ' '; + input.replace(0, pos, maxmatch); + pos = maxmatch.size(); } } diff --git a/src/render/tga.cc b/src/render/tga.cc index 3584566..18236fa 100644 --- a/src/render/tga.cc +++ b/src/render/tga.cc @@ -74,7 +74,7 @@ TGA::image *TGA::load(const char *filename) f->read((void *)&bits, sizeof(GLubyte)); f->skip(length +1); - con_debug << " TGA loading " << width << "x" << height << " " << (int) bits << "bpp" << std::endl; + con_debug << " " << filename << " " << width << "x" << height << "x" << (int) bits << "bpp" << std::endl; if (imgType != TGA_RLE) { // Check for 24 or 32 Bit |