Ninja
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
LinePrinter Struct Reference

Prints lines of text, possibly overprinting previously printed lines if the terminal supports it. More...

#include <line_printer.h>

Public Types

enum  LineType { FULL, ELIDE }
 

Public Member Functions

bool is_smart_terminal () const
 
 LinePrinter ()
 
void Print (string to_print, LineType type)
 Overprints the current line. More...
 
void PrintOnNewLine (const string &to_print)
 Prints a string on a new line, not overprinting previous output. More...
 
void set_smart_terminal (bool smart)
 
void SetConsoleLocked (bool locked)
 Lock or unlock the console. More...
 

Private Member Functions

void PrintOrBuffer (const char *data, size_t size)
 Print the given data to the console, or buffer it if it is locked. More...
 

Private Attributes

bool console_locked_
 Whether console is locked. More...
 
bool have_blank_line_
 Whether the caret is at the beginning of a blank line. More...
 
string line_buffer_
 Buffered current line while console is locked. More...
 
LineType line_type_
 Buffered line type while console is locked. More...
 
string output_buffer_
 Buffered console output while console is locked. More...
 
bool smart_terminal_
 Whether we can do fancy terminal control codes. More...
 

Detailed Description

Prints lines of text, possibly overprinting previously printed lines if the terminal supports it.

Definition at line 24 of file line_printer.h.

Member Enumeration Documentation

Enumerator
FULL 
ELIDE 

Definition at line 30 of file line_printer.h.

Constructor & Destructor Documentation

LinePrinter::LinePrinter ( )

Definition at line 29 of file line_printer.cc.

References smart_terminal_.

Member Function Documentation

bool LinePrinter::is_smart_terminal ( ) const
inline

Definition at line 27 of file line_printer.h.

Referenced by BuildStatus::BuildEdgeFinished().

void LinePrinter::Print ( string  to_print,
LineType  type 
)

Overprints the current line.

If type is ELIDE, elides to_print to fit on one line.

Definition at line 45 of file line_printer.cc.

References console_locked_, ELIDE, ElideMiddle(), have_blank_line_, line_buffer_, line_type_, and smart_terminal_.

Referenced by LaconicPrinter::OnTestStart(), BuildStatus::PrintStatus(), and SetConsoleLocked().

void LinePrinter::PrintOnNewLine ( const string &  to_print)
void LinePrinter::PrintOrBuffer ( const char *  data,
size_t  size 
)
private

Print the given data to the console, or buffer it if it is locked.

Definition at line 110 of file line_printer.cc.

References console_locked_, and output_buffer_.

Referenced by PrintOnNewLine().

void LinePrinter::set_smart_terminal ( bool  smart)
inline

Definition at line 28 of file line_printer.h.

Referenced by BuildStatus::BuildStatus().

void LinePrinter::SetConsoleLocked ( bool  locked)

Lock or unlock the console.

Any output sent to the LinePrinter while the console is locked will not be printed until it is unlocked.

Definition at line 135 of file line_printer.cc.

References console_locked_, line_buffer_, line_type_, output_buffer_, Print(), and PrintOnNewLine().

Referenced by BuildStatus::BuildEdgeFinished(), BuildStatus::BuildEdgeStarted(), and BuildStatus::BuildFinished().

Member Data Documentation

bool LinePrinter::console_locked_
private

Whether console is locked.

Definition at line 53 of file line_printer.h.

Referenced by Print(), PrintOnNewLine(), PrintOrBuffer(), and SetConsoleLocked().

bool LinePrinter::have_blank_line_
private

Whether the caret is at the beginning of a blank line.

Definition at line 50 of file line_printer.h.

Referenced by Print(), and PrintOnNewLine().

string LinePrinter::line_buffer_
private

Buffered current line while console is locked.

Definition at line 56 of file line_printer.h.

Referenced by Print(), PrintOnNewLine(), and SetConsoleLocked().

LineType LinePrinter::line_type_
private

Buffered line type while console is locked.

Definition at line 59 of file line_printer.h.

Referenced by Print(), and SetConsoleLocked().

string LinePrinter::output_buffer_
private

Buffered console output while console is locked.

Definition at line 62 of file line_printer.h.

Referenced by PrintOnNewLine(), PrintOrBuffer(), and SetConsoleLocked().

bool LinePrinter::smart_terminal_
private

Whether we can do fancy terminal control codes.

Definition at line 47 of file line_printer.h.

Referenced by LinePrinter(), and Print().


The documentation for this struct was generated from the following files: