-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConOut.h
57 lines (48 loc) · 1.42 KB
/
ConOut.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef CONOUT_H
#define CONOUT_H
#include <windows.h>
#include <string>
#include <vector>
#include <streambuf>
#include <functional>
//Buffer size for basic_streambuf in characters
//Keep it reasonable - if it's nearing LONG_MAX you definetely doing it wrong
#define W32WBUF_OBUFLEN 4096
class Win32WcostreamBuf: private std::basic_streambuf<wchar_t> {
typedef std::function<void(const std::wstring&)> AoutCallbackType;
public:
enum WCType:char {WCOUT=1, WCERR=2, WCLOG=3};
private:
enum OutType:char {NONE, REDIR, GEN, CON, GUICON, BADCON};
//NONE - we basically have nowhere to output stdstream
//REDIR - stdstream is redirected to file
//GEN - stdstream goes to some generic device
//CON - have own console
//GUICON - succesfully attached parent console
//BADCON - attached parent console is unusable
static int console_attached;
wchar_t obuf[W32WBUF_OBUFLEN];
bool active;
bool enabled;
WCType wc_type;
int orig_mode;
std::wstreambuf *orig_buf;
OutType stdstream_type;
HANDLE hstdstream;
AoutCallbackType aout_proc;
std::wstring aout_buf;
bool WriteBuffer();
void ClearScreen();
void SimulateEnterKey();
virtual int_type overflow(int_type ch);
virtual int sync();
public:
Win32WcostreamBuf(WCType wc_type);
~Win32WcostreamBuf();
bool Activate();
bool AttachAdditionalOutput(AoutCallbackType aout);
void OutputEnabled(bool value);
bool CallAdditionalOutput();
bool Deactivate();
};
#endif //CONOUT_H