7#include "theme_mode.hpp"
8#include "style_sheet.hpp"
9#include "style_sheet_parser.hpp"
11#include "../trace.hpp"
18namespace hi {
inline namespace v1 {
26 [[nodiscard]]
inline static theme_book& global()
noexcept;
35 void register_theme_directory(std::filesystem::path
const& path)
noexcept
47 for (
hilet& theme_dir : theme_dirs) {
48 hilet theme_dir_glob = theme_dir /
"**" /
"*.css";
49 for (
hilet& path :
glob(theme_dir_glob)) {
57 hi_log_error(
"Unable to load theme from file '{}': {}", path.generic_string(), e.
what());
73 for (
hilet& theme_file : theme_files) {
89 [[nodiscard]] std::optional<std::filesystem::path>
find(
std::string name, theme_mode mode)
const noexcept
92 auto it = find_if(theme_files.
begin(), theme_files.
end(), [&](
hilet& entry) {
93 return entry.name == name and entry.mode == mode;
96 if (it != theme_files.
end()) {
101 it = find_if(theme_files.
begin(), theme_files.
end(), [&](
hilet& entry) {
102 return entry.name == name;
105 if (it != theme_files.
end()) {
113 struct theme_file_entry {
116 std::filesystem::path path;
123[[nodiscard]]
inline theme_book& theme_book::global() noexcept
125 static auto r = theme_book{};
131inline void register_theme_directory(std::filesystem::path
const& path)
noexcept
133 return detail::theme_book::global().register_theme_directory(path);
144 return detail::theme_book::global().names();
155 if (
hilet path = detail::theme_book::global().find(name, mode)) {
159 hi_log_info(
"Theme {}:{} at '{}' activated successfully.",
style_sheet.name,
style_sheet.mode, path->generic_string());
163 hi_log_error(
"Unable to load theme {} from file '{}': {}", name, path->generic_string(), e.
what());
168 hi_log_error(
"Unable to find a theme matching {}:{}", name, mode);
Defines utilities for handling glob patterns.
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
generator< std::filesystem::path > glob(glob_pattern pattern)
Find paths on the filesystem that match the glob pattern.
Definition glob.hpp:875
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
std::vector< std::string > theme_names() noexcept
Get a list of theme names.
Definition theme_book.hpp:142
bool load_theme(std::string name, theme_mode mode) noexcept
Find a theme matching the name and mode.
Definition theme_book.hpp:153
Definition style_sheet.hpp:488
void activate() const noexcept
Activate style sheet as the current theme.
Definition style_sheet.hpp:507
theme_book keeps track of multiple themes.
Definition theme_book.hpp:24
void refresh()
Refresh the list of themes from the theme directories.
Definition theme_book.hpp:43
std::vector< std::string > names() const noexcept
Get a list of theme names.
Definition theme_book.hpp:69
std::optional< std::filesystem::path > find(std::string name, theme_mode mode) const noexcept
Find a theme matching the name and mode.
Definition theme_book.hpp:89
T emplace_back(T... args)