Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
Classes | Typedefs | Enumerations | Functions
terminal Namespace Reference

Classes

struct  RGBColor
 
class  TerminalStyle
 
struct  toggle
 A simple yes/no toggle that parses from a string. More...
 

Typedefs

using BGColor = std::variant< BackgroundColor, RGBColor >
 
using FGColor = std::variant< ForegroundColor, RGBColor >
 

Enumerations

enum class  BackgroundColor {
  Default = 49 , Black = 40 , Red = 41 , Green = 42 ,
  Yellow = 43 , Blue = 44 , Magenta = 45 , Cyan = 46 ,
  LightGray = 47 , DarkGray = 100 , LightRed = 101 , LightGreen = 102 ,
  LightYellow = 103 , LightBlue = 104 , LightMagenta = 105 , LightCyan = 106 ,
  White = 107
}
 
enum class  ColorAttribute : unsigned { None = 0 , Bold = 1 << 0 , Dim = 1 << 1 , Underline = 1 << 2 }
 
enum class  ForegroundColor {
  Default = 39 , Black = 30 , Red = 31 , Green = 32 ,
  Yellow = 33 , Blue = 34 , Magenta = 35 , Cyan = 36 ,
  LightGray = 37 , DarkGray = 90 , LightRed = 91 , LightGreen = 92 ,
  LightYellow = 93 , LightBlue = 94 , LightMagenta = 95 , LightCyan = 96 ,
  White = 97
}
 

Functions

std::string cmdline (int argc, char **argv)
 
std::string color_if (std::string_view s, bool b, const TerminalStyle &ts)
 
std::string color_text (std::string_view s, const TerminalStyle &ts)
 
int columns ()
 Return the output terminal column count.
 
int columns (std::FILE *stream)
 Return the terminal column count associated with a C stream.
 
bool env_exists (std::string const &str)
 
std::string expand_environment (std::string const &s)
 
template<typename T , typename U >
T getenv_or_default (const std::string &var, const U &default_value)
 
char const * getenv_or_default (std::string const &str, char const *Default)
 
bool is_a_terminal (std::FILE *stream)
 Test whether a C output stream refers to a terminal.
 
bool no_color_requested ()
 Return whether NO_COLOR requests suppressing default ANSI color output.
 
constexpr ColorAttribute operator| (ColorAttribute lhs, ColorAttribute rhs)
 
constexpr ColorAttribute & operator|= (ColorAttribute &lhs, ColorAttribute rhs)
 
std::optional< BackgroundColor > parseBackgroundColor (const std::string &token)
 
std::optional< ColorAttribute > parseColorAttribute (const std::string &token)
 
std::optional< ForegroundColor > parseForegroundColor (const std::string &token)
 
std::optional< RGBColor > parseHexColor (const std::string &token)
 
std::optional< RGBColor > parseRGBColor (const std::string &token)
 
TerminalStyle parseTerminalStyle (const std::string &styleStr)
 
std::string quote_shell (std::string_view s)
 
int rows ()
 Return the output terminal row count.
 
int rows (std::FILE *stream)
 Return the terminal row count associated with a C stream.
 
std::pair< int, int > size ()
 Return the output terminal size as (rows, columns).
 
std::pair< int, int > size (std::FILE *stream)
 Return the terminal size associated with a C stream.
 
std::vector< std::string > split_string (const std::string &s, char delimiter)
 
std::vector< std::string > splitString (const std::string &s, char delim)
 
std::vector< std::string > splitTopLevel (const std::string &s, char delim=',')
 
std::string to_lower (std::string s)
 
std::string trim (const std::string &s)
 

Typedef Documentation

◆ BGColor

using terminal::BGColor = typedef std::variant<BackgroundColor, RGBColor>

◆ FGColor

using terminal::FGColor = typedef std::variant<ForegroundColor, RGBColor>

Enumeration Type Documentation

◆ BackgroundColor

enum class terminal::BackgroundColor
strong
Enumerator
Default 
Black 
Red 
Green 
Yellow 
Blue 
Magenta 
Cyan 
LightGray 
DarkGray 
LightRed 
LightGreen 
LightYellow 
LightBlue 
LightMagenta 
LightCyan 
White 

◆ ColorAttribute

enum class terminal::ColorAttribute : unsigned
strong
Enumerator
None 
Bold 
Dim 
Underline 

◆ ForegroundColor

