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...
 
bool supports_color () const
 

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...
 
bool supports_color_
 Whether we can use ISO 6429 (ANSI) color sequences. 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

◆ LineType

Enumerator
FULL 
ELIDE 

Definition at line 32 of file line_printer.h.

Constructor & Destructor Documentation

◆ LinePrinter()

LinePrinter::LinePrinter ( )

Definition at line 33 of file line_printer.cc.

References smart_terminal_, and supports_color_.

Member Function Documentation

◆ is_smart_terminal()

bool LinePrinter::is_smart_terminal ( ) const
inline

Definition at line 27 of file line_printer.h.

Referenced by BuildStatus::BuildEdgeStarted().

◆ Print()

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 63 of file line_printer.cc.

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

Referenced by main(), BuildStatus::PrintStatus(), and SetConsoleLocked().

◆ PrintOnNewLine()

void LinePrinter::PrintOnNewLine ( const string &  to_print)

Prints a string on a new line, not overprinting previous output.

Definition at line 126 of file line_printer.cc.

References console_locked_, have_blank_line_, line_buffer_, output_buffer_, and PrintOrBuffer().

Referenced by BuildStatus::BuildEdgeFinished(), BuildStatus::BuildFinished(), testing::Test::Check(), main(), and SetConsoleLocked().

◆ PrintOrBuffer()

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 116 of file line_printer.cc.

References console_locked_, and output_buffer_.

Referenced by PrintOnNewLine().

◆ set_smart_terminal()

void LinePrinter::set_smart_terminal ( bool  smart)
inline

Definition at line 28 of file line_printer.h.

Referenced by BuildStatus::BuildStatus().

◆ SetConsoleLocked()

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 141 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().

◆ supports_color()

bool LinePrinter::supports_color ( ) const
inline

Definition at line 30 of file line_printer.h.

Referenced by BuildStatus::BuildEdgeFinished().

Member Data Documentation

◆ console_locked_

bool LinePrinter::console_locked_
private

Whether console is locked.

Definition at line 58 of file line_printer.h.

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

◆ have_blank_line_

bool LinePrinter::have_blank_line_
private

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

Definition at line 55 of file line_printer.h.

Referenced by Print(), and PrintOnNewLine().

◆ line_buffer_

string LinePrinter::line_buffer_
private

Buffered current line while console is locked.

Definition at line 61 of file line_printer.h.

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

◆ line_type_

LineType LinePrinter::line_type_
private

Buffered line type while console is locked.

Definition at line 64 of file line_printer.h.

Referenced by Print(), and SetConsoleLocked().

◆ output_buffer_

string LinePrinter::output_buffer_
private

Buffered console output while console is locked.

Definition at line 67 of file line_printer.h.

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

◆ smart_terminal_

bool LinePrinter::smart_terminal_
private

Whether we can do fancy terminal control codes.

Definition at line 49 of file line_printer.h.

Referenced by LinePrinter(), and Print().

◆ supports_color_

bool LinePrinter::supports_color_
private

Whether we can use ISO 6429 (ANSI) color sequences.

Definition at line 52 of file line_printer.h.

Referenced by LinePrinter().


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