From 1e0df536c2fae85c317ce9c3cc17603d5f98c911 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 15 Oct 2008 20:33:15 +0000 Subject: moved client console into a Widget --- src/server/console.cc | 63 +++++++++++++++++++++------------------------------ src/server/console.h | 13 ++++++----- src/server/server.cc | 4 ++-- 3 files changed, 35 insertions(+), 45 deletions(-) (limited to 'src/server') diff --git a/src/server/console.cc b/src/server/console.cc index 3f32337..ab03c58 100644 --- a/src/server/console.cc +++ b/src/server/console.cc @@ -59,14 +59,15 @@ void Console::init() init_pair(4, COLOR_BLUE, -1); init_pair(5, COLOR_CYAN, -1); init_pair(6, COLOR_MAGENTA, -1); - init_pair(7, -1, -1); + init_pair(7, COLOR_WHITE, -1); + init_pair(8, -1, -1); } console_initialized = true; console_updated = true; #endif // HAVE_CURSES - con_print << "Initializing console..." << std::endl; + con_print << "^BInitializing console..." << std::endl; #ifdef HAVE_CURSES server_console.history.clear(); @@ -80,7 +81,7 @@ void Console::init() void Console::shutdown() { - con_print << "Shutting down console..." << std::endl; + con_print << "^BShutting down console..." << std::endl; #ifdef HAVE_CURSES server_console.draw(); @@ -91,15 +92,20 @@ void Console::shutdown() #endif } +Console::Console() +{ +} + +Console::~Console() +{ +} + #ifdef HAVE_CURSES void Console::dump() { - flush(); - // dump console content - for (std::deque::iterator it = consoleinterface_text.begin(); it != consoleinterface_text.end(); it++) { - print_ansi((*it).c_str()); - std::cout << std::endl; + for (Text::iterator it = log().begin(); it != log().end(); it++) { + sys::ConsoleInterface::print((*it)); } } @@ -114,23 +120,9 @@ void Console::resize() draw(); } -void Console::flush() +void Console::print(const std::string & text) { - if (rcon()) - return; - - char line[MAXCMDSIZE]; - - while(consoleinterface_buffer.getline(line, MAXCMDSIZE-1)) { - - while (consoleinterface_text.size() >= sys::MAXCONLINES) { - consoleinterface_text.pop_front(); - } - consoleinterface_text.push_back(std::string(line)); - console_updated = true; - } - - consoleinterface_buffer.clear(); + console_updated = true; } void Console::set_color(const char *color_code) @@ -143,10 +135,10 @@ void Console::set_color(const char *color_code) if (aux::is_base_color_code(color_code)) { // base colors - // Black=0, Red=1, Green=2, Yellow=3, Blue=4, Cyan=5, Magenta=6, White=7 + // Default=0, Red=1, Green=2, Yellow=3, Blue=4, Cyan=5, Magenta=6, White=7 color = *(color_code+1) - '0'; - if (color == 3 || color == 0) + if (color == 3 || color == 7) bold = true; else bold = false; @@ -223,15 +215,15 @@ void Console::draw_text() if ((w < 3) || (h < 3)) return; - std::deque lines; + Text lines; int height = stdwin->_maxy - 1; int width = stdwin->_maxx - 1; - int bottom = (int) consoleinterface_text.size() - console_scroll; + int bottom = (int) log().size() - console_scroll; int current_line = 0; // parse console text, wrap long lines - for (std::deque::iterator it = consoleinterface_text.begin(); it != consoleinterface_text.end() && current_line < bottom; it++) { + for (Text::iterator it = log().begin(); it != log().end() && current_line < bottom; it++) { if (current_line >= bottom - height) { std::string linedata(*it); linedata += '\n'; @@ -322,7 +314,7 @@ void Console::draw_text() color_set(0, NULL); attroff(A_BOLD); - for (std::deque::reverse_iterator rit = lines.rbegin(); (y > 0) && (rit != lines.rend()); ++rit) { + for (Text::reverse_iterator rit = lines.rbegin(); (y > 0) && (rit != lines.rend()); ++rit) { const char *c = (*rit).c_str(); int x = 0; @@ -366,20 +358,16 @@ void Console::draw() wrefresh(stdwin); console_updated = false; - console_lastrefresh = 0; } void Console::frame(float seconds) { const size_t scroll_offset = 3; - std::deque::reverse_iterator upit; - - flush(); + Text::reverse_iterator upit; if (!console_initialized) return; - console_lastrefresh += seconds; bool input_updated = false; int key = wgetch(stdwin); @@ -450,8 +438,8 @@ void Console::frame(float seconds) break; } else if (key == KEY_PPAGE) { console_scroll += scroll_offset; - if (console_scroll > consoleinterface_text.size()) - console_scroll = consoleinterface_text.size(); + if (console_scroll > log().size()) + console_scroll = log().size(); console_updated = true; break; } else if (key == KEY_NPAGE) { @@ -487,6 +475,7 @@ void Console::frame(float seconds) if (input_updated) { // move the cursor to input position move(stdwin->_maxy, 1 + input_pos); + wrefresh(stdwin); } } } diff --git a/src/server/console.h b/src/server/console.h index bf77ecd..59d65d9 100644 --- a/src/server/console.h +++ b/src/server/console.h @@ -13,14 +13,15 @@ namespace server { class Console : public sys::ConsoleInterface { public: + Console(); + ~Console(); + /// initialize the server console static void init(); /// shutdown the server console static void shutdown(); #ifdef HAVE_CURSES - /// flush buffered messages - virtual void flush(); /// resize the console virtual void resize(); /// run one console frame @@ -39,16 +40,16 @@ protected: void draw_input(); /// dump console content to cout void dump(); + /// print one line of text (do nothing) + virtual void print(const std::string & text); private: /// set ncurses drawing color void set_color(const char *color_code); - /// timestamp for screen refresh timeout - float console_lastrefresh; // input history - std::deque history; - std::deque::reverse_iterator history_pos; + Text history; + Text::reverse_iterator history_pos; size_t input_pos; size_t console_scroll; diff --git a/src/server/server.cc b/src/server/server.cc index 27cf6bd..f08ca6c 100644 --- a/src/server/server.cc +++ b/src/server/server.cc @@ -56,7 +56,7 @@ void main(int count, char **arguments) void Server::init(int count, char **arguments) { - con_print << "Initializing server..." << std::endl; + con_print << "^BInitializing server..." << std::endl; core::Cvar::sv_private = core::Cvar::set("sv_dedicated", "1", core::Cvar::ReadOnly); core::Application::init(count, arguments); @@ -92,7 +92,7 @@ void Server::run() void Server::shutdown() { - con_print << "Shutting down server..." << std::endl; + con_print << "^BShutting down server..." << std::endl; float ratio = 0; if (core::Stats::network_uncompressed_bytes_sent > 0) -- cgit v1.2.3