-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconsole.h
60 lines (49 loc) · 1.11 KB
/
console.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
58
59
60
#ifndef CONSOLE_H
#define CONSOLE_H
#include <mutex>
#include <iostream>
#include <QMainWindow>
class QTextEdit;
class console_stream : public std::basic_streambuf<char>
{
std::basic_streambuf<char>* cout_buf = nullptr;
public:
console_stream(void):std::basic_streambuf<char>(){}
protected:
virtual int_type overflow(int_type v) override;
virtual std::streamsize xsputn(const char *p, std::streamsize n) override;
public:
void show_output(void);
std::mutex edit_buf;
QString buf;
QTextEdit* log_window = nullptr;
bool has_output = false;
void attach(void)
{
if(!cout_buf)
cout_buf = std::cout.rdbuf(this);
}
void detach(void)
{
if(cout_buf)
std::cout.rdbuf(cout_buf);
}
};
extern console_stream console;
namespace Ui {
class Console;
}
class Console : public QMainWindow
{
Q_OBJECT
public:
explicit Console(QWidget *parent = nullptr);
~Console();
private slots:
void on_run_cmd_clicked();
void on_set_dir_clicked();
private:
Ui::Console *ui;
};
extern console_stream console;
#endif // CONSOLE_H