From f872a912c57879767a7715094790aa4380badce2 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Mon, 8 Apr 2013 21:14:29 -0700 Subject: move printing of new lines into LinePrinter. --- src/build.cc | 24 +++++------------------- src/line_printer.cc | 7 +++++++ src/line_printer.h | 2 ++ 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/build.cc b/src/build.cc index efa4559..4ed586f 100644 --- a/src/build.cc +++ b/src/build.cc @@ -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( diff --git a/src/line_printer.cc b/src/line_printer.cc index 54f0a5b..bfa737e 100644 --- a/src/line_printer.cc +++ b/src/line_printer.cc @@ -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'; +} diff --git a/src/line_printer.h b/src/line_printer.h index 6002667..b3cb163 100644 --- a/src/line_printer.h +++ b/src/line_printer.h @@ -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_; -- cgit v0.12