Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Use CRLF in the terminal prints. #92158

Merged
merged 1 commit into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions platform/windows/windows_terminal_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,30 @@ void WindowsTerminalLogger::logv(const char *p_format, va_list p_list, bool p_er
return;
}

const unsigned int BUFFER_SIZE = 16384;
char buf[BUFFER_SIZE + 1]; // +1 for the terminating character
int len = vsnprintf(buf, BUFFER_SIZE, p_format, p_list);
if (len <= 0) {
return;
const int static_buffer_size = 1024;
char static_buf[static_buffer_size];
char *buf = static_buf;
va_list list_copy;
va_copy(list_copy, p_list);
int len = vsnprintf(buf, static_buffer_size, p_format, p_list);
if (len >= static_buffer_size) {
buf = (char *)memalloc(len + 1);
len = vsnprintf(buf, len + 1, p_format, list_copy);
}
va_end(list_copy);

String str_buf = String::utf8(buf, len).replace("\r\n", "\n").replace("\n", "\r\n");
bruvzg marked this conversation as resolved.
Show resolved Hide resolved
if (len >= static_buffer_size) {
memfree(buf);
}
if ((unsigned int)len >= BUFFER_SIZE) {
len = BUFFER_SIZE; // Output is too big, will be truncated
CharString cstr_buf = str_buf.utf8();
if (cstr_buf.length() == 0) {
return;
}
buf[len] = 0;

DWORD written = 0;
HANDLE h = p_err ? GetStdHandle(STD_ERROR_HANDLE) : GetStdHandle(STD_OUTPUT_HANDLE);
WriteFile(h, &buf[0], len, &written, nullptr);
WriteFile(h, cstr_buf.ptr(), cstr_buf.length(), &written, nullptr);

#ifdef DEBUG_ENABLED
FlushFileBuffers(h);
Expand Down
Loading