Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/console.cc91
-rw-r--r--src/server/console.h7
2 files changed, 80 insertions, 18 deletions
diff --git a/src/server/console.cc b/src/server/console.cc
index 6b24c0c..cdaa1f9 100644
--- a/src/server/console.cc
+++ b/src/server/console.cc
@@ -21,6 +21,8 @@ namespace server {
bool console_initialized = false;
bool console_updated = false;
+const size_t MAXHISTOLINES = 512;
+
Console server_console;
#ifdef HAVE_CURSES
@@ -63,7 +65,11 @@ void Console::init()
con_print << "Initializing console..." << std::endl;
#ifdef HAVE_CURSES
- server_console.console_lastrefresh = 1;
+ server_console.history.clear();
+ server_console.history.push_back("");
+ server_console.history_pos = server_console.history.rbegin();
+ server_console.input_pos = 0;
+
server_console.draw();
#endif // HAVE_CURSES
}
@@ -87,14 +93,8 @@ void Console::resize()
endwin();
refresh();
-
- draw_background();
- draw_text();
- draw_input();
- wrefresh(stdwin);
- console_updated = false;
- console_lastrefresh = 0;
+ draw();
}
void Console::flush()
@@ -199,7 +199,7 @@ void Console::draw_text()
int bottom = (int) consoleinterface_text.size() - console_scroll;
int current_line = 0;
- // parse cons0ole text, wrap long lines
+ // parse console text, wrap long lines
for (std::deque<std::string>::iterator it = consoleinterface_text.begin(); it != consoleinterface_text.end() && current_line < bottom; it++) {
if (current_line >= bottom - height) {
std::string linedata(*it);
@@ -312,18 +312,21 @@ void Console::draw_text()
void Console::draw_input()
{
- wmove(stdwin, stdwin->_maxy, 0);
+ color_set(0, NULL);
+ attron(A_BOLD);
+ // draw input text
+ mvaddstr(stdwin->_maxy, 0, ">");
+ mvaddstr(stdwin->_maxy, 1, (*history_pos).c_str());
+ // fill the remainder with spaces
+ for (int i=1 + (*history_pos).size(); i < stdwin->_maxx; i++)
+ addch(' ');
+ // move the cursor to input position
+ move(stdwin->_maxy, 1 + (*history_pos).size());
}
void Console::draw()
{
- flush();
-
- if (console_lastrefresh < 0.1) {
- return;
- }
-
- if (!(console_initialized && console_updated && stdwin->_maxx && stdwin->_maxy))
+ if (!console_initialized)
return;
draw_background();
@@ -337,17 +340,69 @@ void Console::draw()
void Console::frame(float seconds)
{
+ flush();
+
if (!console_initialized)
return;
console_lastrefresh += seconds;
+ bool input_updated = false;
int key = wgetch(stdwin);
while (key != ERR) {
+ if (key == KEY_BACKSPACE || key == 8 || key == 127) {
+ if ((*history_pos).size() && input_pos) {
+ (*history_pos).erase(input_pos-1, 1);
+ input_pos--;
+ input_updated = true;
+ }
+ break;
+ } else if (key == KEY_STAB || key ==9) {
+ core::CommandBuffer::complete( (*history_pos), input_pos);
+ input_updated = true;
+ break;
+ } else if (key == KEY_LEFT) {
+ } else if (key == KEY_HOME) {
+ } else if (key == KEY_RIGHT) {
+ } else if (key == KEY_END) {
+ } else if (key == KEY_UP) {
+ } else if (key == KEY_DOWN) {
+ } else if (key == KEY_ENTER || key == '\n') {
+ if ((*history_pos).size()) {
+ // store input into history
+ while (history.size() >= MAXHISTOLINES) {
+ history.pop_front();
+ }
+
+ core::cmd() << (*history_pos) << std::endl;
+ con_print << "^B>" << (*history_pos) << std::endl;
+ (*history.rbegin()) = (*history_pos);
+
+ history.push_back("");
+ history_pos = history.rbegin();
+ input_pos = 0;
+ input_updated = true;
+ }
+ break;
+ } else if (key == KEY_PPAGE) {
+ } else if (key == KEY_NPAGE) {
+ } else if ((key >= 32) && (key < 127) && ((*history_pos).size() < MAXCMDSIZE)) {
+ if (input_pos == (*history_pos).size()) {
+ (*history_pos) += (char)key;
+ } else {
+ (*history_pos).insert(input_pos, 1, (char)key);
+ }
+ input_pos++;
+ input_updated = true;
+ }
key = wgetch(stdwin);
}
- draw();
+ if (console_updated) {
+ draw();
+ } else if (input_updated) {
+ draw_input();
+ }
}
#endif // HAVE_CURSES
diff --git a/src/server/console.h b/src/server/console.h
index eeee0ca..ed15c79 100644
--- a/src/server/console.h
+++ b/src/server/console.h
@@ -38,8 +38,15 @@ protected:
private:
/// set ncurses drawing color
void set_color(const char *color_code);
+ /// timestamp for screen refresh timeout
float console_lastrefresh;
+ // input history
+ std::deque<std::string> history;
+ std::deque<std::string>::reverse_iterator history_pos;
+
+ size_t input_pos;
+
#endif
};