Skip to content

Commit 9682aa9

Browse files
committed
修复 xp 下大尺寸字符串输出失败的错误
1 parent 6dfdc20 commit 9682aa9

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

fibjs/src/console/console_std.cpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ void std_logger::out(exlib::string& txt)
3636
m_tty = _isatty(_fileno(stdout)) != FALSE;
3737
}
3838

39+
void WriteConsole(exlib::wchar* ptr, size_t sz)
40+
{
41+
DWORD dwWrite;
42+
43+
while (sz)
44+
{
45+
size_t sz1 = sz;
46+
if (sz1 >= 16384)
47+
sz1 = 16384;
48+
WriteConsoleW(m_handle, ptr, (DWORD)sz1, &dwWrite, NULL);
49+
ptr += sz1;
50+
sz -= sz1;
51+
}
52+
}
53+
3954
void out(exlib::string& s)
4055
{
4156
if (!m_tty)
@@ -48,13 +63,12 @@ void std_logger::out(exlib::string& txt)
4863
exlib::wchar *ptr = &ws[0];
4964
exlib::wchar *pend = ptr + ws.length();
5065
exlib::wchar *ptr2;
51-
DWORD dwWrite;
5266

5367
while (ptr2 = (exlib::wchar *) qstrchr(ptr, L'\x1b'))
5468
{
5569
if (ptr2[1] == '[')
5670
{
57-
WriteConsoleW(m_handle, ptr, (DWORD)(ptr2 - ptr), &dwWrite, NULL);
71+
WriteConsole(ptr, ptr2 - ptr);
5872

5973
ptr2 += 2;
6074

@@ -159,7 +173,7 @@ void std_logger::out(exlib::string& txt)
159173
ptr = ptr2;
160174
}
161175

162-
WriteConsoleW(m_handle, ptr, (DWORD)(pend - ptr), &dwWrite, NULL);
176+
WriteConsole(ptr, pend - ptr);
163177
}
164178

165179
private:

0 commit comments

Comments
 (0)