Create simple configuration file

This commit is contained in:
SeanOMik 2021-12-07 20:17:10 -05:00
parent 42e1519091
commit fc5159df02
5 changed files with 54 additions and 2 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
.cache
build
config.toml

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"cmake.debugConfig": {
"cwd": "${workspaceFolder}"
}
}

18
include/config/config.h Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include <toml.hpp>
#include <toml/parser.hpp>
#include <toml/value.hpp>
#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"]);
}
};

View File

@ -0,0 +1,22 @@
#pragma once
#include <toml.hpp>
#include <toml/parser.hpp>
#include <toml/value.hpp>
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();
}
};

View File

@ -1,6 +1,11 @@
#include <iostream>
#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;
}