Skip to content

Commit

Permalink
Pick a reasonable fallback wrap width when GetConsoleScreenBufferInfo…
Browse files Browse the repository at this point in the history
…() fails
attie-argentum committed Nov 14, 2020
1 parent 36b787d commit e88c285
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions STDLogSink.cpp
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@
#include <cstdio>
#include <cstdarg>
#include <string>
#include <sstream>
#include <limits.h>
#ifdef _WIN32
#include <windows.h>
@@ -62,9 +63,28 @@ STDLogSink::STDLogSink(Severity min_severity)
m_termWidth = 120; //for now, force emscripten to always 120 char wrapping
#endif
#else
HANDLE h;
BOOL ret;
ostringstream msg;
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
m_termWidth = csbi.dwSize.X;

m_termWidth = 80; //Pick a reasonable fallback value

h = GetStdHandle(STD_OUTPUT_HANDLE);
if (h == INVALID_HANDLE_VALUE)
{
msg << "GetStdHandle() failed (" << GetLastError() << ");\n";
Log(Severity::WARNING, msg.str());
}
else if ((ret = GetConsoleScreenBufferInfo(h, &csbi)) == FALSE)
{
msg << "GetConsoleScreenBufferInfo() failed (" << GetLastError() << ");\n";
Log(Severity::WARNING, msg.str());
}
else
{
m_termWidth = csbi.dwSize.X;
}
#endif
}

0 comments on commit e88c285

Please sign in to comment.