From a95b0819703aefc6a4f74004d6639f2cebd1e5d2 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Mon, 8 Apr 2013 21:19:27 -0700 Subject: Make LinePrinter members private, add comments. --- src/build.cc | 6 +++--- src/line_printer.h | 11 ++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/build.cc b/src/build.cc index 4ed586f..340a3d9 100644 --- a/src/build.cc +++ b/src/build.cc @@ -77,7 +77,7 @@ BuildStatus::BuildStatus(const BuildConfig& config) // Don't do anything fancy in verbose mode. if (config_.verbosity != BuildConfig::NORMAL) - printer_.smart_terminal_ = false; + printer_.set_smart_terminal(false); progress_status_format_ = getenv("NINJA_STATUS"); if (!progress_status_format_) @@ -112,7 +112,7 @@ void BuildStatus::BuildEdgeFinished(Edge* edge, if (config_.verbosity == BuildConfig::QUIET) return; - if (printer_.smart_terminal_) + if (printer_.is_smart_terminal()) PrintStatus(edge); // Print the command that is spewing before printing its output. @@ -133,7 +133,7 @@ void BuildStatus::BuildEdgeFinished(Edge* edge, // thousands of parallel compile commands.) // TODO: There should be a flag to disable escape code stripping. string final_output; - if (!printer_.smart_terminal_) + if (!printer_.is_smart_terminal()) final_output = StripAnsiEscapeCodes(output); else final_output = output; diff --git a/src/line_printer.h b/src/line_printer.h index b3cb163..78510ea 100644 --- a/src/line_printer.h +++ b/src/line_printer.h @@ -17,22 +17,31 @@ #include +/// Prints lines of text, possibly overprinting previously printed lines +/// if the terminal supports it. class LinePrinter { public: LinePrinter(); + bool is_smart_terminal() const { return smart_terminal_; } + void set_smart_terminal(bool smart) { smart_terminal_ = smart; } + enum LineType { FULL, SHORT }; + /// Overprints the current line. If type is SHORT, elides to_print to fit on + /// one line. void Print(std::string to_print, LineType type); + /// Prints a string on a new line, not overprinting previous output. void PrintOnNewLine(const std::string& to_print); - //private: + private: /// Whether we can do fancy terminal control codes. bool smart_terminal_; + /// Whether the caret is at the beginning of a blank line. bool have_blank_line_; }; -- cgit v0.12