Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys/consoleinterface.h')
-rw-r--r--src/sys/consoleinterface.h150
1 files changed, 101 insertions, 49 deletions
diff --git a/src/sys/consoleinterface.h b/src/sys/consoleinterface.h
index 5411cb6..3a7d3ed 100644
--- a/src/sys/consoleinterface.h
+++ b/src/sys/consoleinterface.h
@@ -8,89 +8,141 @@
#define __INCLUDED_SYS_CONSOLEINTERFACE_H__
#include <iostream>
+#include <string>
+#include <streambuf>
+#include <ostream>
#include <sstream>
#include <deque>
#include "sys/sys.h"
-/// global define to send a message to the system console
-#define con_print sys::ConsoleInterface::instance()->messagestream()
-/// global define to send a warning message to the system console
-#define con_warn sys::ConsoleInterface::instance()->warningstream()
-/// global define to send an error message to the system console
-#define con_error sys::ConsoleInterface::instance()->errorstream()
-
-#ifdef HAVE_DEBUG_MESSAGES
-/// global define to send a debug message to the system console
-#define con_debug sys::ConsoleInterface::instance()->debugstream()
-#else
-#define con_debug if (0) *(std::ostream*)(0)
-#endif
namespace sys
{
-const size_t MAXCONLINES = 2048;
+/// true if ANSI colors are enabled
+bool ansi();
-/// interface for the client and server Console classes
-class ConsoleInterface
-{
-public:
- /// default constructor
- ConsoleInterface();
+/// enable or disable ANSI colors
+void set_ansi(bool enable = true);
- /// default destructor
- virtual ~ConsoleInterface();
-
- /// stream to send normal messages to
- std::ostream & messagestream();
+/* -- ConsoleBuffer ------------------------------------------------ */
- /// stream to send warning messages to
- std::ostream & warningstream();
+typedef std::char_traits<char> Traits;
- /// stream to send error messages to
- std::ostream & errorstream();
+/// buffer back-end for console output
+class ConsoleBuffer : public std::basic_streambuf<char, Traits >
+{
+public:
+ const std::string & str() const
+ {
+ return con_buffer;
+ }
+
+protected:
+ /// stream overflow
+ virtual int overflow(int c = Traits::eof());
+
+private:
+ std::string con_buffer;
+};
- /// stream to send debug messages to
- std::ostream & debugstream();
- /// flush buffered messages
- virtual void flush();
+/* -- ConsoleStream ------------------------------------------------ */
- /// resize the console (ncurses stub)
- virtual void resize();
+/// provides global streams for console output
+class ConsoleStream : public std::basic_ostream<char, Traits >
+{
+public:
+ ConsoleStream();
+ ~ConsoleStream();
+
+ inline ConsoleBuffer & buf()
+ {
+ return con_buffer;
+ }
+
+private:
+ ConsoleBuffer con_buffer;
+};
- /// return the console inputbuffer
- inline std::stringstream & buffer() { return consoleinterface_buffer; }
+/// global console output stream
+extern ConsoleStream con_out;
- inline bool rcon() { return consoleinterface_rcon; }
- inline bool ansi() { return consoleinterface_ansi; }
+/* -- Console ------------------------------------------------------ */
- /// enable or disable ANSI escape sequences
- void set_ansi(bool enable = true);
+/// interface for the client and server Console classes
+class ConsoleInterface
+{
+public:
+ /// default constructor
+ ConsoleInterface();
+
+ /// default destructor
+ virtual ~ConsoleInterface();
+
+ /// set maximal number of lines in the log
+ void set_logsize(const size_t logsize);
+
+ /// return rcon state
+ inline bool rcon()
+ {
+ return consoleinterface_rcon;
+ }
+
/// enable or disable rcon
void set_rcon(bool enable = true);
-
+
+ typedef std::deque<std::string> Text;
+
+ inline Text & rconbuf()
+ {
+ return consoleinterface_rconbuf;
+ }
+
+ inline Text & log()
+ {
+ return consoleinterface_log;
+ }
+
/// a pointer to the current console instance
static ConsoleInterface *instance();
-
+
+ /// incoming text event handler
+ void event_text(const std::string & text);
+
+ /// ncurses resize event
+ virtual void resize()
+ {};
+
protected:
- std::deque<std::string> consoleinterface_text;
- std::stringstream consoleinterface_buffer;
+ /// print one line of text
+ virtual void print(const std::string & text);
- /// print a string to stdout with ansi color codes
- void print_ansi(const char *line);
-
private:
/// console singleton
static ConsoleInterface *consoleinterface_instance;
- bool consoleinterface_ansi;
+
bool consoleinterface_rcon;
+ Text consoleinterface_rconbuf;
+
+ Text consoleinterface_log;
+ size_t consoleinterface_logsize;
};
} // namespace sys
+#define con_print sys::con_out << "^N"
+#define con_warn sys::con_out << "^W"
+#define con_error sys::con_out << "^R"
+#ifdef HAVE_DEBUG_MESSAGES
+#define con_debug sys::con_out << "^D"
+#else
+#define con_debug if (0) *(std::ostream*)(0)
+#endif
+
+
#endif // __INCLUDED_SYS_CONSOLEINTERFACE_H__