termstyle 1.0.0-pre.3
An open-source C++ header file that enables developers to easily define and apply customizable style presets for terminal outputs such as warnings, infos, and errors.
Loading...
Searching...
No Matches
termstyle.hpp File Reference

Header file for the termstyle library. More...

#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
#include <map>

Go to the source code of this file.

Classes

class  Error
 Base class for all exceptions thrown by the library. More...
 
class  PresetNameUsed
 Thrown when a preset name is already used. More...
 
class  PresetNotFound
 Thrown when a preset is not found. More...
 
class  BadColorID
 
struct  termstyle::Col256
 Struct for storing 256-color codes. More...
 
struct  termstyle::ColRGB
 Struct for storing RGB color codes. More...
 
struct  termstyle::Color
 Struct for storing different types of colors. More...
 
struct  termstyle::StyleString
 Struct for storing styled strings. More...
 
struct  termstyle::Config
 Configuration namespace. More...
 
struct  termstyle::PresetConfig
 Struct for storing preset configurations. More...
 
class  termstyle::StyledCout
 A class that provides styled output to the standard output stream. More...
 
class  termstyle::OnExit
 The OnExit class is a helper class that performs an action when it goes out of scope. More...
 

Namespaces

namespace  termstyle
 Namespace for the termstyle library.
 

Macros

#define TERMSTYLE_HPP
 
#define TERMSTYLE_NODISCARD   [[nodiscard]]
 
#define TERMSTYLE_ERROR_DEF(parent, name)
 
#define TERMSTYLE_ERROR_SIMPLE(name)    explicit name(std::string msg) : name(#name, msg, ExitCodes::name) {}
 

Enumerations

enum class  ExitCodes : int {
  SUCCESS = 0 , IncorrectConstruction = 100 , PresetNameUsed , PresetNotFound ,
  BadColorID , BaseClass = 200
}
 
enum class  termstyle::Codes : int {
  RESTORE = 0 , BRIGHT = 1 , DIM = 2 , ITALIC = 3 ,
  UNDERLINE = 4 , FLASH = 5 , REVERSE = 7 , HIDDEN = 8 ,
  STRIKE = 9 , BRIGHT_RESET = 22 , DIM_RESET = 22 , ITALIC_RESET = 23 ,
  UNDERLINE_RESET = 24 , FLASH_RESET = 25 , REVERSE_RESET = 27 , HIDDEN_RESET = 28 ,
  STRIKE_RESET = 29 , FOREGROUND_BLACK = 30 , FOREGROUND_RED = 31 , FOREGROUND_GREEN = 32 ,
  FOREGROUND_YELLOW = 33 , FOREGROUND_BLUE = 34 , FOREGROUND_PURPLE = 35 , FOREGROUND_CYAN = 36 ,
  FOREGROUND_WHITE = 37 , FOREGROUND_RESET = 39 , BACKGROUND_BLACK = 40 , BACKGROUND_RED = 41 ,
  BACKGROUND_GREEN = 42 , BACKGROUND_YELLOW = 43 , BACKGROUND_BLUE = 44 , BACKGROUND_PURPLE = 45 ,
  BACKGROUND_CYAN = 46 , BACKGROUND_WHITE = 47 , BACKGROUND_RESET = 49
}
 Enum class for ANSI escape codes.
 
enum class  termstyle::ColorMode : int { FOREGROUND = 38 , BACKGROUND = 48 }
 Enum class for color modes.
 
enum class  termstyle::ColorType : int { COL16 = 0 , COL256 = 1 , COLRGB = 2 }
 Enum class for color types.
 
enum class  termstyle::ParseMode : int { ALL = 0 , PREFIX = 1 , SUFFIX = 2 }
 Enum class for parse modes.
 

Functions

template<typename T >
std::string termstyle::code2string (const std::vector< T > &codelist) noexcept
 
std::string termstyle::code2string (const Codes &col)
 
bool termstyle::validateColorID (int ID)
 Validates a color 256 ID.
 
std::string termstyle::col256_2string (std::vector< Col256 > codelist) noexcept
 
std::string termstyle::col256_2string (const Col256 &col) noexcept
 
std::string termstyle::colrgb_2string (const ColRGB &col) noexcept
 
std::string termstyle::parseColortype (std::vector< Color > codelist) noexcept
 
std::string termstyle::parse (const PresetConfig &preset, ParseMode mode=ParseMode::ALL) noexcept
 
void termstyle::addPreset (std::string name, PresetConfig preset)
 Adds a preset with the given name and configuration.
 
void termstyle::print (std::string preset, std::string text="")
 
StyledCout termstyle::style (const std::string &preset)
 

Variables

std::map< std::string, PresetConfigtermstyle::presets = {}
 A map that stores preset configurations.
 
OnExit termstyle::onExitInstance
 

Detailed Description

Header file for the termstyle library.

This file contains the declarations of classes, structs, and functions used in the termstyle library. The library allows you to create presets and style your terminal output using ANSI escape codes.

Macro Definition Documentation

◆ TERMSTYLE_ERROR_DEF

#define TERMSTYLE_ERROR_DEF ( parent,
name )
Value:
protected: \
name(std::string ename, std::string msg, int exit_code) \
: parent(std::move(ename), std::move(msg), exit_code) {} \
name(std::string ename, std::string msg, ExitCodes exit_code) \
: parent(std::move(ename), std::move(msg), exit_code) {} \
\
public: \
name(std::string msg, ExitCodes exit_code) \
: parent(#name, std::move(msg), exit_code) {} \
name(std::string msg, int exit_code) \
: parent(#name, std::move(msg), exit_code) {}