summaryrefslogtreecommitdiffstats
path: root/src/windows/leash/out2con.h
blob: ebd3859d3cad3255479d93c4cae1fa24e852cbde (plain)
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
#ifndef OUT2CON_H
#define OUT2CON_H

/* Call CreateConsoleEcho() to create a console and begin echoing stdout to it.
 * The original stream (if any) will still receive output from stdout.
 * Call DestroyConsoleEcho() to stop echoing stdout to the console.
 * The original stream continues to receive stdout.
 *
 * WARNING: it is not safe to use stdout from another thread during
 *          CreateConsoleEcho() or DestroyConsoleEcho()
 */

class ConsoleEcho;

ConsoleEcho *
CreateConsoleEcho();

void
DestroyConsoleEcho(ConsoleEcho *consoleEcho);

// Convenience class to automatically echo to console within a scope
class AutoConsoleEcho
{
public:
    AutoConsoleEcho() : m_echo(CreateConsoleEcho())
    {
    }

    ~AutoConsoleEcho()
    {
        DestroyConsoleEcho(m_echo);
    }
private:
    ConsoleEcho* m_echo;
};


#endif