mirror of
https://codeberg.org/vyn/selenite.git
synced 2025-07-01 09:13:19 +00:00
Switch json library to rei-json
This commit is contained in:
parent
1872ab7b18
commit
7ce7ad3ee1
5 changed files with 36 additions and 24790 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "cpp/external/rei-json"]
|
||||
path = cpp/external/rei-json
|
||||
url = https://codeberg.org/vyn/rei-json.git
|
|
@ -10,4 +10,4 @@ add_library(selenite
|
|||
src/palette.cpp
|
||||
)
|
||||
|
||||
target_include_directories(selenite PRIVATE "include")
|
||||
target_include_directories(selenite PRIVATE "external/rei-json/include")
|
||||
|
|
1
cpp/external/rei-json
vendored
Submodule
1
cpp/external/rei-json
vendored
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 2041a0aafe85085dcf35a37437db493898f1be3c
|
24767
cpp/src/json.hpp
24767
cpp/src/json.hpp
File diff suppressed because it is too large
Load diff
|
@ -1,7 +1,9 @@
|
|||
#include "selenite/palette.h"
|
||||
#include "json.hpp"
|
||||
#include "rei-json/Object.h"
|
||||
#include "rei-json/json.h"
|
||||
#include <fstream>
|
||||
#include <optional>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
namespace selenite
|
||||
|
@ -24,30 +26,37 @@ std::optional<Palette> parseJson(const std::string &path)
|
|||
if (!file) {
|
||||
return std::nullopt;
|
||||
}
|
||||
auto json = nlohmann::json::parse(file);
|
||||
|
||||
if (!json.is_object() || !json["primary"].is_string() || !json["secondary"].is_string() ||
|
||||
!json["background"].is_string() || !json["background2"].is_string() ||
|
||||
!json["background4"].is_string() || !json["background3"].is_string() ||
|
||||
!json["pane"].is_string() || !json["foreground"].is_string() ||
|
||||
!json["foregroundHint"].is_string() || !json["green"].is_string() ||
|
||||
!json["orange"].is_string() || !json["red"].is_string()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
std::stringstream buffer;
|
||||
buffer << file.rdbuf();
|
||||
auto jsonStr = buffer.str();
|
||||
|
||||
auto jsonOpt = rei::json::parse(jsonStr);
|
||||
auto json = std::get<rei::json::JsonObject>(jsonOpt);
|
||||
|
||||
|
||||
/*if (!json.is_object() || !json["primary"].is_string() || !json["secondary"].is_string() ||*/
|
||||
/*!json["background"].is_string() || !json["background2"].is_string() ||*/
|
||||
/*!json["background4"].is_string() || !json["background3"].is_string() ||*/
|
||||
/*!json["pane"].is_string() || !json["foreground"].is_string() ||*/
|
||||
/*!json["foregroundHint"].is_string() || !json["green"].is_string() ||*/
|
||||
/*!json["orange"].is_string() || !json["red"].is_string()) {*/
|
||||
/*return std::nullopt;*/
|
||||
/*}*/
|
||||
|
||||
Palette palette{
|
||||
.primary = hexStringToColor(json["primary"].get<std::string>()),
|
||||
.secondary = hexStringToColor(json["secondary"].get<std::string>()),
|
||||
.background = hexStringToColor(json["background"].get<std::string>()),
|
||||
.background2 = hexStringToColor(json["background2"].get<std::string>()),
|
||||
.background3 = hexStringToColor(json["background3"].get<std::string>()),
|
||||
.background4 = hexStringToColor(json["background4"].get<std::string>()),
|
||||
.pane = hexStringToColor(json["pane"].get<std::string>()),
|
||||
.foreground = hexStringToColor(json["foreground"].get<std::string>()),
|
||||
.foregroundHint = hexStringToColor(json["foregroundHint"].get<std::string>()),
|
||||
.green = hexStringToColor(json["green"].get<std::string>()),
|
||||
.orange = hexStringToColor(json["orange"].get<std::string>()),
|
||||
.red = hexStringToColor(json["red"].get<std::string>()),
|
||||
.primary = hexStringToColor(json.getString("primary")),
|
||||
.secondary = hexStringToColor(json.getString("secondary")),
|
||||
.background = hexStringToColor(json.getString("background")),
|
||||
.background2 = hexStringToColor(json.getString("background2")),
|
||||
.background3 = hexStringToColor(json.getString("background3")),
|
||||
.background4 = hexStringToColor(json.getString("background4")),
|
||||
.pane = hexStringToColor(json.getString("pane")),
|
||||
.foreground = hexStringToColor(json.getString("foreground")),
|
||||
.foregroundHint = hexStringToColor(json.getString("foregroundHint")),
|
||||
.green = hexStringToColor(json.getString("green")),
|
||||
.orange = hexStringToColor(json.getString("orange")),
|
||||
.red = hexStringToColor(json.getString("red")),
|
||||
};
|
||||
return palette;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue