ratatui_toolkit/primitives/statusline/
mod.rs

1//! A status-line widget that can stack up indicators
2//! on the left and right end.
3//!
4//! If you use the constants SLANT_TL_BR and SLANT_BL_TR as
5//! separator you can do neo-vim/neovim style statusline.
6//!
7//! This is adapted from rat-widget's StatusLineStacked.
8//!
9//! # Example
10//!
11//! ```rust,no_run
12//! use ratatui::style::{Color, Style};
13//! use ratatui::text::Span;
14//! use ratatui_toolkit::statusline_stacked::{StatusLineStacked, SLANT_BL_TR, SLANT_TL_BR};
15//!
16//! StatusLineStacked::new()
17//!     .start(
18//!         Span::from(" STATUS ").style(Style::new().fg(Color::Black).bg(Color::DarkGray)),
19//!         Span::from(SLANT_TL_BR).style(Style::new().fg(Color::DarkGray).bg(Color::Green)),
20//!     )
21//!     .start(
22//!         Span::from(" OPERATIONAL ").style(Style::new().fg(Color::Black).bg(Color::Green)),
23//!         Span::from(SLANT_TL_BR).style(Style::new().fg(Color::Green)),
24//!     )
25//!     .center("Some status message...")
26//!     .end(
27//!         Span::from(" INFO ").style(Style::new().fg(Color::Black).bg(Color::Cyan)),
28//!         Span::from(SLANT_BL_TR).style(Style::new().fg(Color::Cyan)),
29//!     );
30//! ```
31
32pub mod constructors;
33pub mod methods;
34pub mod traits;
35
36use ratatui::style::Style;
37use ratatui::text::Line;
38use std::marker::PhantomData;
39
40/// PowerLine block cut at the diagonal (top-left to bottom-right).
41/// Requires a Nerd Font or PowerLine font.
42pub const SLANT_TL_BR: &str = "\u{e0b8}";
43
44/// PowerLine block cut at the diagonal (bottom-left to top-right).
45/// Requires a Nerd Font or PowerLine font.
46pub const SLANT_BL_TR: &str = "\u{e0ba}";
47
48/// Statusline with stacked indicators on the left and right side.
49///
50/// This widget creates a statusline with a "stacked" appearance using
51/// PowerLine-style diagonal separators. It has three sections:
52/// - Left: Stack indicators from left to right
53/// - Center: Centered status message
54/// - Right: Stack indicators from right to left
55#[derive(Debug, Clone)]
56pub struct StatusLineStacked<'a> {
57    style: Style,
58    left: Vec<(Line<'a>, Line<'a>)>,
59    center_margin: u16,
60    center: Line<'a>,
61    right: Vec<(Line<'a>, Line<'a>)>,
62    phantom: PhantomData<&'a ()>,
63}
64
65/// Operational mode for styled statusline
66#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
67pub enum OperationalMode {
68    /// Normal operation (green)
69    #[default]
70    Operational,
71    /// Warning state (yellow)
72    Dire,
73    /// Critical state (red)
74    Evacuate,
75}
76
77/// Builder for creating a styled statusline that looks like rat-salsa's menu_status2.
78///
79/// This provides a pre-configured statusline with the "Westinghouse" reactor-control aesthetic.
80pub struct StyledStatusLine<'a> {
81    mode: OperationalMode,
82    title: &'a str,
83    center_text: String,
84    render_count: usize,
85    event_count: usize,
86    render_time_us: u64,
87    event_time_us: u64,
88    message_count: u32,
89    use_slants: bool,
90}