OpenMS
ConsoleUtils Class Reference

#include <OpenMS/APPLICATIONS/ConsoleUtils.h>

Collaboration diagram for ConsoleUtils:
[legend]

Public Member Functions

 ConsoleUtils (const ConsoleUtils &)=delete
 Copy C'tor (deleted) More...
 
void operator= (ConsoleUtils const &)=delete
 Assignment operator (deleted) More...
 
int getConsoleWidth () const
 width of the console (or INTMAX on internal error) More...
 

Static Public Member Functions

static const ConsoleUtilsgetInstance ()
 returns the singleton – the only instanciation of this class More...
 
static StringList breakStringList (const String &input, const Size indentation, const Size max_lines, const Size first_line_prefill=0)
 
static String breakString (const String &input, const Size indentation, const Size max_lines, const Size first_line_prefill=0)
 same as breakStringList(), but concatenates the result using '
' for convenience More...
 

Private Member Functions

 ConsoleUtils ()
 C'tor (private) – use ConsoleUtils::getInstance() More...
 
int readConsoleSize_ ()
 read console settings for output shaping More...
 
StringList breakString_ (const String &input, const Size indentation, const Size max_lines, Size first_line_prefill) const
 returns a console friendly version of input More...
 

Private Attributes

int console_width_ = std::numeric_limits<int>::max()
 width of console we are currently in (if not determinable, set to INTMAX, i.e. not breaks) More...
 

Friends

struct ConsoleWidthTest
 allows us to set console_width to a fixed value for testing More...
 

Detailed Description

Determines the width of the console automatically.

To manually force a certain width set the environment variable 'COLUMNS' to a desired value.

Constructor & Destructor Documentation

◆ ConsoleUtils() [1/2]

ConsoleUtils ( )
private

C'tor (private) – use ConsoleUtils::getInstance()

◆ ConsoleUtils() [2/2]

ConsoleUtils ( const ConsoleUtils )
delete

Copy C'tor (deleted)

Member Function Documentation

◆ breakString()

static String breakString ( const String input,
const Size  indentation,
const Size  max_lines,
const Size  first_line_prefill = 0 
)
static

same as breakStringList(), but concatenates the result using '
' for convenience

◆ breakString_()

StringList breakString_ ( const String input,
const Size  indentation,
const Size  max_lines,
Size  first_line_prefill 
) const
private

returns a console friendly version of input

◆ breakStringList()

static StringList breakStringList ( const String input,
const Size  indentation,
const Size  max_lines,
const Size  first_line_prefill = 0 
)
static

Make a string console-friendly by breaking it into multiple lines according to the console width. The 'indentation' gives the number of spaces which is prepended beginning at the second (!) line, so one gets a left aligned block which has some space to the left. An indentation of 0 results in the native console's default behaviour: just break at the end of its width and start a new line. max_lines gives the upper limit of lines returned after breaking is finished. Excess lines are removed and replaced by '...', BUT the last line will be preserved.

Parameters
inputString to be split
indentationNumber of spaces to use for lines 2 until last line (should not exceed the console width)
max_linesLimit of output lines (all others are removed)
first_line_prefillAssume this many chars were already written in the current line of the console (should not exceed the console width)

◆ getConsoleWidth()

int getConsoleWidth ( ) const
inline

width of the console (or INTMAX on internal error)

◆ getInstance()

static const ConsoleUtils& getInstance ( )
static

returns the singleton – the only instanciation of this class

◆ operator=()

void operator= ( ConsoleUtils const &  )
delete

Assignment operator (deleted)

◆ readConsoleSize_()

int readConsoleSize_ ( )
private

read console settings for output shaping

Friends And Related Function Documentation

◆ ConsoleWidthTest

friend struct ConsoleWidthTest
friend

allows us to set console_width to a fixed value for testing

Member Data Documentation

◆ console_width_

int console_width_ = std::numeric_limits<int>::max()
private

width of console we are currently in (if not determinable, set to INTMAX, i.e. not breaks)