diff options
author | Nico Weber <thakis@chromium.org> | 2014-12-02 05:05:23 (GMT) |
---|---|---|
committer | Nico Weber <thakis@chromium.org> | 2014-12-02 05:10:55 (GMT) |
commit | 97a4fe200a60718ac0a03a23999462834dd9d3b4 (patch) | |
tree | df4c7408a9e0d28f5eeb51b1a6c8951650860ee5 /src/line_printer.cc | |
parent | b532cab080bbde2068ab49aba814c7176111681f (diff) | |
download | Ninja-97a4fe200a60718ac0a03a23999462834dd9d3b4.zip Ninja-97a4fe200a60718ac0a03a23999462834dd9d3b4.tar.gz Ninja-97a4fe200a60718ac0a03a23999462834dd9d3b4.tar.bz2 |
win: Let the "Pause" key or Ctrl-S pause output.
In cmd.exe, hitting the "Pause" key or Ctrl-S will pause
programs until a key is pressed. This is apparently
implemented when stdout is writing to, so use printf
instead of Console functions to reset the cursor to
the start of the line. Also happens to simplify the code.
(This already worked in -v mode since that already
prints using printf.)
Based on a patch from gmisocpp@gmail.com!
Diffstat (limited to 'src/line_printer.cc')
-rw-r--r-- | src/line_printer.cc | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/line_printer.cc b/src/line_printer.cc index 813f63e..8e7b8f1 100644 --- a/src/line_printer.cc +++ b/src/line_printer.cc @@ -50,22 +50,17 @@ void LinePrinter::Print(string to_print, LineType type) { return; } -#ifdef _WIN32 - CONSOLE_SCREEN_BUFFER_INFO csbi; - GetConsoleScreenBufferInfo(console_, &csbi); -#endif - if (smart_terminal_) { -#ifndef _WIN32 printf("\r"); // Print over previous line, if any. -#else - csbi.dwCursorPosition.X = 0; - SetConsoleCursorPosition(console_, csbi.dwCursorPosition); -#endif + // On Windows, calling a C library function writing to stdout also handles + // pausing the executable when the "Pause" key or Ctrl-S is pressed. } if (smart_terminal_ && type == ELIDE) { #ifdef _WIN32 + CONSOLE_SCREEN_BUFFER_INFO csbi; + GetConsoleScreenBufferInfo(console_, &csbi); + // Don't use the full width or console will move to next line. size_t width = static_cast<size_t>(csbi.dwSize.X) - 1; to_print = ElideMiddle(to_print, width); |