diff options
author | Stijn Buys <ingar@osirion.org> | 2008-05-14 21:07:10 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-05-14 21:07:10 +0000 |
commit | a185c11f2397c0296a4b62cc266b4fa00a63c1e2 (patch) | |
tree | 186da4cdee2d9cd46fb2415567da1c441c7431ef /src/sys/consoleinterface.cc | |
parent | 599adb817e19d9be3502e501dc904c7255cd616c (diff) |
console, camera & interpolation
Diffstat (limited to 'src/sys/consoleinterface.cc')
-rw-r--r-- | src/sys/consoleinterface.cc | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/src/sys/consoleinterface.cc b/src/sys/consoleinterface.cc index f80939d..a300ea1 100644 --- a/src/sys/consoleinterface.cc +++ b/src/sys/consoleinterface.cc @@ -17,11 +17,15 @@ ConsoleInterface *ConsoleInterface::consoleinterface_instance = 0; ConsoleInterface::ConsoleInterface() { + consoleinterface_ansi = true; if (consoleinterface_instance) { std::cerr << "multiple sys::ConsoleInterface instances!" << std::endl; sys::quit(2); } + consoleinterface_instance = this; + consoleinterface_text.clear(); + consoleinterface_buffer.clear(); } ConsoleInterface::~ConsoleInterface() @@ -34,4 +38,129 @@ ConsoleInterface *ConsoleInterface::instance() return consoleinterface_instance; } +std::ostream & ConsoleInterface::messagestream() +{ + flush(); + return (consoleinterface_buffer << "^N"); +} + +std::ostream & ConsoleInterface::warningstream() +{ + flush(); + return (consoleinterface_buffer << "^W"); +} + +std::ostream & ConsoleInterface::errorstream() +{ + flush(); + return (consoleinterface_buffer << "^R"); +} + +std::ostream & ConsoleInterface::debugstream() +{ + flush(); + return (consoleinterface_buffer << "^D"); +} + +void ConsoleInterface::flush() +{ + char line[MAXCMDSIZE]; + + while(consoleinterface_buffer.getline(line, MAXCMDSIZE-1)) { + + while (consoleinterface_text.size() >= MAXCONLINES) { + consoleinterface_text.pop_front(); + } + consoleinterface_text.push_back(std::string(line)); + + // print to stdout + print_ansi(line); + std::cout << std::endl; + } + + consoleinterface_buffer.clear(); +} + +void ConsoleInterface::print_ansi(const char *line) +{ + if (consoleinterface_ansi) + std::cout << "\033[0;39m"; + + const char *c = line; + while (*c) { + + if ((*c == '^')) { + bool is_code = true; + int bold = 0; + int color = 39; + + switch (*(c+1)) { + case '0': // black + color = 0; + bold = 1; + break; + case '1': // red + color = 31; + break; + case '2': // green + color = 32; + break; + case '3': // yellow + bold = 1; + color = 33; + break; + case '4': // blue + color = 34; + break; + case '5': // cyan + color = 36; + break; + case '6': // magenta + color = 35; + break; + case '7': // white is mapped to foreground color + bold = 1; + color = 39; + break; + + case 'N': // normal + bold = 0; + color = 39; + break; + case 'B': // bold + bold = 1; + color = 39; + break; + case 'D': // debug + bold = 0; + color = 39; + break; + case 'R': // error + bold = 0; + color = 31; + break; + case 'W': // warning + bold = 1; + color = 33; + break; + case 'F': // fancy + bold = 0; + color = 32; + break; + default: + is_code = false; + } + if (is_code) { + c++; + if (consoleinterface_ansi) + std::cout << "\033[" << bold << ";" << color << "m"; + } else + std::cout << *c; + } else { + std::cout << *c; + } + c++; + } +} + } // namespace sys |