Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/dedicated/console.cc')
-rw-r--r--src/dedicated/console.cc107
1 files changed, 54 insertions, 53 deletions
diff --git a/src/dedicated/console.cc b/src/dedicated/console.cc
index 5b7d92f..2c4c0da 100644
--- a/src/dedicated/console.cc
+++ b/src/dedicated/console.cc
@@ -22,7 +22,8 @@
#include <curses.h>
#endif
-namespace dedicated {
+namespace dedicated
+{
bool console_initialized = false;
bool console_updated = false;
@@ -43,19 +44,19 @@ Console *console()
void Console::init()
{
#ifdef HAVE_CURSES
- stdwin = initscr(); // initialize the ncurses window
- cbreak(); // disable input line buffering
- noecho(); // don't show typed characters
- keypad(stdwin, TRUE); // enable special keys
- nodelay(stdwin, TRUE); // non-blocking input
- curs_set(1); // enable cursor
+ stdwin = initscr(); // initialize the ncurses window
+ cbreak(); // disable input line buffering
+ noecho(); // don't show typed characters
+ keypad(stdwin, TRUE); // enable special keys
+ nodelay(stdwin, TRUE); // non-blocking input
+ curs_set(1); // enable cursor
if (has_colors() == TRUE) {
start_color();
// this is ncurses-specific
use_default_colors();
// COLOR_PAIR(0) is terminal default
- init_pair(1, COLOR_RED, -1);
+ init_pair(1, COLOR_RED, -1);
init_pair(2, COLOR_GREEN, -1);
init_pair(3, COLOR_YELLOW, -1);
init_pair(4, COLOR_BLUE, -1);
@@ -69,10 +70,10 @@ void Console::init()
con_print << "^BInitializing console..." << std::endl;
#ifdef HAVE_CURSES
- server_console.history.clear();
- server_console.history.push_back("");
- server_console.history_pos = server_console.history.rbegin();
- server_console.input_pos = 0;
+ server_console.history.clear();
+ server_console.history.push_back("");
+ server_console.history_pos = server_console.history.rbegin();
+ server_console.input_pos = 0;
server_console.console_scroll = 0;
server_console.draw();
#endif // HAVE_CURSES
@@ -105,7 +106,7 @@ Console::~Console()
#ifdef HAVE_CURSES
void Console::dump()
{
- // dump console content
+ // dump console content
for (Queue::iterator it = log().begin(); it != log().end(); it++) {
sys::ConsoleInterface::print((*it));
}
@@ -115,11 +116,11 @@ void Console::resize()
{
if (!console_initialized)
return;
-
+
endwin();
refresh();
- draw();
+ draw();
}
void Console::print(const std::string & text)
@@ -142,7 +143,7 @@ void Console::set_color(const char *color_code)
// base colors
// Default=0, Red=1, Green=2, Yellow=3, Blue=4, Cyan=5, Magenta=6, White=7
- color = *(color_code+1) - '0';
+ color = *(color_code + 1) - '0';
if (color == 3 || color == 7)
bold = true;
else
@@ -150,7 +151,7 @@ void Console::set_color(const char *color_code)
} else if (aux::is_core_color_code(color_code)) {
- switch (*(color_code+1)) {
+ switch (*(color_code + 1)) {
case 'N': // normal color
case 'D': // debug color
color = 0;
@@ -206,7 +207,7 @@ void Console::draw_status()
attroff(A_BOLD);
color_set(2, NULL);
int minutes = (int) floorf(core::game()->time() / 60.0f);
- int seconds = (int) floorf( core::game()->time() - (float) minutes* 60.0f);
+ int seconds = (int) floorf(core::game()->time() - (float) minutes * 60.0f);
std::stringstream status;
status << "time " << std::setfill(' ') << std::setw(3) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds;
mvaddnstr(0, 1, status.str().c_str(), status.str().size());
@@ -249,8 +250,8 @@ void Console::draw_text()
}
// new word, wrap if necessary
- else if ((*c == '\n' ) || ( *c == ' ')) {
-
+ else if ((*c == '\n') || (*c == ' ')) {
+
if (line_length + word_length > console_width) {
if (line.size()) {
lines.push_back(line);
@@ -260,31 +261,31 @@ void Console::draw_text()
line_length = 0;
}
}
-
+
line.append(word);
line_length += word_length;
word.clear();
word_length = 0;
wordpen = pen;
-
+
// new line
- if (*c == '\n' ) {
+ if (*c == '\n') {
lines.push_back(line);
line.clear();
line_length = 0;
- // new word
- } else if (*c == ' ' ) {
+ // new word
+ } else if (*c == ' ') {
line += ' ';
line_length++;
}
}
// new character
- else {
+ else {
word += *c;
word_length++;
-
+
if (word_length == console_width) {
if (line.size()) {
lines.push_back(line);
@@ -305,9 +306,9 @@ void Console::draw_text()
c++;
}
-
+
}
- current_line++;
+ current_line++;
}
int y = console_height - 1;
@@ -339,20 +340,20 @@ void Console::draw_input()
attron(A_BOLD);
// draw input text
mvaddstr(console_height, 0, ">");
- mvaddstr(console_height, 1, (*history_pos).c_str());
+ mvaddstr(console_height, 1, (*history_pos).c_str());
// fill the remainder with spaces
- for (int i=1 + (*history_pos).size(); i < console_width; i++)
+ for (int i = 1 + (*history_pos).size(); i < console_width; i++)
addch(' ');
}
-void Console::draw()
+void Console::draw()
{
- if (!console_initialized)
+ if (!console_initialized)
return;
#ifdef _WIN32
- console_width = stdwin->_maxx -1;
- console_height = stdwin->_maxy -1;
+ console_width = stdwin->_maxx - 1;
+ console_height = stdwin->_maxy - 1;
#else
console_width = stdwin->_maxx;
console_height = stdwin->_maxy;
@@ -381,13 +382,13 @@ void Console::frame()
while (key != ERR) {
if (key == KEY_BACKSPACE || key == 8 || key == 127) {
if ((*history_pos).size() && input_pos) {
- (*history_pos).erase(input_pos-1, 1);
+ (*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);
+ } else if (key == KEY_STAB || key == 9) {
+ core::CommandBuffer::complete((*history_pos), input_pos);
input_updated = true;
break;
} else if (key == KEY_LEFT) {
@@ -396,7 +397,7 @@ void Console::frame()
}
input_updated = true;
break;
- } else if (key == KEY_RIGHT) {
+ } else if (key == KEY_RIGHT) {
if (input_pos < (*history_pos).size()) {
input_pos++;
}
@@ -425,38 +426,38 @@ void Console::frame()
input_pos = (*history_pos).size();
input_updated = true;
}
- break;
- } else if (key == KEY_ENTER || key == '\n') {
+ break;
+ } 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;
console_updated = true;
}
break;
- } else if (key == KEY_PPAGE) {
- console_scroll += scroll_offset;
- if (console_scroll > log().size())
+ } else if (key == KEY_PPAGE) {
+ console_scroll += scroll_offset;
+ if (console_scroll > log().size())
console_scroll = log().size();
console_updated = true;
- break;
- } else if (key == KEY_NPAGE) {
- if (console_scroll > scroll_offset)
+ break;
+ } else if (key == KEY_NPAGE) {
+ if (console_scroll > scroll_offset)
console_scroll -= scroll_offset;
- else
+ else
console_scroll = 0;
console_updated = true;
- break;
- } else if ((key >= 32) && (key < 127) && ((*history_pos).size() < MAXCMDSIZE)) {
+ break;
+ } else if ((key >= 32) && (key < 127) && ((*history_pos).size() < MAXCMDSIZE)) {
if (input_pos == (*history_pos).size()) {
(*history_pos) += (char)key;
} else {
@@ -464,7 +465,7 @@ void Console::frame()
}
input_pos++;
input_updated = true;
- }
+ }
key = wgetch(stdwin);
}