Skip to main content

rich_interact/components/
mod.rs

1//! Ready-made components (0.0.13 workstream 3), built from the crate's
2//! primitives: [`Item`](crate::Item), [`Viewport`](crate::Viewport) and the
3//! [fuzzy](crate::fuzzy) matcher. Each works under both drivers, degrades to
4//! a line-based prompt without a terminal, and is styled by one [`Theme`].
5
6mod approve;
7mod asset;
8mod color;
9mod confirm;
10mod date;
11#[cfg(feature = "data")]
12mod explore;
13mod file;
14mod form;
15mod input;
16mod jump;
17mod log;
18mod pager;
19mod paginator;
20mod reorder;
21mod select;
22mod textarea;
23mod theme;
24mod views;
25
26pub use approve::{ApprovalQueue, ApprovalReport, Decision, Verdict, approve_keymap};
27pub use asset::{AssetKind, AssetPicker, BOX_STYLES, emoji};
28pub use color::{ColorFormat, ColorPicker};
29pub use confirm::{Choice, Confirm};
30pub use date::{DatePicker, DateTimePicker, TimePicker, date_keymap};
31#[cfg(feature = "data")]
32pub use explore::{DataExplorer, explore_keymap, json_path};
33pub use file::{FileMode, FilePicker, display_name, display_path};
34pub use form::{Answers, Form, Value};
35pub use input::{Input, Provider, Suggestion, input_keymap};
36pub use jump::{Jump, JumpGroup, JumpHit, JumpIndex, JumpSource, Jumped, jump_keymap};
37pub use log::{LogEvent, LogView, log_filter_keymap, log_view_keymap};
38pub use pager::{Pager, pager_keymap, pager_search_keymap, table_header_rows};
39pub use paginator::{Paginator, PaginatorStyle, paginator_keymap};
40pub use reorder::{Reorder, move_item, reorder_keymap};
41pub use select::{MultiSelect, PreviewLayout, Select, select_keymap};
42pub use textarea::TextArea;
43pub use theme::{THEME_SAMPLE, ThemePicker};
44pub use views::{TableSelect, TreeSelect, table_keymap, tree_keymap};
45
46use rich::Style;
47
48/// The styles and symbols every component draws with.
49#[derive(Clone, Debug)]
50pub struct Theme {
51    /// The mark before a question (`?`).
52    pub question: String,
53    pub question_style: Style,
54    pub prompt: Style,
55    /// The focused row's pointer (`❯`).
56    pub pointer: String,
57    pub pointer_style: Style,
58    pub focused: Style,
59    /// Characters a filter matched.
60    pub matched: Style,
61    pub checked: String,
62    pub unchecked: String,
63    pub checked_style: Style,
64    /// Hints, counts and descriptions.
65    pub hint: Style,
66    pub error: Style,
67    /// A finished component's answer.
68    pub answer: Style,
69    pub border: Style,
70}
71
72fn style(definition: &str) -> Style {
73    Style::parse(definition).expect("a built-in style")
74}
75
76impl Default for Theme {
77    fn default() -> Self {
78        Theme {
79            question: "?".into(),
80            question_style: style("bold green"),
81            prompt: style("bold"),
82            pointer: "❯".into(),
83            pointer_style: style("bold magenta"),
84            focused: style("bold"),
85            matched: style("bold magenta"),
86            checked: "◉".into(),
87            unchecked: "○".into(),
88            checked_style: style("green"),
89            hint: style("dim"),
90            error: style("red"),
91            answer: style("cyan"),
92            border: style("dim"),
93        }
94    }
95}
96
97// The line helpers moved to the public kit (0.0.14); the components use
98// them from there.
99pub(crate) use crate::kit::{fit, highlight, pad, pasted, plain, question, shown, text, width};