mirror of
https://github.com/PowerShell/Win32-OpenSSH.git
synced 2025-07-21 04:54:48 +02:00
Fix to UNICODE issues.
This commit is contained in:
parent
37477b654c
commit
5c02287fd8
@ -315,6 +315,9 @@ void ConSetAttribute(int *iParam, int iParamCount)
|
||||
case ANSI_ATTR_RESET:
|
||||
iAttr |= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
|
||||
|
||||
iAttr = iAttr & ~BACKGROUND_RED;
|
||||
iAttr = iAttr & ~BACKGROUND_BLUE;
|
||||
iAttr = iAttr & ~BACKGROUND_GREEN;
|
||||
iAttr = iAttr & ~BACKGROUND_INTENSITY;
|
||||
iAttr = iAttr & ~FOREGROUND_INTENSITY;
|
||||
iAttr = iAttr & ~COMMON_LVB_UNDERSCORE;
|
||||
@ -530,11 +533,23 @@ void ConFillToEndOfLine()
|
||||
int ConWriteString(char* pszString, int cbString)
|
||||
{
|
||||
DWORD Result = 0;
|
||||
int needed = 0;
|
||||
int cnt = 0;
|
||||
wchar_t* utf16 = NULL;
|
||||
|
||||
if ((needed = MultiByteToWideChar(CP_UTF8, 0, pszString, cbString, NULL, 0)) == 0 ||
|
||||
(utf16 = malloc(needed * sizeof(wchar_t))) == NULL ||
|
||||
(cnt = MultiByteToWideChar(CP_UTF8, 0, pszString, cbString, utf16, needed)) == 0) {
|
||||
Result = (DWORD)printf(pszString);
|
||||
} else {
|
||||
if (hOutputConsole)
|
||||
WriteConsole(hOutputConsole, pszString, cbString, &Result, 0);
|
||||
WriteConsoleW(hOutputConsole, utf16, cnt, &Result, 0);
|
||||
else
|
||||
Result = (DWORD) printf(pszString);
|
||||
Result = (DWORD)wprintf(utf16);
|
||||
}
|
||||
|
||||
if(utf16)
|
||||
free(utf16);
|
||||
|
||||
return cbString;
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ void SendHorizontalScroll(HANDLE hInput, int cells) {
|
||||
WriteFile(hInput, formatted_output, out, &wr, NULL);
|
||||
}
|
||||
|
||||
void SendCharacter(HANDLE hInput, WORD attributes, char character) {
|
||||
void SendCharacter(HANDLE hInput, WORD attributes, wchar_t character) {
|
||||
|
||||
DWORD wr = 0;
|
||||
DWORD out = 0;
|
||||
@ -266,6 +266,9 @@ void SendCharacter(HANDLE hInput, WORD attributes, char character) {
|
||||
PSTR Next;
|
||||
size_t SizeLeft;
|
||||
|
||||
if (!character)
|
||||
return;
|
||||
|
||||
Next = formatted_output;
|
||||
SizeLeft = sizeof formatted_output;
|
||||
|
||||
@ -339,52 +342,33 @@ void SendCharacter(HANDLE hInput, WORD attributes, char character) {
|
||||
if (bUseAnsiEmulation && attributes != pattributes)
|
||||
WriteFile(hInput, formatted_output, (Next - formatted_output), &wr, NULL);
|
||||
|
||||
WriteFile(hInput, &character, 1, &wr, NULL);
|
||||
// East asian languages have 2 bytes for each character, only use the first
|
||||
if (!(attributes & COMMON_LVB_TRAILING_BYTE))
|
||||
{
|
||||
int nSize = WideCharToMultiByte(CP_UTF8,
|
||||
0,
|
||||
&character,
|
||||
1,
|
||||
Next,
|
||||
10,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
if(nSize > 0)
|
||||
WriteFile(hInput, Next, nSize, &wr, NULL);
|
||||
}
|
||||
|
||||
pattributes = attributes;
|
||||
}
|
||||
|
||||
void SendBuffer(HANDLE hInput, CHAR_INFO *buffer, DWORD bufferSize) {
|
||||
|
||||
DWORD wr = 0;
|
||||
DWORD out = 0;
|
||||
DWORD current = 0;
|
||||
|
||||
char* formatted_output = NULL;
|
||||
|
||||
USHORT Color = 0;
|
||||
ULONG Status = 0;
|
||||
|
||||
if (bufferSize <= 0)
|
||||
return;
|
||||
|
||||
formatted_output = (char *)malloc(bufferSize);
|
||||
|
||||
PSTR Next;
|
||||
Next = formatted_output;
|
||||
|
||||
for (DWORD i = 0; i < bufferSize; i++)
|
||||
{
|
||||
// East asian languages have 2 bytes for each character, only use the first
|
||||
if (!(buffer[i].Attributes & COMMON_LVB_TRAILING_BYTE))
|
||||
{
|
||||
WideCharToMultiByte(cp,
|
||||
0,
|
||||
&buffer[i].Char.UnicodeChar,
|
||||
1,
|
||||
Next,
|
||||
1,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
SendCharacter(hInput, buffer[i].Attributes, *Next);
|
||||
|
||||
Next++;
|
||||
}
|
||||
}
|
||||
|
||||
if (formatted_output) {
|
||||
free(formatted_output);
|
||||
SendCharacter(hInput, buffer[i].Attributes, buffer[i].Char.UnicodeChar);
|
||||
}
|
||||
}
|
||||
|
||||
@ -465,7 +449,8 @@ DWORD WINAPI MonitorChild(_In_ LPVOID lpParameter) {
|
||||
DWORD ProcessEvent(void *p) {
|
||||
|
||||
char f[255];
|
||||
char chUpdate;
|
||||
wchar_t chUpdate;
|
||||
|
||||
WORD wAttributes;
|
||||
WORD wX;
|
||||
WORD wY;
|
||||
|
@ -166,7 +166,7 @@ int ReadConsoleForTermEmul(HANDLE hInput, char *destin, int destinlen)
|
||||
if (InputRecord.Event.KeyEvent.bKeyDown)
|
||||
{
|
||||
int n = WideCharToMultiByte(
|
||||
GetConsoleCP(),
|
||||
CP_UTF8,
|
||||
0,
|
||||
&(InputRecord.Event.KeyEvent.uChar.UnicodeChar),
|
||||
1,
|
||||
|
Loading…
x
Reference in New Issue
Block a user