SST 15.0
Structural Simulation Toolkit
SST::Util::SmartTextFormatter Class Reference

Class to format text for console output. More...

#include <smartTextFormatter.h>

Public Member Functions

 SmartTextFormatter (const std::vector< int > &tabStops, int repeat=0)
 Constructor for SmartTextFormatter.
 
void clear ()
 Clear the formatter.
 
void setTabStops (const std::vector< int > &stops, int repeat=0)
 Sets the tabstops for the formatter.
 
void append (const std::string &input)
 Append a string to the formatter.
 
std::string str ()
 Return the current output of the formatter.
 

Detailed Description

Class to format text for console output.

It will wrap lines at word boundaries based on the terminal width. It can also handle tab and indent using various escape sequences described in the append() function.

NOTE: The API is in flux and won't be final until the SST 15 release.

Constructor & Destructor Documentation

◆ SmartTextFormatter()

SST::Util::SmartTextFormatter::SmartTextFormatter ( const std::vector< int > & tabStops,
int repeat = 0 )

Constructor for SmartTextFormatter.

Parameters
tabStopsVector of column indices that will serve as tab stops
repeatIf set to value greater than zero, the last "repeat" tab stops will repeat the input pattern through the whole width of the terminal (i.e., the differences from the tab stop before will be used to generate new tab stops until the end of the line).

References setTabStops().

Member Function Documentation

◆ append()

void SST::Util::SmartTextFormatter::append ( const std::string & input)

Append a string to the formatter.

The formatter will add the string to the output (which can be retrieved through the str() function) and add newline characters between words to wrap text at the terminal boundary. The width of the terminal is determined automatically and will default to 80 if the width is indeterminate (for example, the output is piped to a file).

The input string can also include the following escape sequences, which will behave as described:

\t - Will advance the output to the next tab stop. If the current line is already beyond the current tab stop, the formatter will just insert a newline

\v - Will push a new indent at the current column of the output line to the indent stack

\v\v - Will pop the most recent indent from the stack


- Normal new line character. In addition to adding a new line, it will also clear the indent stack

\r - Will insert a new line character, but advance the output to the current indent position

Parameters
inputInput string to add to the formatted output

◆ setTabStops()

void SST::Util::SmartTextFormatter::setTabStops ( const std::vector< int > & stops,
int repeat = 0 )

Sets the tabstops for the formatter.

This can be done at anytime and will take immediate effect.

Parameters
stopsVector of column indexes that will serve as tab stops
repeatIf set to value greater than zero, the last "repeat" tab stops will repeat the input pattern through the whole width of the terminal (i.e., the differences from the tab stop before will be used to generate new tab stops until the end of the line).

Referenced by SmartTextFormatter().

◆ str()

std::string SST::Util::SmartTextFormatter::str ( )

Return the current output of the formatter.

Any trailing spaces will be left off.


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