SST 15.0
Structural Simulation Toolkit
|
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. | |
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.
SST::Util::SmartTextFormatter::SmartTextFormatter | ( | const std::vector< int > & | tabStops, |
int | repeat = 0 ) |
Constructor for SmartTextFormatter.
tabStops | Vector of column indices that will serve as tab stops |
repeat | If 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().
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
input | Input string to add to the formatted output |
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.
stops | Vector of column indexes that will serve as tab stops |
repeat | If 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().
std::string SST::Util::SmartTextFormatter::str | ( | ) |
Return the current output of the formatter.
Any trailing spaces will be left off.