summaryrefslogtreecommitdiff
path: root/library/Console-windows.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-windows.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-windows.cpp')
-rw-r--r--library/Console-windows.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/library/Console-windows.cpp b/library/Console-windows.cpp
index af6af6b2..e0e5310f 100644
--- a/library/Console-windows.cpp
+++ b/library/Console-windows.cpp
@@ -64,13 +64,12 @@ using namespace DFHack;
namespace DFHack
{
- class Private
+ class Private : public std::stringbuf
{
public:
- Private()
+ Private() : basic_stringbuf<char>::basic_stringbuf()
{
dfout_C = 0;
- stream_o = 0;
rawmode = 0;
console_in = 0;
console_out = 0;
@@ -79,7 +78,20 @@ namespace DFHack
state = con_unclaimed;
raw_cursor = 0;
};
- /// Print a formatted string, like printf
+ virtual ~Private()
+ {
+ //sync();
+ }
+ protected:
+ int sync()
+ {
+ print (str().c_str());
+ // Clear the string buffer
+ str(std::string());
+ return 0;
+ }
+ public:
+ /// Print a formatted string, like printf
int print(const char * format, ...)
{
va_list args;
@@ -371,7 +383,6 @@ namespace DFHack
}
FILE * dfout_C;
- duthomhas::stdiobuf * stream_o;
int rawmode; /* for atexit() function to check if restore is needed*/
std::deque <std::string> history;
@@ -415,6 +426,7 @@ bool Console::init(void)
// Allocate a console!
AllocConsole();
d->ConsoleWindow = GetConsoleWindow();
+ d->wlock = SDL_CreateMutex();
HMENU hm = GetSystemMenu(d->ConsoleWindow,false);
DeleteMenu(hm, SC_CLOSE, MF_BYCOMMAND);
@@ -444,10 +456,8 @@ bool Console::init(void)
std::ios::sync_with_stdio();
// make our own weird streams so our IO isn't redirected
- d->stream_o = new duthomhas::stdiobuf(d->dfout_C);
- rdbuf(d->stream_o);
+ rdbuf(d);
std::cin.tie(this);
- d->wlock = SDL_CreateMutex();
clear();
return true;
}