move printing of new lines into LinePrinter.
authorNico Weber <nicolasweber@gmx.de>
Tue, 9 Apr 2013 04:14:29 +0000 (21:14 -0700)
committerNico Weber <nicolasweber@gmx.de>
Tue, 9 Apr 2013 04:14:29 +0000 (21:14 -0700)
src/build.cc
src/line_printer.cc
src/line_printer.h

index efa4559..4ed586f 100644 (file)
@@ -115,19 +115,11 @@ void BuildStatus::BuildEdgeFinished(Edge* edge,
   if (printer_.smart_terminal_)
     PrintStatus(edge);
 
-  if (!success) {
-    if (!printer_.have_blank_line_)
-      printf("\n");
-
-    // Print the command that is spewing before printing its output.
-    printf("FAILED: %s\n", edge->EvaluateCommand().c_str());
-    printer_.have_blank_line_ = true;
-  }
+  // Print the command that is spewing before printing its output.
+  if (!success)
+    printer_.PrintOnNewLine("FAILED: " + edge->EvaluateCommand() + "\n");
 
   if (!output.empty()) {
-    if (!printer_.have_blank_line_)
-      printf("\n");
-
     // ninja sets stdout and stderr of subprocesses to a pipe, to be able to
     // check if the output is empty. Some compilers, e.g. clang, check
     // isatty(stderr) to decide if they should print colored output.
@@ -145,18 +137,12 @@ void BuildStatus::BuildEdgeFinished(Edge* edge,
       final_output = StripAnsiEscapeCodes(output);
     else
       final_output = output;
-
-    if (!final_output.empty()) {
-      printf("%s", final_output.c_str());
-      if (*final_output.rbegin() == '\n')
-        printer_.have_blank_line_ = true;
-    }
+    printer_.PrintOnNewLine(final_output);
   }
 }
 
 void BuildStatus::BuildFinished() {
-  if (printer_.smart_terminal_ && !printer_.have_blank_line_)
-    printf("\n");
+  printer_.PrintOnNewLine("");
 }
 
 string BuildStatus::FormatProgressStatus(
index 54f0a5b..bfa737e 100644 (file)
@@ -96,3 +96,10 @@ void LinePrinter::Print(std::string to_print, LineType type) {
     printf("%s\n", to_print.c_str());
   }
 }
+
+void LinePrinter::PrintOnNewLine(const string& to_print) {
+  if (!have_blank_line_)
+    printf("\n");
+  printf("%s", to_print.c_str());
+  have_blank_line_ = to_print.empty() || *to_print.rbegin() == '\n';
+}
index 6002667..b3cb163 100644 (file)
@@ -27,6 +27,8 @@ class LinePrinter {
   };
   void Print(std::string to_print, LineType type);
 
+  void PrintOnNewLine(const std::string& to_print);
+
  //private:
   /// Whether we can do fancy terminal control codes.
   bool smart_terminal_;