Consolix
Loading...
Searching...
No Matches
consolix Namespace Reference

< Utility modules and helpers. More...

Namespaces

namespace  compat

Classes

class  BaseLoopComponent
 Abstract base class for application components with looping functionality. More...
class  LoggerComponent
 Fallback LoggerComponent when LogIt is disabled. More...
class  MultiStream
 A class for handling multi-target log streams. More...
class  LogoComponent
 Component responsible for displaying a customizable ASCII logo. More...
class  LoopComponent
 Component for managing a customizable execution loop. More...
class  TitleComponent
 Handles setting and retrieving the console window title. More...
class  AppComponentManager
 Manages a collection of application components with lifecycle support. More...
class  ConsoleApplication
 Singleton class to manage the lifecycle of a console application. More...
class  ServiceLocator
 A universal service locator for managing shared resources. More...
class  IAppComponent
 Interface for defining application components. More...
class  IShutdownable
 Interface for components supporting shutdown logic. More...
class  ColorManipulator
 A utility class for managing text color in streams. More...

Enumerations

enum class  TextColor {
  Black , DarkRed , DarkGreen , DarkYellow ,
  DarkBlue , DarkMagenta , DarkCyan , LightGray ,
  DarkGray , Red , Green , Yellow ,
  Blue , Magenta , Cyan , White
}
 Represents text colors for console output. More...

Functions

void init ()
 Initializes the application. This function prepares the application and service locator for use.
template<typename InitAction>
void init (InitAction init_action)
 Initializes the application with a custom action. This function prepares the application and service locator, and executes a custom action during initialization.
template<typename Component, typename... Args>
std::shared_ptr< Component > add (Args &&... args)
 Adds a new component to the application. Creates a new instance of the specified component type and adds it to the application.
void add (std::shared_ptr< IAppComponent > component)
 Adds an existing component to the application. Registers a pre-existing component with the application.
void run ()
 Runs the application. Processes all components in the application's main loop.
template<typename IterationAction>
void run (IterationAction iteration_action)
 Runs the application with a custom loop action.
void stop ()
 Stops the application. Stops the application's main loop and begins the shutdown process.
template<typename T>
void register_service (std::function< std::shared_ptr< T >()> creator)
 Registers a resource or service globally. Registers a resource or service with the ServiceLocator using the provided creator function.
template<typename T>
void register_service ()
 Registers a resource with default construction globally. Registers a resource or service using default construction.
template<typename T>
T & get_service ()
 Retrieves a resource globally. Retrieves a reference to a globally registered resource from the ServiceLocator.
template<typename T>
bool has_service ()
 Checks if a resource is registered globally.
void clear_all ()
 Clears all registered resources globally. Clears all resources and services registered in the ServiceLocator.
ColorManipulator color (TextColor color)
 Creates a color manipulator for use in output streams.
std::ostream & operator<< (std::ostream &os, const ColorManipulator &manip)
 Overloads the stream operator to apply text color.
const char * to_c_str (const TextColor &color)
 Converts a TextColor to an ANSI escape code string.
bool check_escaped (const std::string &json_string, std::size_t quote_position)
 Checks if a character in a JSON string is escaped.
std::string strip_json_comments (const std::string &json_string, bool with_whitespace=false, bool preserve_newlines=true)
 Removes comments from a JSON string.
std::string get_exec_path ()
 Retrieves the full path of the executable.
std::string get_exec_dir ()
 Retrieves the directory of the executable file.
std::string get_file_name (const std::string &file_path)
 Extracts the file name from a full file path.
std::string resolve_exec_path (const std::string &relative_path)
 Resolves a relative path to absolute, based on executable location.
std::string make_relative (const std::string &file_path, const std::string &base_path)
 Computes the relative path from base_path to file_path.
void create_directories (const std::string &path)
 Creates directories recursively for the given path.
bool copy_to_clipboard (const std::string &text)
 Copies the given text to the system clipboard.
std::string get_clipboard_text ()
 Retrieves text from the system clipboard.
std::string get_os_name ()
 Gets the name of the operating system.
std::uint64_t get_system_time_ms ()
 Gets the current system time in milliseconds.
int get_cpu_count ()
 Gets the number of logical CPU cores.
std::string get_home_directory ()
 Gets the user's home directory path.
std::string get_temp_directory ()
 Gets the system temporary directory path.
std::string get_env_var (const std::string &var_name)
 Retrieves an environment variable's value.

Detailed Description

< Utility modules and helpers.

< Global configuration macros for Consolix. < Core functionalities of Consolix. < Aggregated components of Consolix.

Main namespace for the Consolix framework.

