summaryrefslogtreecommitdiff
path: root/library/Console-linux.cpp
diff options
context:
space:
mode:
authorPetr Mrázek2011-07-16 00:15:20 +0200
committerPetr Mrázek2011-07-16 00:15:20 +0200
commit9eea07fb66e0b64033fa814edab78c433b1e217a (patch)
tree955ef2fa27b7ede918a06efcd45ad94171c5329a /library/Console-linux.cpp
parentb85f196dc4b12629b463ed01854fd30aaf54defa (diff)
downloaddfhack-9eea07fb66e0b64033fa814edab78c433b1e217a.tar.gz
dfhack-9eea07fb66e0b64033fa814edab78c433b1e217a.tar.bz2
dfhack-9eea07fb66e0b64033fa814edab78c433b1e217a.tar.xz
The console is now awesome when you use C++ streams too.
Diffstat (limited to 'library/Console-linux.cpp')
-rw-r--r--library/Console-linux.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/library/Console-linux.cpp b/library/Console-linux.cpp
index 81ebf724..acbf5b11 100644
--- a/library/Console-linux.cpp
+++ b/library/Console-linux.cpp
@@ -122,17 +122,28 @@ const char * getANSIColor(const int c)
namespace DFHack
{
- class Private
+ class Private : public std::stringbuf
{
public:
Private()
{
dfout_C = NULL;
- stream_o = NULL;
rawmode = false;
supported_terminal = false;
state = con_unclaimed;
};
+ virtual ~Private()
+ {
+ //sync();
+ }
+ protected:
+ int sync()
+ {
+ print(str().c_str());
+ str(std::string()); // Clear the string buffer
+ return 0;
+ }
+ public:
/// Print a formatted string, like printf
int print(const char * format, ...)
{
@@ -563,7 +574,6 @@ namespace DFHack
return raw_buffer.size();
}
FILE * dfout_C;
- duthomhas::stdiobuf * stream_o;
std::deque <std::string> history;
bool supported_terminal;
// state variables
@@ -598,9 +608,8 @@ bool Console::init(void)
d = new Private();
// make our own weird streams so our IO isn't redirected
d->dfout_C = fopen("/dev/tty", "w");
- d->stream_o = new duthomhas::stdiobuf(d->dfout_C);
d->wlock = SDL_CreateMutex();
- rdbuf(d->stream_o);
+ rdbuf(d);
std::cin.tie(this);
clear();
d->supported_terminal = !isUnsupportedTerm() && isatty(STDIN_FILENO);