Ninja
line_printer.h
Go to the documentation of this file.
00001 // Copyright 2013 Google Inc. All Rights Reserved.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //     http://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
00014 
00015 #ifndef NINJA_LINE_PRINTER_H_
00016 #define NINJA_LINE_PRINTER_H_
00017 
00018 #include <string>
00019 using namespace std;
00020 
00021 /// Prints lines of text, possibly overprinting previously printed lines
00022 /// if the terminal supports it.
00023 struct LinePrinter {
00024   LinePrinter();
00025 
00026   bool is_smart_terminal() const { return smart_terminal_; }
00027   void set_smart_terminal(bool smart) { smart_terminal_ = smart; }
00028 
00029   enum LineType {
00030     FULL,
00031     ELIDE
00032   };
00033   /// Overprints the current line. If type is ELIDE, elides to_print to fit on
00034   /// one line.
00035   void Print(string to_print, LineType type);
00036 
00037   /// Prints a string on a new line, not overprinting previous output.
00038   void PrintOnNewLine(const string& to_print);
00039 
00040  private:
00041   /// Whether we can do fancy terminal control codes.
00042   bool smart_terminal_;
00043 
00044   /// Whether the caret is at the beginning of a blank line.
00045   bool have_blank_line_;
00046 
00047 #ifdef _WIN32
00048   void* console_;
00049 #endif
00050 };
00051 
00052 #endif  // NINJA_LINE_PRINTER_H_