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 (std::string to_print, LineType type)
 Overprints the current line. More...
 
void PrintOnNewLine (const std::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...
 
std::string line_buffer_
 Buffered current line while console is locked. More...
 
LineType line_type_
 Buffered line type while console is locked. More...
 
std::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 23 of file line_printer.h.

Member Enumeration Documentation

◆ LineType

Enumerator
FULL 
ELIDE 

Definition at line 31 of file line_printer.h.

Constructor & Destructor Documentation

◆ LinePrinter()

LinePrinter::LinePrinter ( )

Definition at line 36 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 26 of file line_printer.h.

References smart_terminal_.

Referenced by StatusPrinter::BuildEdgeStarted().

◆ Print()

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

Overprints the current line.

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

Definition at line 67 of file line_printer.cc.

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

Referenced by StatusPrinter::PrintStatus(), and SetConsoleLocked().

◆ PrintOnNewLine()

void LinePrinter::PrintOnNewLine ( const std::string &  to_print)

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

Definition at line 136 of file line_printer.cc.

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

Referenced by StatusPrinter::BuildEdgeFinished(), StatusPrinter::BuildFinished(), StatusPrinter::PrintStatus(), 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 126 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 27 of file line_printer.h.

References smart_terminal_.

Referenced by StatusPrinter::StatusPrinter().

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

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

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

◆ supports_color()

bool LinePrinter::supports_color ( ) const
inline

Definition at line 29 of file line_printer.h.

References supports_color_.

Referenced by StatusPrinter::BuildEdgeFinished().

Member Data Documentation

◆ console_locked_

bool LinePrinter::console_locked_
private

Whether console is locked.

Definition at line 57 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 54 of file line_printer.h.

Referenced by Print(), and PrintOnNewLine().

◆ line_buffer_

std::string LinePrinter::line_buffer_
private

Buffered current line while console is locked.

Definition at line 60 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 63 of file line_printer.h.

Referenced by Print(), and SetConsoleLocked().

◆ output_buffer_

std::string LinePrinter::output_buffer_
private

Buffered console output while console is locked.

Definition at line 66 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 48 of file line_printer.h.

Referenced by is_smart_terminal(), LinePrinter(), Print(), and set_smart_terminal().

◆ supports_color_

bool LinePrinter::supports_color_
private

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

Definition at line 51 of file line_printer.h.

Referenced by LinePrinter(), Print(), and supports_color().


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