1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! Free-function loader API for [`Theme`].
//!
//! Wraps `Theme::from_toml_str` / `Theme::from_path` as top-level functions
//! so callers can write `hjkl_theme::loader::load_from_path(p)?` without
//! importing the `Theme` struct, and provides `default_theme()` with a
//! minimal bundled dark palette.
//!
//! `resolve_palette_refs` is exposed here for symmetry, but resolution
//! happens automatically inside `parse_toml` / `load_from_path`; callers
//! that build a `Theme` via those functions get fully-resolved colors with
//! no additional step required.
use Path;
use crate::;
/// Built-in minimal dark theme source embedded at compile time.
const DEFAULT_THEME_TOML: &str = include_str!;
/// Parse a TOML string into a fully-resolved [`Theme`].
///
/// Palette `$name` references are resolved automatically.
///
/// # Errors
/// Returns [`ThemeError::Toml`] on parse failure or
/// [`ThemeError::UnresolvedPalette`] / [`ThemeError::BadHex`] on bad
/// color values.
/// Read a TOML file from `path` and return a fully-resolved [`Theme`].
///
/// Palette `$name` references are resolved automatically.
///
/// # Errors
/// Returns [`ThemeError::Io`] on read failure or any error that
/// [`parse_toml`] can return.
/// Walk a [`Theme`] and verify all palette references are resolved.
///
/// After a successful call to [`parse_toml`] or [`load_from_path`] this
/// is always a no-op — resolution is performed during parsing. The
/// function is provided as an explicit checkpoint for callers that
/// construct a `Theme` by other means (e.g. merging two themes) and
/// want to assert completeness before use.
///
/// Returns `Ok(())` when every color in the theme is already concrete.
///
/// # Errors
/// Returns [`ThemeError::UnresolvedPalette`] if a `$name` palette
/// reference could not be resolved. (This cannot happen for themes
/// produced by [`parse_toml`] / [`load_from_path`].)
/// Return the bundled default dark [`Theme`].
///
/// The theme is a minimal dark palette suitable as a fallback when no
/// user theme file is found. It is embedded in the binary at compile
/// time and always valid.
///
/// # Panics
/// Panics if the bundled TOML is malformed — this would be a compile-time
/// error caught by `cargo test`.