tree_display/theme.rs
1//! Color and line graphics bundled into a cohesive visual style.
2//!
3//! A theme brings together color palettes and line characters to create
4//! a consistent look for tree output. Choose from predefined themes or
5//! mix and match colors and graphics to suit your preferences.
6
7use super::color::Colors;
8use super::graphics::Graphics;
9
10// ──── API ─────────────────────────────────────────────────────────────────────────────────────
11
12/// A complete theme for tree display.
13///
14/// A theme combines color configuration and line graphics to define the
15/// visual appearance of tree output. Themes control everything from syntax
16/// highlighting colors to the characters used for drawing tree lines.
17///
18/// ## Example
19/// ```no_run
20/// use tree_display::{Theme, Colors, Graphics};
21///
22/// // Use the default theme
23/// let theme = Theme::default();
24///
25/// // Create a custom theme
26/// let custom = Theme::new()
27/// .colors(Colors::VSCODE_DARK_PLUS)
28/// .lines(Graphics::LIGHT_ROUNDED)
29/// .align_to_values(true);
30/// ```
31#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
32pub struct Theme {
33 /// Color configuration for syntax highlighting
34 pub colors: Colors,
35 /// Line characters for tree drawing
36 pub lines: Graphics,
37 /// Whether to align labels with values vertically
38 ///
39 /// When `true`: subtrees are aligned with the values they describe.
40 ///
41 /// When `false`: all subtrees have the same consistent indentation.
42 pub align_to_values: bool,
43}
44
45// ──── Utility ───────────────────────────────────────────────────────────────────────────────────
46
47impl Theme {
48 /// Creates a new [`Theme`] with default settings.
49 ///
50 /// The default theme uses no colors, light Unicode lines, and no value alignment.
51 pub const fn new() -> Self {
52 Self {
53 colors: Colors::new(),
54 lines: Graphics::new(),
55 align_to_values: false,
56 }
57 }
58
59 /// Sets the color configuration for this theme.
60 pub const fn colors(mut self, colors: Colors) -> Self {
61 self.colors = colors;
62 self
63 }
64
65 /// Sets the line graphics for this theme.
66 pub const fn lines(mut self, lines: Graphics) -> Self {
67 self.lines = lines;
68 self
69 }
70
71 /// Sets whether subtrees should be aligned with values.
72 ///
73 /// When `true`: subtrees are aligned with the values they describe.
74 ///
75 /// When `false`: all subtrees have the same consistent indentation.
76 pub const fn align_to_values(mut self, align_to_values: bool) -> Self {
77 self.align_to_values = align_to_values;
78 self
79 }
80}
81
82impl Default for Theme {
83 /// Creates a new [`Theme`] with default settings.
84 ///
85 /// The default theme uses no colors, light Unicode lines, and no value alignment.
86 fn default() -> Self {
87 Self::new()
88 }
89}