The consolix namespace contains all classes, functions, and utilities provided by the Consolix framework. It is the primary namespace used for building structured and flexible console applications.

Enumeration Type Documentation

◆ TextColor

enum class consolix::TextColor
strong

Represents text colors for console output.

The enumeration defines a set of standard text colors compatible with both ANSI escape codes (Linux/macOS) and Windows API (Windows).

Enumerator
Black 
DarkRed 
DarkGreen 
DarkYellow 
DarkBlue 
DarkMagenta 
DarkCyan 
LightGray 
DarkGray 
Red 
Green 
Yellow 
Blue 
Magenta 
Cyan 
White 

Definition at line 19 of file enums.hpp.

Function Documentation

◆ add() [1/2]

template<typename Component, typename... Args>
std::shared_ptr< Component > consolix::add ( Args &&... args)
inline

Adds a new component to the application. Creates a new instance of the specified component type and adds it to the application.

Template Parameters
ComponentThe type of the component to add.
ArgsThe types of the arguments to pass to the component's constructor.
Parameters
argsArguments to construct the component.
Returns
A std::shared_ptr to the added component.
Examples
example_application_main_loop.cpp.

Definition at line 50 of file application_utils.hpp.

◆ add() [2/2]

void consolix::add ( std::shared_ptr< IAppComponent > component)
inline

Adds an existing component to the application. Registers a pre-existing component with the application.

Parameters
componentA std::shared_ptr to the component to add.

Definition at line 57 of file application_utils.hpp.

◆ check_escaped()

bool consolix::check_escaped ( const std::string & json_string,
std::size_t quote_position )
inline

Checks if a character in a JSON string is escaped.

Parameters
json_stringThe JSON string.
quote_positionThe position of the character to check.
Returns
true if the character is escaped, false otherwise.

Definition at line 18 of file json_utils.hpp.

◆ clear_all()

void consolix::clear_all ( )
inline

Clears all registered resources globally. Clears all resources and services registered in the ServiceLocator.

Definition at line 65 of file service_utils.hpp.

◆ color()

ColorManipulator consolix::color ( TextColor color)
inline

Creates a color manipulator for use in output streams.

Parameters
colorThe desired text color.
Returns
A ColorManipulator object for stream manipulation.
Examples
example_application_main_loop.cpp.

Definition at line 52 of file ColorManipulator.hpp.

◆ copy_to_clipboard()

bool consolix::copy_to_clipboard ( const std::string & text)
inline

Copies the given text to the system clipboard.

Parameters
textThe text to copy.
Returns
True if the operation was successful, false otherwise.

Definition at line 27 of file system_utils.hpp.

◆ create_directories()

void consolix::create_directories ( const std::string & path)
inline

Creates directories recursively for the given path.

Parameters
pathThe directory path to create.
Exceptions
std::runtime_errorif the directories cannot be created.

Definition at line 87 of file path_utils.hpp.

◆ get_clipboard_text()

std::string consolix::get_clipboard_text ( )
inline

Retrieves text from the system clipboard.

Returns
Clipboard contents as a string, or an empty string on failure.

Definition at line 57 of file system_utils.hpp.

◆ get_cpu_count()

int consolix::get_cpu_count ( )
inline

Gets the number of logical CPU cores.

Returns
The number of logical CPU cores.

Definition at line 103 of file system_utils.hpp.

◆ get_env_var()

std::string consolix::get_env_var ( const std::string & var_name)
inline

Retrieves an environment variable's value.

Parameters
var_nameThe name of the environment variable.
Returns
The value of the environment variable, or an empty string if not found.

Definition at line 147 of file system_utils.hpp.

◆ get_exec_dir()

std::string consolix::get_exec_dir ( )
inline

Retrieves the directory of the executable file.

Returns
A string containing the directory path of the executable.

Definition at line 52 of file path_utils.hpp.

◆ get_exec_path()

std::string consolix::get_exec_path ( )
inline

Retrieves the full path of the executable.

Returns
A string containing the full path of the executable.

Definition at line 21 of file path_utils.hpp.

◆ get_file_name()

std::string consolix::get_file_name ( const std::string & file_path)
inline

Extracts the file name from a full file path.

Parameters
file_pathThe full file path as a string.
Returns
The extracted file name, or the full string if no directory separator is found.

Definition at line 59 of file path_utils.hpp.

◆ get_home_directory()

std::string consolix::get_home_directory ( )
inline

Gets the user's home directory path.

Returns
A string containing the home directory path.

Definition at line 117 of file system_utils.hpp.

◆ get_os_name()

std::string consolix::get_os_name ( )
inline

Gets the name of the operating system.

Returns
A string representing the OS name.

Definition at line 81 of file system_utils.hpp.

◆ get_service()

