-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCONSOLE.CPP
94 lines (74 loc) · 1.88 KB
/
CONSOLE.CPP
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Console.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "Console.h"
// CConsole
IMPLEMENT_DYNAMIC(CConsole, CDialogBar)
CConsole::CConsole() :
CDialogBar(),
m_strCommandPrompt(_T(">>> ")),
m_strContinuePrompt(_T("... "))
{
m_strCurrentPrompt = m_strCommandPrompt;
}
CConsole::~CConsole()
{
}
void CConsole::DoDataExchange(CDataExchange* pDX)
{
CDialogBar::DoDataExchange(pDX);
DDX_Control(pDX, IDC_COMMAND, m_cbCommand);
DDX_Control(pDX, IDC_OUTPUT, m_wndOutput);
}
BEGIN_MESSAGE_MAP(CConsole, CDialogBar)
ON_COMMAND(IDC_RUN, &CConsole::OnRun)
ON_UPDATE_COMMAND_UI(IDC_RUN, &CConsole::OnUpdateRun)
ON_MESSAGE(WM_INITDIALOG,OnInitDialog)
END_MESSAGE_MAP()
// CConsole message handlers
LRESULT CConsole::OnInitDialog(WPARAM wParam, LPARAM lParam)
{
HandleInitDialog(wParam, lParam);
UpdateData(FALSE);
return FALSE;
}
void CConsole::OnUpdateRun(CCmdUI *pCmdUI)
{
pCmdUI->Enable(TRUE);
}
void CConsole::OnRun()
{
CString strCommand;
m_cbCommand.GetWindowText(strCommand);
HistoryAdd(strCommand);
WriteCommand(m_strCurrentPrompt);
WriteCommand(strCommand);
WriteCommand(CString("\r\n"));
//auto* old = std::cout.rdbuf();
//std::cout.rdbuf(&m_wndOutput);
USES_CONVERSION;
int result = PyRun_SimpleString(OLE2A(strCommand));
//m_pPython->RunCommand(strCommand);
//std::cout.rdbuf(old);
m_cbCommand.SetEditSel(0, -1);
m_cbCommand.Clear();
}
void CConsole::HistoryAdd(const CString& strCommand)
{
auto i = m_cbCommand.FindStringExact(-1, strCommand);
if (i != CB_ERR)
{
m_cbCommand.DeleteString(i);
}
i = m_cbCommand.InsertString(0, strCommand);
m_cbCommand.SetCurSel(i);
}
void CConsole::WriteCommand(const CString& strCommand)
{
CString str;
m_wndOutput.GetWindowText(str);
str += strCommand;
m_wndOutput.SetWindowText(str);
m_wndOutput.UpdateWindow();
}