summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2011-03-02 20:22:07 (GMT)
committerEvan Martin <martine@danga.com>2011-03-02 20:22:07 (GMT)
commitf375fe451611f5eda01c8f157cb55db3f3802a15 (patch)
tree0e59b4add53b00b90a5365c7c931b1e3555bbb1d /src
parent642bd20865e2369b075d70fb8356cb5b099a54ab (diff)
downloadNinja-f375fe451611f5eda01c8f157cb55db3f3802a15.zip
Ninja-f375fe451611f5eda01c8f157cb55db3f3802a15.tar.gz
Ninja-f375fe451611f5eda01c8f157cb55db3f3802a15.tar.bz2
limit output width to prevent line-wrapping
Diffstat (limited to 'src')
-rw-r--r--src/build.cc12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/build.cc b/src/build.cc
index 874542a..09c362a 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -15,7 +15,9 @@
#include "build.h"
#include <stdio.h>
+#include <sys/ioctl.h>
#include <sys/time.h>
+#include <sys/termios.h>
#include "build_log.h"
#include "graph.h"
@@ -104,6 +106,16 @@ void BuildStatus::PrintStatus(Edge* edge) {
to_print = edge->EvaluateCommand();
if (smart_terminal_) {
+ // Limit output to width of the terminal so we don't cause line-wrapping.
+ winsize size;
+ if (ioctl(0, TIOCGWINSZ, &size) == 0) {
+ const int kMargin = 15; // Space for [xxx/yyy] and "...".
+ if (to_print.size() + kMargin > size.ws_col) {
+ int substr = to_print.size() + kMargin - size.ws_col;
+ to_print = "..." + to_print.substr(substr);
+ }
+ }
+
printf("\r[%d/%d] %s\e[K", finished_edges_, total_edges_,
to_print.c_str());
fflush(stdout);