From fc5159df0247c3ee70667e9d9e26a2d1a4c5f5c0 Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Tue, 7 Dec 2021 20:17:10 -0500 Subject: [PATCH] Create simple configuration file --- .gitignore | 4 +++- .vscode/settings.json | 5 +++++ include/config/config.h | 18 ++++++++++++++++++ include/config/programs_config.h | 22 ++++++++++++++++++++++ src/main.cpp | 7 ++++++- 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 include/config/config.h create mode 100644 include/config/programs_config.h diff --git a/.gitignore b/.gitignore index d73e005..d15306b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .cache -build \ No newline at end of file +build + +config.toml \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..570a496 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cmake.debugConfig": { + "cwd": "${workspaceFolder}" + } +} \ No newline at end of file diff --git a/include/config/config.h b/include/config/config.h new file mode 100644 index 0000000..d4309ba --- /dev/null +++ b/include/config/config.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include +#include + +#include "programs_config.h" + +class Config { +public: + ProgramsConfig programs; + + Config(const std::string& config_path) { + toml::value toml = toml::parse(config_path); + + programs = ProgramsConfig(toml["programs"]); + } +}; \ No newline at end of file diff --git a/include/config/programs_config.h b/include/config/programs_config.h new file mode 100644 index 0000000..82a2177 --- /dev/null +++ b/include/config/programs_config.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include + +class ProgramsConfig { +public: + std::string terminal; + std::string launcher; + + /* ProgramsConfig(const std::string& config_path) : ProgramsConfig(toml::parse(config_path)) { + + } */ + + ProgramsConfig() = default; + + ProgramsConfig(toml::value& toml_config) { + terminal = toml_config["terminal"].as_string(); + launcher = toml_config["launcher"].as_string(); + } +}; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 0862618..79050c3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,11 @@ #include +#include "config/config.h" + int main() { - std::cout << "hello world" << std::endl; + Config config("config.toml"); + + std::cout << "Terminal: \"" << config.programs.terminal << "\" - Launcher: \"" << config.programs.launcher << "\"" << std::endl; + return 0; } \ No newline at end of file