bubbletea_widgets/list/
style.rs

1//! Styling system for list components.
2//!
3//! This module provides comprehensive styling options for list components, including
4//! styles for different UI elements and visual states. The styling system is built
5//! on top of lipgloss and provides sensible defaults for terminal applications.
6//!
7//! ## Style Categories
8//!
9//! - **Title and Header**: Styles for list titles and column headers
10//! - **Status and Filter**: Styles for status bar and filter prompt
11//! - **Pagination**: Styles for pagination indicators and navigation
12//! - **Visual Elements**: Styles for spinners, dots, and separators
13//!
14//! ## Constants
15//!
16//! - `BULLET`: Unicode bullet character (`•`) used in pagination
17//! - `ELLIPSIS`: Unicode ellipsis character (`…`) for truncated content
18//!
19//! ## Color Scheme
20//!
21//! The default styles use a dark theme with:
22//! - Bright colors for active/selected elements
23//! - Subdued colors for secondary information
24//! - High contrast for readability
25//!
26//! ## Example
27//!
28//! ```rust
29//! use bubbletea_widgets::list::style::{ListStyles, BULLET, ELLIPSIS};
30//! use lipgloss::{Style, Color};
31//!
32//! let mut styles = ListStyles::default();
33//! styles.title = Style::new()
34//!     .foreground(Color::from("cyan"))
35//!     .bold(true);
36//! ```
37
38use lipgloss::{self, style::Style, Color};
39
40/// Unicode bullet character used in pagination indicators.
41pub const BULLET: &str = "•";
42/// Unicode ellipsis character used for truncated content.
43pub const ELLIPSIS: &str = "…";
44
45/// Collection of styles applied to list UI elements.
46#[derive(Debug, Clone)]
47pub struct ListStyles {
48    /// Style for the title bar container.
49    pub title_bar: Style,
50    /// Style for the list title text.
51    pub title: Style,
52    /// Style for spinner glyphs.
53    pub spinner: Style,
54    /// Style for the filter prompt label.
55    pub filter_prompt: Style,
56    /// Style for the filter cursor/caret.
57    pub filter_cursor: Style,
58    /// Style for default filter character highlight.
59    pub default_filter_character_match: Style,
60    /// Style for the status bar container.
61    pub status_bar: Style,
62    /// Style for the status bar when the list is empty.
63    pub status_empty: Style,
64    /// Style for active filter text in the status bar.
65    pub status_bar_active_filter: Style,
66    /// Style for filter match count in the status bar.
67    pub status_bar_filter_count: Style,
68    /// Style for the "No items" message.
69    pub no_items: Style,
70    /// Style for pagination area.
71    pub pagination_style: Style,
72    /// Style for help text area.
73    pub help_style: Style,
74    /// Style for the active pagination dot.
75    pub active_pagination_dot: Style,
76    /// Style for the inactive pagination dot.
77    pub inactive_pagination_dot: Style,
78    /// Style for arabic numerals in pagination.
79    pub arabic_pagination: Style,
80    /// Style for the divider dot between elements.
81    pub divider_dot: Style,
82}
83
84impl Default for ListStyles {
85    fn default() -> Self {
86        // Fallback to dark-theme oriented colors (use dark variants)
87        let very_subdued = Color::from("#3C3C3C");
88        let subdued = Color::from("#5C5C5C");
89        Self {
90            title_bar: Style::new().padding(0, 0, 1, 2),
91            title: Style::new()
92                .background(Color::from("62"))
93                .foreground(Color::from("230"))
94                .padding(0, 1, 0, 1),
95            spinner: Style::new().foreground(Color::from("#747373")),
96            filter_prompt: Style::new().foreground(Color::from("#ECFD65")),
97            filter_cursor: Style::new().foreground(Color::from("#EE6FF8")),
98            default_filter_character_match: Style::new().underline(true),
99            status_bar: Style::new()
100                .foreground(Color::from("#777777"))
101                .padding(0, 0, 1, 2),
102            status_empty: Style::new().foreground(subdued.clone()),
103            status_bar_active_filter: Style::new().foreground(Color::from("#dddddd")),
104            status_bar_filter_count: Style::new().foreground(very_subdued.clone()),
105            no_items: Style::new().foreground(Color::from("#626262")),
106            arabic_pagination: Style::new().foreground(subdued.clone()),
107            pagination_style: Style::new().padding_left(2),
108            help_style: Style::new().padding(1, 0, 0, 2),
109            active_pagination_dot: Style::new()
110                .foreground(Color::from("#979797"))
111                .set_string(BULLET),
112            inactive_pagination_dot: Style::new()
113                .foreground(very_subdued.clone())
114                .set_string(BULLET),
115            divider_dot: Style::new()
116                .foreground(very_subdued)
117                .set_string(&format!(" {} ", BULLET)),
118        }
119    }
120}