enum class terminal::ForegroundColor
strong
Enumerator
Default 
Black 
Red 
Green 
Yellow 
Blue 
Magenta 
Cyan 
LightGray 
DarkGray 
LightRed 
LightGreen 
LightYellow 
LightBlue 
LightMagenta 
LightCyan 
White 

Function Documentation

◆ cmdline()

std::string terminal::cmdline ( int  argc,
char **  argv 
)
inline

◆ color_if()

std::string terminal::color_if ( std::string_view  s,
bool  b,
const TerminalStyle &  ts 
)
inline

◆ color_text()

std::string terminal::color_text ( std::string_view  s,
const TerminalStyle &  ts 
)
inline

◆ columns() [1/2]

int terminal::columns ( )

Return the output terminal column count.

Returns
COLUMNS, the detected terminal width, or UNI20_FALLBACK_TERMINAL_WIDTH.

◆ columns() [2/2]

int terminal::columns ( std::FILE *  stream)

Return the terminal column count associated with a C stream.

Parameters
streamStream whose file descriptor should be queried.
Returns
COLUMNS, the detected terminal width, or UNI20_FALLBACK_TERMINAL_WIDTH.

◆ env_exists()

bool terminal::env_exists ( std::string const &  str)
inline

◆ expand_environment()

std::string terminal::expand_environment ( std::string const &  s)

◆ getenv_or_default() [1/2]

template<typename T , typename U >
T terminal::getenv_or_default ( const std::string &  var,
const U &  default_value 
)

◆ getenv_or_default() [2/2]

char const * terminal::getenv_or_default ( std::string const &  str,
char const *  Default 
)
inline

◆ is_a_terminal()

bool terminal::is_a_terminal ( std::FILE *  stream)

Test whether a C output stream refers to a terminal.

Parameters
streamStream to inspect; a null stream is not a terminal.
Returns
True when the stream has a valid terminal file descriptor.

◆ no_color_requested()

bool terminal::no_color_requested ( )
inline

Return whether NO_COLOR requests suppressing default ANSI color output.

Returns
True when NO_COLOR is present and not empty.

◆ operator|()

constexpr ColorAttribute terminal::operator| ( ColorAttribute  lhs,
ColorAttribute  rhs 
)
constexpr

◆ operator|=()

constexpr ColorAttribute & terminal::operator|= ( ColorAttribute &  lhs,
ColorAttribute  rhs 
)
constexpr

◆ parseBackgroundColor()

std::optional< BackgroundColor > terminal::parseBackgroundColor ( const std::string &  token)

◆ parseColorAttribute()

std::optional< ColorAttribute > terminal::parseColorAttribute ( const std::string &  token)

◆ parseForegroundColor()

std::optional< ForegroundColor > terminal::parseForegroundColor ( const std::string &  token)

◆ parseHexColor()

std::optional< RGBColor > terminal::parseHexColor ( const std::string &  token)

◆ parseRGBColor()

std::optional< RGBColor > terminal::parseRGBColor ( const std::string &  token)

◆ parseTerminalStyle()

TerminalStyle terminal::parseTerminalStyle ( const std::string &  styleStr)

◆ quote_shell()

std::string terminal::quote_shell ( std::string_view  s)
inline

◆ rows() [1/2]

int terminal::rows ( )

Return the output terminal row count.

Returns
LINES, the detected terminal height, or the built-in row fallback.

◆ rows() [2/2]

int terminal::rows ( std::FILE *  stream)

Return the terminal row count associated with a C stream.

Parameters
streamStream whose file descriptor should be queried.
Returns
LINES, the detected terminal height, or the built-in row fallback.

◆ size() [1/2]

std::pair< int, int > terminal::size ( )

Return the output terminal size as (rows, columns).

Returns
Positive row and column counts, using configured fallbacks when detection is unavailable.

◆ size() [2/2]

std::pair< int, int > terminal::size ( std::FILE *  stream)

Return the terminal size associated with a C stream.

Parameters
streamStream whose file descriptor should be queried.
Returns
Positive row and column counts, using configured fallbacks when detection is unavailable.

◆ split_string()

std::vector< std::string > terminal::split_string ( const std::string &  s,
char  delimiter 
)

◆ splitString()

std::vector< std::string > terminal::splitString ( const std::string &  s,
char  delim 
)

◆ splitTopLevel()

std::vector< std::string > terminal::splitTopLevel ( const std::string &  s,
char  delim = ',' 
)

◆ to_lower()

std::string terminal::to_lower ( std::string  s)
inline

◆ trim()

std::string terminal::trim ( const std::string &  s)
inline