Improvement: #72 Input command is always at the end of Shelldlg

This commit is contained in:
yuanyuanxiang
2025-04-06 16:23:10 +08:00
parent 13288b5c4e
commit 9475e59887
4 changed files with 62 additions and 5 deletions

View File

@@ -6,6 +6,18 @@
#include "ShellDlg.h"
#include "afxdialogex.h"
BEGIN_MESSAGE_MAP(CAutoEndEdit, CEdit)
ON_WM_CHAR()
END_MESSAGE_MAP()
void CAutoEndEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) {
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD>ı<EFBFBD>ĩβ
int nLength = GetWindowTextLength();
SetSel(nLength, nLength);
// <20><><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><E0B4A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
// CShellDlg <20>Ի<EFBFBD><D4BB><EFBFBD>
@@ -34,6 +46,7 @@ void CShellDlg::DoDataExchange(CDataExchange* pDX)
BEGIN_MESSAGE_MAP(CShellDlg, CDialog)
ON_WM_CLOSE()
ON_WM_CTLCOLOR()
ON_WM_SIZE()
END_MESSAGE_MAP()
@@ -59,6 +72,12 @@ BOOL CShellDlg::OnInitDialog()
BYTE bToken = COMMAND_NEXT;
m_iocpServer->OnClientPreSending(m_ContextObject, &bToken, sizeof(BYTE));
m_Edit.SetWindowTextA(">>");
m_nCurSel = m_Edit.GetWindowTextLengthA();
m_nReceiveLength = m_nCurSel;
m_Edit.SetSel((int)m_nCurSel, (int)m_nCurSel);
m_Edit.PostMessage(EM_SETSEL, m_nCurSel, m_nCurSel);
return TRUE; // return TRUE unless you set the focus to a control
// <20>쳣: OCX <20><><EFBFBD><EFBFBD>ҳӦ<D2B3><D3A6><EFBFBD><EFBFBD> FALSE
}
@@ -76,6 +95,12 @@ VOID CShellDlg::OnReceiveComplete()
}
#include <regex>
std::string removeAnsiCodes(const std::string& input) {
std::regex ansi_regex("\x1B\\[[0-9;]*[mK]");
return std::regex_replace(input, ansi_regex, "");
}
VOID CShellDlg::AddKeyBoardData(void)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
@@ -84,7 +109,8 @@ VOID CShellDlg::AddKeyBoardData(void)
//Shit\0
m_ContextObject->InDeCompressedBuffer.WriteBuffer((LPBYTE)"", 1); //<2F>ӱ<EFBFBD><D3B1><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>\0
Buffer tmp = m_ContextObject->InDeCompressedBuffer.GetMyBuffer(0);
CString strResult = tmp.c_str(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> \0
bool firstRecv = tmp.c_str() == std::string(">");
CString strResult = firstRecv ? "" : CString("\r\n") + removeAnsiCodes(tmp.c_str()).c_str(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> \0
//<2F><EFBFBD><E6BBBB>ԭ<EFBFBD><D4AD><EFBFBD>Ļ<EFBFBD><C4BB>з<EFBFBD> <20><><EFBFBD><EFBFBD>cmd <20>Ļ<EFBFBD><C4BB><EFBFBD>ͬw32<33>µı<C4B1>ؼ<EFBFBD><D8BC>Ļ<EFBFBD><C4BB>з<EFBFBD><D0B7><EFBFBD>һ<EFBFBD><D2BB> <20><><EFBFBD>еĻس<C4BB><D8B3><EFBFBD><EFBFBD><EFBFBD>
strResult.Replace("\n", "\r\n");
@@ -146,15 +172,14 @@ BOOL CShellDlg::PreTranslateMessage(MSG* pMsg)
//Ȼ<><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7>ͳ<EFBFBD>ȥ
LPBYTE pSrc = (LPBYTE)str.GetBuffer(0) + m_nCurSel;
#ifdef _DEBUG
OutputDebugStringA("[Shell]=> ");
OutputDebugStringA((char*)pSrc);
TRACE("[Shell]=> %s", (char*)pSrc);
#endif
int length = str.GetLength() - m_nCurSel;
m_iocpServer->OnClientPreSending(m_ContextObject, pSrc, length);
m_nCurSel = m_Edit.GetWindowTextLength();
if (0 == strcmp((char*)pSrc, "exit\r\n"))
{
ShowWindow(SW_HIDE);
return PostMessage(WM_CLOSE);
}
}
// <20><><EFBFBD><EFBFBD>VK_BACK
@@ -190,3 +215,19 @@ HBRUSH CShellDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
}
return hbr;
}
void CShellDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if (!m_Edit.GetSafeHwnd()) return; // ȷ<><C8B7><EFBFBD>ؼ<EFBFBD><D8BC>Ѵ<EFBFBD><D1B4><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>úʹ<C3BA>С
CRect rc;
m_Edit.GetWindowRect(&rc);
ScreenToClient(&rc);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿؼ<C3BF><D8BC><EFBFBD>С
m_Edit.MoveWindow(0, 0, cx, cy, TRUE);
}