template<typename T>
T & consolix::get_service ( )
inline

Retrieves a resource globally. Retrieves a reference to a globally registered resource from the ServiceLocator.

Template Parameters
TThe type of the resource.
Returns
Reference to the resource.
Examples
example_application_main_loop.cpp.

Definition at line 51 of file service_utils.hpp.

◆ get_system_time_ms()

std::uint64_t consolix::get_system_time_ms ( )
inline

Gets the current system time in milliseconds.

Returns
System time in milliseconds.

Definition at line 95 of file system_utils.hpp.

◆ get_temp_directory()

std::string consolix::get_temp_directory ( )
inline

Gets the system temporary directory path.

Returns
A string containing the temporary directory path.

Definition at line 131 of file system_utils.hpp.

◆ has_service()

template<typename T>
bool consolix::has_service ( )
inline

Checks if a resource is registered globally.

Template Parameters
TThe type of the resource.
Returns
true if the resource is registered, false otherwise.

Definition at line 59 of file service_utils.hpp.

◆ init() [1/2]

void consolix::init ( )
inline

Initializes the application. This function prepares the application and service locator for use.

Definition at line 28 of file application_utils.hpp.

◆ init() [2/2]

template<typename InitAction>
void consolix::init ( InitAction init_action)
inline

Initializes the application with a custom action. This function prepares the application and service locator, and executes a custom action during initialization.

Template Parameters
InitActionA callable type for the custom initialization action.
Parameters
init_actionThe action to execute during initialization.

Definition at line 38 of file application_utils.hpp.

◆ make_relative()

std::string consolix::make_relative ( const std::string & file_path,
const std::string & base_path )
inline

Computes the relative path from base_path to file_path.

Parameters
file_pathThe target file path.
base_pathThe base path from which to compute the relative path.
Returns
A string representing the relative path from base_path to file_path.

Definition at line 74 of file path_utils.hpp.

◆ operator<<()

std::ostream & consolix::operator<< ( std::ostream & os,
const ColorManipulator & manip )
inline

Overloads the stream operator to apply text color.

Parameters
osThe output stream.
manipThe ColorManipulator controlling the text color.
Returns
The modified output stream.

Definition at line 60 of file ColorManipulator.hpp.

◆ register_service() [1/2]

template<typename T>
void consolix::register_service ( )
inline

Registers a resource with default construction globally. Registers a resource or service using default construction.

Template Parameters
TThe type of the resource.

Definition at line 42 of file service_utils.hpp.

◆ register_service() [2/2]

template<typename T>
void consolix::register_service ( std::function< std::shared_ptr< T >()> creator)
inline

Registers a resource or service globally. Registers a resource or service with the ServiceLocator using the provided creator function.

Template Parameters
TThe type of the resource.
Parameters
creatorA function to create the resource (optional).

Definition at line 34 of file service_utils.hpp.

◆ resolve_exec_path()

std::string consolix::resolve_exec_path ( const std::string & relative_path)
inline

Resolves a relative path to absolute, based on executable location.

Parameters
relative_pathRelative path from executable directory.
Returns
Absolute path string.

Definition at line 66 of file path_utils.hpp.

◆ run() [1/2]

void consolix::run ( )
inline

Runs the application. Processes all components in the application's main loop.

Examples
example_application_main_loop.cpp.

Definition at line 63 of file application_utils.hpp.

◆ run() [2/2]

template<typename IterationAction>
void consolix::run ( IterationAction iteration_action)
inline

Runs the application with a custom loop action.

Executes a custom action during each iteration of the application's main loop.

Template Parameters
IterationActionA callable type for the custom loop action.
Parameters
iteration_actionThe action to execute in the main loop.

Definition at line 73 of file application_utils.hpp.

◆ stop()

void consolix::stop ( )
inline

Stops the application. Stops the application's main loop and begins the shutdown process.

Definition at line 79 of file application_utils.hpp.

◆ strip_json_comments()

std::string consolix::strip_json_comments ( const std::string & json_string,
bool with_whitespace = false,
bool preserve_newlines = true )
inline

Removes comments from a JSON string.

Parameters
json_stringThe JSON string to process.
with_whitespaceIf true, comments are replaced with equivalent whitespace.
preserve_newlinesIf true and with_whitespace is enabled, newline characters are preserved.
Returns
A JSON string with comments removed.

Definition at line 38 of file json_utils.hpp.

◆ to_c_str()

const char * consolix::to_c_str ( const TextColor & color)
inline

Converts a TextColor to an ANSI escape code string.

Parameters
colorThe text color to convert.
Returns
A C-style string representing the ANSI escape code for the color.

Definition at line 41 of file enums.hpp.