summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Niklas Hasse <jhasse@bixense.com>2021-02-23 09:00:23 (GMT)
committerGitHub <noreply@github.com>2021-02-23 09:00:23 (GMT)
commitec8de9c247dde02c447cff23cb826a7524110e79 (patch)
treee733ce0faa3ec06bcebcaaca4814e77aa5719e3f /src
parentc83f00c8a641901339a9d04ff00e2a1212b49ab9 (diff)
parent00459e2b44fe1ee1a508f562bdf05acbea99c181 (diff)
downloadNinja-ec8de9c247dde02c447cff23cb826a7524110e79.zip
Ninja-ec8de9c247dde02c447cff23cb826a7524110e79.tar.gz
Ninja-ec8de9c247dde02c447cff23cb826a7524110e79.tar.bz2
Merge pull request #1915 from jhasse/windows-utf8
Use UTF-8 on Windows 10 Version 1903, fix #1195
Diffstat (limited to 'src')
-rw-r--r--src/line_printer.cc35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/line_printer.cc b/src/line_printer.cc
index 68c58ad..3138960 100644
--- a/src/line_printer.cc
+++ b/src/line_printer.cc
@@ -87,22 +87,27 @@ void LinePrinter::Print(string to_print, LineType type) {
GetConsoleScreenBufferInfo(console_, &csbi);
to_print = ElideMiddle(to_print, static_cast<size_t>(csbi.dwSize.X));
- // We don't want to have the cursor spamming back and forth, so instead of
- // printf use WriteConsoleOutput which updates the contents of the buffer,
- // but doesn't move the cursor position.
- COORD buf_size = { csbi.dwSize.X, 1 };
- COORD zero_zero = { 0, 0 };
- SMALL_RECT target = {
- csbi.dwCursorPosition.X, csbi.dwCursorPosition.Y,
- static_cast<SHORT>(csbi.dwCursorPosition.X + csbi.dwSize.X - 1),
- csbi.dwCursorPosition.Y
- };
- vector<CHAR_INFO> char_data(csbi.dwSize.X);
- for (size_t i = 0; i < static_cast<size_t>(csbi.dwSize.X); ++i) {
- char_data[i].Char.AsciiChar = i < to_print.size() ? to_print[i] : ' ';
- char_data[i].Attributes = csbi.wAttributes;
+ if (supports_color_) { // this means ENABLE_VIRTUAL_TERMINAL_PROCESSING
+ // succeeded
+ printf("%s\x1B[K", to_print.c_str()); // Clear to end of line.
+ fflush(stdout);
+ } else {
+ // We don't want to have the cursor spamming back and forth, so instead of
+ // printf use WriteConsoleOutput which updates the contents of the buffer,
+ // but doesn't move the cursor position.
+ COORD buf_size = { csbi.dwSize.X, 1 };
+ COORD zero_zero = { 0, 0 };
+ SMALL_RECT target = { csbi.dwCursorPosition.X, csbi.dwCursorPosition.Y,
+ static_cast<SHORT>(csbi.dwCursorPosition.X +
+ csbi.dwSize.X - 1),
+ csbi.dwCursorPosition.Y };
+ vector<CHAR_INFO> char_data(csbi.dwSize.X);
+ for (size_t i = 0; i < static_cast<size_t>(csbi.dwSize.X); ++i) {
+ char_data[i].Char.AsciiChar = i < to_print.size() ? to_print[i] : ' ';
+ char_data[i].Attributes = csbi.wAttributes;
+ }
+ WriteConsoleOutput(console_, &char_data[0], buf_size, zero_zero, &target);
}
- WriteConsoleOutput(console_, &char_data[0], buf_size, zero_zero, &target);
#else
// Limit output to width of the terminal if provided so we don't cause
// line-wrapping.