8#include "../settings/settings.hpp"
9#include "../macros.hpp"
35 void register_directory(
std::filesystem::path path) noexcept
37 _theme_directories.push_back(path);
40 void reload() noexcept
44 for (hilet& theme_directory : _theme_directories) {
45 hilet theme_directory_glob = theme_directory /
"**" /
"*.theme.json";
46 for (hilet& theme_path : glob(theme_directory_glob)) {
47 auto t =
trace<
"theme_scan">{};
50 themes.push_back(std::make_unique<theme>(theme_path));
52 hi_log_error(
"Failed parsing theme at {}. \"{}\"", theme_path.string(), e.
what());
57 if (ssize(themes) == 0) {
58 hi_log_fatal(
"Did not load any themes.");
66 for (hilet& t : themes) {
82 [[nodiscard]]
theme const&
find(std::string_view name, theme_mode mode)
const noexcept
84 theme *default_theme =
nullptr;
85 theme *default_theme_and_mode =
nullptr;
86 theme *matching_theme =
nullptr;
87 theme *matching_theme_and_mode =
nullptr;
89 for (hilet& t : themes) {
90 if (t->name == name and t->mode == mode) {
91 matching_theme_and_mode = t.get();
92 }
else if (t->name == name) {
93 matching_theme = t.get();
94 }
else if (t->name ==
"default" and t->mode == mode) {
95 default_theme_and_mode = t.get();
96 }
else if (t->name ==
"default") {
97 default_theme = t.get();
101 if (matching_theme_and_mode) {
102 return *matching_theme_and_mode;
103 }
else if (matching_theme) {
104 return *matching_theme;
105 }
else if (default_theme_and_mode) {
106 return *default_theme_and_mode;
107 }
else if (default_theme) {
108 return *default_theme;
109 }
else if (ssize(themes) > 0) {
110 return *themes[0].get();
126 _global = std::make_unique<theme_book>();
131inline void register_theme_directory(std::filesystem::path
const &path)
noexcept
133 return theme_book::global().register_directory(path);
138 return theme_book::global().reload();
141template<std::ranges::range R>
142inline void register_theme_directories(R &&r)
noexcept
144 for (
auto &path: r) {
145 register_theme_directory(path);
150[[
nodiscard]]
inline theme
const& find_theme(std::string_view name, theme_mode mode)
noexcept
152 return theme_book::global().find(name, mode);
157 return theme_book::global().names();
162 return find_theme(*theme_book::global().selected_theme, os_settings::theme_mode());
DOXYGEN BUG.
Definition algorithm.hpp:16
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
theme_book keeps track of multiple themes.
Definition theme_book.hpp:20
theme const & find(std::string_view name, theme_mode mode) const noexcept
Find a theme matching the name and mode.
Definition theme_book.hpp:82
A observer pointing to the whole or part of a observable.
Definition observer.hpp:26