#include "toml.hpp"
#include <cstdlib>
#include <filesystem>
#include <iostream>
Go to the source code of this file.
Macros | |
#define | PARENT_LIB "library" |
Macros for parent and field names used in the TOML configuration. | |
#define | PARENT_LIB_FIELD_NAME "name" |
#define | PARENT_LIB_FIELD_DIR "directory" |
#define | PARENT_FTP "ftp" |
#define | PARENT_FTP_FIELD_USER "username" |
#define | PARENT_FTP_FIELD_SALT "salt" |
#define | PARENT_FTP_FIELD_PWD_HASH "password_hash" |
#define | PARENT_DBG "debug" |
#define | PARENT_DBG_FIELD_PARSER_LOG "parser_log" |
#define | PARENT_KEYBINDS "keybinds" |
#define | SPECIAL_KEYBIND_ENTER_STR "Enter" |
#define | SPECIAL_KEYBIND_TAB_STR "Tab" |
#define | SPECIAL_KEYBIND_SPACE_STR "Space" |
#define | PARENT_COLORS "colors" |
Functions | |
string | getConfigPath (string fileName) |
Retrieves the path to the configuration file. | |
string | getCachePath () |
bool | configFileExists (const string &filePath) |
Checks if the configuration file exists. | |
auto | loadConfig () |
Loads the configuration file. | |
string_view | parseTOMLField (string parent, string field) |
Parses a string field from the TOML configuration. | |
int64_t | parseTOMLFieldInt (string parent, string field) |
Parses an integer field from the TOML configuration. | |
Variables | |
auto | config = loadConfig() |
#define PARENT_COLORS "colors" |
Parent section for color settings
#define PARENT_DBG "debug" |
Parent section for debug settings
#define PARENT_DBG_FIELD_PARSER_LOG "parser_log" |
Field for debug parser log setting
#define PARENT_FTP "ftp" |
Parent section for FTP settings
#define PARENT_FTP_FIELD_PWD_HASH "password_hash" |
Field for FTP password hash
#define PARENT_FTP_FIELD_SALT "salt" |
Field for FTP salt
#define PARENT_FTP_FIELD_USER "username" |
Field for FTP username
#define PARENT_KEYBINDS "keybinds" |
Parent section for keybinds
#define PARENT_LIB "library" |
Macros for parent and field names used in the TOML configuration.
These macros represent the sections and fields in the TOML configuration file. Parent section for library settings
#define PARENT_LIB_FIELD_DIR "directory" |
Field for the library directory
#define PARENT_LIB_FIELD_NAME "name" |
Field for the library name
#define SPECIAL_KEYBIND_ENTER_STR "Enter" |
Special keybind for Enter
#define SPECIAL_KEYBIND_SPACE_STR "Space" |
Special keybind for Space
#define SPECIAL_KEYBIND_TAB_STR "Tab" |
Special keybind for Tab
bool configFileExists | ( | const string & | filePath | ) |
Checks if the configuration file exists.
This function checks if the config.toml
file exists at the given file path.
filePath | The path to the configuration file. |
true
if the file exists, otherwise false
. string getCachePath | ( | ) |
< Exit gracefully if the HOME environment variable is not set.
string getConfigPath | ( | string | fileName | ) |
Retrieves the path to the configuration file.
This function constructs the path to the config.toml
file located in the user's home directory, inside the .config/inLimbo/
folder.
fileName | The name of the configuration file (e.g., "config.toml"). |
std::runtime_error | If the HOME environment variable is not found. |
< Exit gracefully if the HOME environment variable is not set.
auto loadConfig | ( | ) |
Loads the configuration file.
This function loads the config.toml
file and parses it using the toml
library. If the file does not exist, the program exits gracefully with an error message.
toml::parse_result
object representing the parsed configuration. std::runtime_error | If the configuration file does not exist or cannot be parsed. |
string_view parseTOMLField | ( | string | parent, |
string | field ) |
Parses a string field from the TOML configuration.
This function retrieves the value of a specific field within a parent section of the TOML configuration. If the field is not found, it returns an empty string view.
parent | The parent section name (e.g., "library"). |
field | The field name within the parent section (e.g., "name"). |
< If the field is not found, return an empty string view.
int64_t parseTOMLFieldInt | ( | string | parent, |
string | field ) |
Parses an integer field from the TOML configuration.
This function retrieves the value of a specific field as an integer from the TOML configuration. If the field is not found, it returns -1 as a default value.
parent | The parent section name (e.g., "ftp"). |
field | The field name within the parent section (e.g., "username"). |
< If the field is not found, return -1 as default.
auto config = loadConfig() |
Parse the configuration file during the initialization