rs-rich-interact 0.0.13

Interactive terminal components for rs-rich: event loop, viewport, item model, headless testing
Documentation
//! Ready-made components (0.0.13 workstream 3), built from the crate's
//! primitives: [`Item`](crate::Item), [`Viewport`](crate::Viewport) and the
//! [fuzzy](crate::fuzzy) matcher. Each works under both drivers, degrades to
//! a line-based prompt without a terminal, and is styled by one [`Theme`].

mod approve;
mod asset;
mod color;
mod confirm;
mod date;
#[cfg(feature = "data")]
mod explore;
mod file;
mod form;
mod input;
mod jump;
mod log;
mod pager;
mod paginator;
mod reorder;
mod select;
mod textarea;
mod theme;
mod views;

pub use approve::{ApprovalQueue, ApprovalReport, Decision, Verdict, approve_keymap};
pub use asset::{AssetKind, AssetPicker, BOX_STYLES, emoji};
pub use color::{ColorFormat, ColorPicker};
pub use confirm::{Choice, Confirm};
pub use date::{DatePicker, DateTimePicker, TimePicker, date_keymap};
#[cfg(feature = "data")]
pub use explore::{DataExplorer, explore_keymap, json_path};
pub use file::{FileMode, FilePicker, display_name, display_path};
pub use form::{Answers, Form, Value};
pub use input::{Input, Provider, Suggestion, input_keymap};
pub use jump::{Jump, JumpGroup, JumpHit, JumpIndex, JumpSource, Jumped, jump_keymap};
pub use log::{LogEvent, LogView, log_filter_keymap, log_view_keymap};
pub use pager::{Pager, pager_keymap, pager_search_keymap, table_header_rows};
pub use paginator::{Paginator, PaginatorStyle, paginator_keymap};
pub use reorder::{Reorder, move_item, reorder_keymap};
pub use select::{MultiSelect, PreviewLayout, Select, select_keymap};
pub use textarea::TextArea;
pub use theme::{THEME_SAMPLE, ThemePicker};
pub use views::{TableSelect, TreeSelect, table_keymap, tree_keymap};

use rich::Style;

/// The styles and symbols every component draws with.
#[derive(Clone, Debug)]
pub struct Theme {
    /// The mark before a question (`?`).
    pub question: String,
    pub question_style: Style,
    pub prompt: Style,
    /// The focused row's pointer (`❯`).
    pub pointer: String,
    pub pointer_style: Style,
    pub focused: Style,
    /// Characters a filter matched.
    pub matched: Style,
    pub checked: String,
    pub unchecked: String,
    pub checked_style: Style,
    /// Hints, counts and descriptions.
    pub hint: Style,
    pub error: Style,
    /// A finished component's answer.
    pub answer: Style,
    pub border: Style,
}

fn style(definition: &str) -> Style {
    Style::parse(definition).expect("a built-in style")
}

impl Default for Theme {
    fn default() -> Self {
        Theme {
            question: "?".into(),
            question_style: style("bold green"),
            prompt: style("bold"),
            pointer: "❯".into(),
            pointer_style: style("bold magenta"),
            focused: style("bold"),
            matched: style("bold magenta"),
            checked: "◉".into(),
            unchecked: "○".into(),
            checked_style: style("green"),
            hint: style("dim"),
            error: style("red"),
            answer: style("cyan"),
            border: style("dim"),
        }
    }
}

// The line helpers moved to the public kit (0.0.14); the components use
// them from there.
pub(crate) use crate::kit::{fit, highlight, pad, pasted, plain, question, shown, text, width};