use ratatui::{
layout::Rect,
style::{Color, Modifier, Style},
text::{Line, Span},
widgets::{Block, BorderType, Borders},
};
use serde::{Deserialize, Serialize};
use std::sync::atomic::{AtomicU8, Ordering};
use std::sync::OnceLock;
use std::time::{Duration, Instant};
static THEME: OnceLock<ThemeConfig> = OnceLock::new();
pub fn theme() -> &'static ThemeConfig {
THEME.get_or_init(ThemeConfig::default)
}
pub fn init_theme(config: ThemeConfig) {
let _ = THEME.set(config);
}
static DIM_FACTOR: AtomicU8 = AtomicU8::new(0);
pub fn dim_theme(factor: f32) {
let clamped = (factor.clamp(0.0, 1.0) * 255.0) as u8;
DIM_FACTOR.store(clamped, Ordering::Relaxed);
}
pub fn restore_theme() {
DIM_FACTOR.store(0, Ordering::Relaxed);
}
pub fn get_dim() -> f32 {
DIM_FACTOR.load(Ordering::Relaxed) as f32 / 255.0
}
fn apply_dim(color: Color) -> Color {
let factor = get_dim();
if factor == 0.0 {
return color;
}
dim_color_by(color, factor)
}
fn dim_color_by(color: Color, factor: f32) -> Color {
match color {
Color::Rgb(r, g, b) => {
let inv = 1.0 - factor;
Color::Rgb(
(r as f32 * inv) as u8,
(g as f32 * inv) as u8,
(b as f32 * inv) as u8,
)
}
_ => color,
}
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct RgbColor {
pub r: u8,
pub g: u8,
pub b: u8,
}
impl RgbColor {
pub const fn new(r: u8, g: u8, b: u8) -> Self {
Self { r, g, b }
}
pub fn to_color(self) -> Color {
Color::Rgb(self.r, self.g, self.b)
}
}
impl From<RgbColor> for Color {
fn from(rgb: RgbColor) -> Self {
rgb.to_color()
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ThemeConfig {
#[serde(default)]
pub accent: AccentColors,
#[serde(default)]
pub neon: NeonColors,
#[serde(default)]
pub background: BackgroundColors,
#[serde(default)]
pub text: TextColors,
#[serde(default)]
pub border: BorderColors,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AccentColors {
#[serde(default = "default_accent")]
pub primary: RgbColor,
#[serde(default = "default_accent_dim")]
pub dim: RgbColor,
#[serde(default = "default_accent_bright")]
pub bright: RgbColor,
}
impl Default for AccentColors {
fn default() -> Self {
Self {
primary: default_accent(),
dim: default_accent_dim(),
bright: default_accent_bright(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NeonColors {
#[serde(default = "default_neon_green")]
pub green: RgbColor,
#[serde(default = "default_neon_amber")]
pub amber: RgbColor,
#[serde(default = "default_neon_red")]
pub red: RgbColor,
#[serde(default = "default_neon_purple")]
pub purple: RgbColor,
#[serde(default = "default_neon_cyan")]
pub cyan: RgbColor,
#[serde(default = "default_neon_pink")]
pub pink: RgbColor,
#[serde(default = "default_electric_blue")]
pub electric_blue: RgbColor,
}
impl Default for NeonColors {
fn default() -> Self {
Self {
green: default_neon_green(),
amber: default_neon_amber(),
red: default_neon_red(),
purple: default_neon_purple(),
cyan: default_neon_cyan(),
pink: default_neon_pink(),
electric_blue: default_electric_blue(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BackgroundColors {
#[serde(default = "default_bg_deep")]
pub deep: RgbColor,
#[serde(default = "default_bg_panel")]
pub panel: RgbColor,
#[serde(default = "default_bg_surface")]
pub surface: RgbColor,
#[serde(default = "default_bg_selected")]
pub selected: RgbColor,
#[serde(default = "default_bg_elevated")]
pub elevated: RgbColor,
#[serde(default = "default_bg_hover")]
pub hover: RgbColor,
}
impl Default for BackgroundColors {
fn default() -> Self {
Self {
deep: default_bg_deep(),
panel: default_bg_panel(),
surface: default_bg_surface(),
selected: default_bg_selected(),
elevated: default_bg_elevated(),
hover: default_bg_hover(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TextColors {
#[serde(default = "default_text_dim")]
pub dim: RgbColor,
#[serde(default = "default_text_secondary")]
pub secondary: RgbColor,
#[serde(default = "default_text_primary")]
pub primary: RgbColor,
#[serde(default = "default_text_bright")]
pub bright: RgbColor,
}
impl Default for TextColors {
fn default() -> Self {
Self {
dim: default_text_dim(),
secondary: default_text_secondary(),
primary: default_text_primary(),
bright: default_text_bright(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BorderColors {
#[serde(default = "default_border_dim")]
pub dim: RgbColor,
#[serde(default = "default_border_active")]
pub active: RgbColor,
}
impl Default for BorderColors {
fn default() -> Self {
Self {
dim: default_border_dim(),
active: default_border_active(),
}
}
}
fn default_accent() -> RgbColor {
RgbColor::new(80, 200, 220)
}
fn default_accent_dim() -> RgbColor {
RgbColor::new(60, 150, 170)
}
fn default_accent_bright() -> RgbColor {
RgbColor::new(100, 220, 240)
}
fn default_neon_green() -> RgbColor {
RgbColor::new(57, 255, 20)
}
fn default_neon_amber() -> RgbColor {
RgbColor::new(255, 191, 0)
}
fn default_neon_red() -> RgbColor {
RgbColor::new(255, 80, 80)
}
fn default_neon_purple() -> RgbColor {
RgbColor::new(160, 100, 220)
}
fn default_neon_cyan() -> RgbColor {
RgbColor::new(0, 255, 255)
}
fn default_neon_pink() -> RgbColor {
RgbColor::new(255, 100, 150)
}
fn default_electric_blue() -> RgbColor {
RgbColor::new(80, 180, 255)
}
fn default_bg_deep() -> RgbColor {
RgbColor::new(12, 14, 22)
}
fn default_bg_panel() -> RgbColor {
RgbColor::new(18, 21, 32)
}
fn default_bg_surface() -> RgbColor {
RgbColor::new(26, 30, 44)
}
fn default_bg_selected() -> RgbColor {
RgbColor::new(35, 45, 65)
}
fn default_bg_elevated() -> RgbColor {
RgbColor::new(40, 50, 70)
}
fn default_bg_hover() -> RgbColor {
RgbColor::new(45, 55, 75)
}
fn default_text_dim() -> RgbColor {
RgbColor::new(90, 100, 120)
}
fn default_text_secondary() -> RgbColor {
RgbColor::new(140, 150, 170)
}
fn default_text_primary() -> RgbColor {
RgbColor::new(210, 215, 230)
}
fn default_text_bright() -> RgbColor {
RgbColor::new(245, 248, 255)
}
fn default_border_dim() -> RgbColor {
RgbColor::new(50, 58, 78)
}
fn default_border_active() -> RgbColor {
RgbColor::new(80, 200, 220)
}
#[allow(non_snake_case)]
pub fn ACCENT() -> Color {
apply_dim(theme().accent.primary.to_color())
}
#[allow(non_snake_case)]
pub fn ACCENT_DIM() -> Color {
apply_dim(theme().accent.dim.to_color())
}
#[allow(non_snake_case)]
pub fn ACCENT_BRIGHT() -> Color {
apply_dim(theme().accent.bright.to_color())
}
#[allow(non_snake_case)]
pub fn NEON_GREEN() -> Color {
apply_dim(theme().neon.green.to_color())
}
#[allow(non_snake_case)]
pub fn NEON_AMBER() -> Color {
apply_dim(theme().neon.amber.to_color())
}
#[allow(non_snake_case)]
pub fn NEON_RED() -> Color {
apply_dim(theme().neon.red.to_color())
}
#[allow(non_snake_case)]
pub fn NEON_PURPLE() -> Color {
apply_dim(theme().neon.purple.to_color())
}
#[allow(non_snake_case)]
pub fn NEON_CYAN() -> Color {
apply_dim(theme().neon.cyan.to_color())
}
#[allow(non_snake_case)]
pub fn NEON_PINK() -> Color {
apply_dim(theme().neon.pink.to_color())
}
#[allow(non_snake_case)]
pub fn ELECTRIC_BLUE() -> Color {
apply_dim(theme().neon.electric_blue.to_color())
}
#[allow(non_snake_case)]
pub fn BG_DEEP() -> Color {
apply_dim(theme().background.deep.to_color())
}
#[allow(non_snake_case)]
pub fn BG_PANEL() -> Color {
apply_dim(theme().background.panel.to_color())
}
#[allow(non_snake_case)]
pub fn BG_SURFACE() -> Color {
apply_dim(theme().background.surface.to_color())
}
#[allow(non_snake_case)]
pub fn BG_SELECTED() -> Color {
apply_dim(theme().background.selected.to_color())
}
#[allow(non_snake_case)]
pub fn BG_ELEVATED() -> Color {
apply_dim(theme().background.elevated.to_color())
}
#[allow(non_snake_case)]
pub fn BG_HOVER() -> Color {
apply_dim(theme().background.hover.to_color())
}
#[allow(non_snake_case)]
pub fn TEXT_DIM() -> Color {
apply_dim(theme().text.dim.to_color())
}
#[allow(non_snake_case)]
pub fn TEXT_SECONDARY() -> Color {
apply_dim(theme().text.secondary.to_color())
}
#[allow(non_snake_case)]
pub fn TEXT_PRIMARY() -> Color {
apply_dim(theme().text.primary.to_color())
}
#[allow(non_snake_case)]
pub fn TEXT_BRIGHT() -> Color {
apply_dim(theme().text.bright.to_color())
}
#[allow(non_snake_case)]
pub fn BORDER_DIM() -> Color {
apply_dim(theme().border.dim.to_color())
}
#[allow(non_snake_case)]
pub fn BORDER_ACTIVE() -> Color {
apply_dim(theme().border.active.to_color())
}
pub mod raw {
use super::*;
#[allow(non_snake_case)]
pub fn ACCENT() -> Color {
theme().accent.primary.to_color()
}
#[allow(non_snake_case)]
pub fn ACCENT_DIM() -> Color {
theme().accent.dim.to_color()
}
#[allow(non_snake_case)]
pub fn ACCENT_BRIGHT() -> Color {
theme().accent.bright.to_color()
}
#[allow(non_snake_case)]
pub fn NEON_GREEN() -> Color {
theme().neon.green.to_color()
}
#[allow(non_snake_case)]
pub fn NEON_AMBER() -> Color {
theme().neon.amber.to_color()
}
#[allow(non_snake_case)]
pub fn NEON_RED() -> Color {
theme().neon.red.to_color()
}
#[allow(non_snake_case)]
pub fn NEON_PURPLE() -> Color {
theme().neon.purple.to_color()
}
#[allow(non_snake_case)]
pub fn NEON_CYAN() -> Color {
theme().neon.cyan.to_color()
}
#[allow(non_snake_case)]
pub fn NEON_PINK() -> Color {
theme().neon.pink.to_color()
}
#[allow(non_snake_case)]
pub fn ELECTRIC_BLUE() -> Color {
theme().neon.electric_blue.to_color()
}
#[allow(non_snake_case)]
pub fn BG_DEEP() -> Color {
theme().background.deep.to_color()
}
#[allow(non_snake_case)]
pub fn BG_PANEL() -> Color {
theme().background.panel.to_color()
}
#[allow(non_snake_case)]
pub fn BG_SURFACE() -> Color {
theme().background.surface.to_color()
}
#[allow(non_snake_case)]
pub fn BG_SELECTED() -> Color {
theme().background.selected.to_color()
}
#[allow(non_snake_case)]
pub fn BG_ELEVATED() -> Color {
theme().background.elevated.to_color()
}
#[allow(non_snake_case)]
pub fn BG_HOVER() -> Color {
theme().background.hover.to_color()
}
#[allow(non_snake_case)]
pub fn TEXT_DIM() -> Color {
theme().text.dim.to_color()
}
#[allow(non_snake_case)]
pub fn TEXT_SECONDARY() -> Color {
theme().text.secondary.to_color()
}
#[allow(non_snake_case)]
pub fn TEXT_PRIMARY() -> Color {
theme().text.primary.to_color()
}
#[allow(non_snake_case)]
pub fn TEXT_BRIGHT() -> Color {
theme().text.bright.to_color()
}
#[allow(non_snake_case)]
pub fn BORDER_DIM() -> Color {
theme().border.dim.to_color()
}
#[allow(non_snake_case)]
pub fn BORDER_ACTIVE() -> Color {
theme().border.active.to_color()
}
pub fn modal_block(title: impl Into<String>) -> Block<'static> {
let title_str = title.into();
Block::default()
.title(format!(" {} ", title_str))
.title_style(
Style::default()
.fg(TEXT_BRIGHT())
.add_modifier(Modifier::BOLD),
)
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(BORDER_DIM()))
.style(Style::default().bg(BG_DEEP()))
}
pub fn input_block(label: impl Into<String>, is_focused: bool) -> Block<'static> {
let label_str = label.into();
if is_focused {
Block::default()
.title(format!(" {} ", label_str))
.title_style(
Style::default()
.fg(ACCENT_BRIGHT())
.add_modifier(Modifier::BOLD),
)
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(ACCENT()))
} else {
Block::default()
.title(format!(" {} ", label_str))
.title_style(Style::default().fg(TEXT_DIM()))
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(BORDER_DIM()))
}
}
pub fn form_title() -> Style {
Style::default()
.fg(NEON_CYAN())
.add_modifier(Modifier::BOLD)
}
pub fn form_hint() -> Style {
Style::default().fg(TEXT_DIM())
}
pub fn form_error() -> Style {
Style::default().fg(NEON_RED())
}
pub fn form_note() -> Style {
Style::default()
.fg(TEXT_DIM())
.add_modifier(Modifier::ITALIC)
}
pub fn input_text() -> Style {
Style::default().fg(TEXT_PRIMARY())
}
pub fn keybind_key_style() -> Style {
Style::default().fg(NEON_AMBER())
}
pub fn selector_option_selected(is_field_active: bool) -> Style {
if is_field_active {
Style::default()
.fg(BG_DEEP())
.bg(ACCENT())
.add_modifier(Modifier::BOLD)
} else {
Style::default()
.fg(BG_DEEP())
.bg(TEXT_SECONDARY())
.add_modifier(Modifier::BOLD)
}
}
pub fn selector_option_unselected(is_field_active: bool) -> Style {
if is_field_active {
Style::default().fg(ACCENT_DIM())
} else {
Style::default().fg(TEXT_DIM())
}
}
}
#[derive(Clone, Copy)]
pub struct GradientColors {
pub start: (u8, u8, u8),
pub end: (u8, u8, u8),
}
const GRADIENT_PRESETS: &[GradientColors] = &[
GradientColors {
start: (0, 230, 255),
end: (60, 160, 255),
},
GradientColors {
start: (0, 230, 240),
end: (0, 180, 200),
},
GradientColors {
start: (100, 180, 255),
end: (180, 130, 255),
},
GradientColors {
start: (0, 200, 200),
end: (80, 220, 255),
},
GradientColors {
start: (160, 140, 255),
end: (220, 130, 200),
},
GradientColors {
start: (80, 220, 180),
end: (0, 200, 230),
},
GradientColors {
start: (80, 160, 255),
end: (0, 220, 240),
},
GradientColors {
start: (230, 140, 200),
end: (160, 120, 230),
},
];
#[derive(Clone)]
pub struct AnimationState {
pub start_time: Instant,
pub gradient: GradientColors,
}
impl Default for AnimationState {
fn default() -> Self {
let seed = Instant::now().elapsed().as_nanos() as usize;
let gradient = GRADIENT_PRESETS[seed % GRADIENT_PRESETS.len()];
Self {
start_time: Instant::now(),
gradient,
}
}
}
impl AnimationState {
pub fn new() -> Self {
Self::default()
}
pub fn elapsed(&self) -> Duration {
self.start_time.elapsed()
}
pub fn pulse(&self, period_ms: u64) -> f32 {
let elapsed_ms = self.elapsed().as_millis() as f32;
let period = period_ms as f32;
((elapsed_ms / period * std::f32::consts::PI * 2.0).sin() + 1.0) / 2.0
}
pub fn cycle(&self, period_ms: u64) -> f32 {
let elapsed_ms = self.elapsed().as_millis() as u64;
(elapsed_ms % period_ms) as f32 / period_ms as f32
}
pub fn frame(&self, frame_count: usize, period_ms: u64) -> usize {
let elapsed_ms = self.elapsed().as_millis() as u64;
((elapsed_ms / period_ms) as usize) % frame_count
}
}
pub const SPINNER_FRAMES: [&str; 8] = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧"];
pub const SPINNER_DOTS: [&str; 4] = ["⣾", "⣽", "⣻", "⢿"];
pub const SPINNER_PULSE: [&str; 4] = ["◐", "◓", "◑", "◒"];
pub fn spinner(animation: &AnimationState) -> &'static str {
let frame = animation.frame(SPINNER_FRAMES.len(), 100);
SPINNER_FRAMES[frame]
}
pub fn spinner_dots(animation: &AnimationState) -> &'static str {
let frame = animation.frame(SPINNER_DOTS.len(), 150);
SPINNER_DOTS[frame]
}
pub fn spinner_pulse(animation: &AnimationState) -> &'static str {
let frame = animation.frame(SPINNER_PULSE.len(), 250);
SPINNER_PULSE[frame]
}
pub const INDICATOR_CONNECTED: &str = "●";
pub const INDICATOR_CONNECTING: &str = "◐";
pub const INDICATOR_DISCONNECTED: &str = "○";
pub const INDICATOR_ERROR: &str = "✕";
use ratatui::widgets::{Scrollbar, ScrollbarOrientation};
pub fn scrollbar(is_active: bool) -> Scrollbar<'static> {
Scrollbar::new(ScrollbarOrientation::VerticalRight)
.begin_symbol(Some("▲"))
.end_symbol(Some("▼"))
.track_symbol(Some("│"))
.thumb_symbol("█")
.style(Style::default().fg(if is_active {
ACCENT_DIM()
} else {
BORDER_DIM()
}))
}
pub fn scrollbar_area(content_area: Rect) -> Rect {
Rect::new(
content_area.x + content_area.width.saturating_sub(1),
content_area.y,
1,
content_area.height,
)
}
pub fn border_inactive() -> Style {
Style::default().fg(BORDER_DIM())
}
pub fn border_focused() -> Style {
Style::default().fg(BORDER_ACTIVE())
}
pub fn border_active(_animation: &AnimationState) -> Style {
border_focused()
}
pub fn status_connected() -> Style {
Style::default().fg(NEON_GREEN())
}
pub fn status_connecting(animation: &AnimationState) -> Style {
let pulse = animation.pulse(800);
let intensity = (180.0 + 75.0 * pulse) as u8;
Style::default().fg(Color::Rgb(255, intensity, 0))
}
pub fn status_error() -> Style {
Style::default().fg(NEON_RED())
}
pub fn status_disconnected() -> Style {
Style::default().fg(TEXT_DIM())
}
pub fn panel_block(_title: impl Into<String>, _is_active: bool) -> Block<'static> {
Block::default()
.borders(Borders::NONE)
.padding(ratatui::widgets::Padding::new(1, 1, 0, 0))
}
pub fn render_panel_header(
f: &mut ratatui::Frame,
area: Rect,
title: &str,
is_active: bool,
) -> Rect {
render_panel_header_split(f, area, title, "", is_active)
}
pub fn render_panel_header_split(
f: &mut ratatui::Frame,
area: Rect,
title_left: &str,
title_right: &str,
is_active: bool,
) -> Rect {
let header_area = Rect::new(area.x, area.y, area.width, 1);
let content_area = Rect::new(
area.x,
area.y + 1,
area.width,
area.height.saturating_sub(1),
);
let (bg_color, fg_color, right_fg) = if is_active {
(ACCENT(), BG_DEEP(), BG_DEEP())
} else {
(BG_SURFACE(), TEXT_SECONDARY(), TEXT_DIM())
};
let width = area.width as usize;
let left_content = format!(" {} ", title_left);
let left_len = left_content.chars().count();
let right_content = if title_right.is_empty() {
String::new()
} else {
format!("{} ", title_right)
};
let right_len = right_content.chars().count();
let padding = width.saturating_sub(left_len + right_len);
let mut spans = vec![
Span::styled(
left_content,
Style::default()
.fg(fg_color)
.bg(bg_color)
.add_modifier(Modifier::BOLD),
),
Span::styled(" ".repeat(padding), Style::default().bg(bg_color)),
];
if !title_right.is_empty() {
spans.push(Span::styled(
right_content,
Style::default().fg(right_fg).bg(bg_color),
));
}
let header =
ratatui::widgets::Paragraph::new(Line::from(spans)).style(Style::default().bg(bg_color));
f.render_widget(header, header_area);
content_area
}
pub fn themed_block(title: impl Into<String>, is_active: bool) -> Block<'static> {
panel_block(title, is_active)
}
pub fn animated_block(
title: impl Into<String>,
is_active: bool,
_animation: &AnimationState,
) -> Block<'static> {
panel_block(title, is_active)
}
pub fn modal_block(title: impl Into<String>) -> Block<'static> {
let title_str = title.into();
Block::default()
.title(format!(" {} ", title_str))
.title_style(
Style::default()
.fg(TEXT_BRIGHT())
.add_modifier(Modifier::BOLD),
)
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(BORDER_DIM()))
.style(Style::default().bg(BG_DEEP()))
}
pub fn glass_block(title: impl Into<String>) -> Block<'static> {
modal_block(title)
}
pub fn confirm_block(title: impl Into<String>) -> Block<'static> {
modal_block(title)
}
pub fn list_selected() -> Style {
Style::default().bg(BG_SELECTED())
}
pub fn list_highlight() -> Style {
Style::default()
.bg(BG_ELEVATED())
.add_modifier(Modifier::BOLD)
}
pub fn list_hover() -> Style {
Style::default().bg(BG_HOVER())
}
pub fn text_highlight() -> Style {
Style::default()
.fg(ACCENT_BRIGHT())
.add_modifier(Modifier::BOLD)
}
#[derive(Clone, Copy)]
pub struct PaneSplit {
pub ratio: f32,
pub min: f32,
pub max: f32,
pub resizing: bool,
}
impl Default for PaneSplit {
fn default() -> Self {
Self {
ratio: 0.4,
min: 0.2,
max: 0.8,
resizing: false,
}
}
}
impl PaneSplit {
pub fn new(ratio: f32) -> Self {
Self {
ratio: ratio.clamp(0.2, 0.8),
..Default::default()
}
}
pub fn adjust(&mut self, delta: f32) {
self.ratio = (self.ratio + delta).clamp(self.min, self.max);
}
pub fn left_percent(&self) -> u16 {
(self.ratio * 100.0) as u16
}
pub fn right_percent(&self) -> u16 {
100 - self.left_percent()
}
pub fn is_on_handle(&self, area: Rect, x: u16) -> bool {
let split_x = area.x + (area.width as f32 * self.ratio) as u16;
x >= split_x.saturating_sub(1) && x <= split_x.saturating_add(1)
}
}
pub fn keybind(key: &str, description: &str) -> Vec<Span<'static>> {
vec![
Span::styled(
format!(" {} ", key),
Style::default()
.fg(BG_DEEP())
.bg(ACCENT())
.add_modifier(Modifier::BOLD),
),
Span::styled(
format!(" {} ", description),
Style::default().fg(TEXT_SECONDARY()),
),
]
}
pub fn keybind_subtle(key: &str, description: &str) -> Vec<Span<'static>> {
vec![
Span::styled(key.to_string(), Style::default().fg(NEON_AMBER())),
Span::styled(
format!(" {} ", description),
Style::default().fg(TEXT_DIM()),
),
]
}
pub fn keybind_key_style() -> Style {
Style::default().fg(NEON_AMBER())
}
pub const LOGO: &[&str] = &[
"███╗ ███╗███████╗███╗ ███╗████████╗██╗ ██╗██╗",
"████╗ ████║██╔════╝████╗ ████║╚══██╔══╝██║ ██║██║",
"██╔████╔██║█████╗ ██╔████╔██║ ██║ ██║ ██║██║",
"██║╚██╔╝██║██╔══╝ ██║╚██╔╝██║ ██║ ██║ ██║██║",
"██║ ╚═╝ ██║███████╗██║ ╚═╝ ██║ ██║ ╚██████╔╝██║",
"╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝",
];
pub const LOGO_COMPACT: &[&str] = &["┏┳┓┏━╸┏┳┓╺┳╸╻ ╻╻", "┃┃┃┣╸ ┃┃┃ ┃ ┃ ┃┃", "╹ ╹┗━╸╹ ╹ ╹ ┗━┛╹"];
pub fn logo_lines(animation: &AnimationState) -> Vec<Line<'static>> {
let cycle = animation.cycle(5000);
let gradient = &animation.gradient;
LOGO.iter()
.map(|line| {
let char_count = line.chars().count() as f32;
let chars: Vec<Span<'static>> = line
.chars()
.enumerate()
.map(|(char_idx, ch)| {
if ch == ' ' {
return Span::styled(ch.to_string(), Style::default());
}
let pos = char_idx as f32 / char_count;
let wave = ((pos * std::f32::consts::PI * 2.0)
- (cycle * std::f32::consts::PI * 2.0))
.sin();
let t = (wave + 1.0) / 2.0;
let r = (gradient.start.0 as f32
+ (gradient.end.0 as f32 - gradient.start.0 as f32) * t)
as u8;
let g = (gradient.start.1 as f32
+ (gradient.end.1 as f32 - gradient.start.1 as f32) * t)
as u8;
let b = (gradient.start.2 as f32
+ (gradient.end.2 as f32 - gradient.start.2 as f32) * t)
as u8;
let color = apply_dim(Color::Rgb(r, g, b));
Span::styled(
ch.to_string(),
Style::default().fg(color).add_modifier(Modifier::BOLD),
)
})
.collect();
Line::from(chars)
})
.collect()
}
pub fn input_block(label: impl Into<String>, is_focused: bool) -> Block<'static> {
let label_str = label.into();
if is_focused {
Block::default()
.title(format!(" {} ", label_str))
.title_style(
Style::default()
.fg(ACCENT_BRIGHT())
.add_modifier(Modifier::BOLD),
)
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(ACCENT()))
} else {
Block::default()
.title(format!(" {} ", label_str))
.title_style(Style::default().fg(TEXT_DIM()))
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(BORDER_DIM()))
}
}
pub fn input_text() -> Style {
Style::default().fg(TEXT_PRIMARY())
}
pub fn input_placeholder() -> Style {
Style::default().fg(TEXT_DIM())
}
pub fn selector_option_selected(is_field_active: bool) -> Style {
if is_field_active {
Style::default()
.fg(BG_DEEP())
.bg(ACCENT())
.add_modifier(Modifier::BOLD)
} else {
Style::default()
.fg(BG_DEEP())
.bg(TEXT_SECONDARY())
.add_modifier(Modifier::BOLD)
}
}
pub fn selector_option_unselected(is_field_active: bool) -> Style {
if is_field_active {
Style::default().fg(ACCENT_DIM())
} else {
Style::default().fg(TEXT_DIM())
}
}
pub fn form_title() -> Style {
Style::default()
.fg(NEON_CYAN())
.add_modifier(Modifier::BOLD)
}
pub fn form_hint() -> Style {
Style::default().fg(TEXT_DIM())
}
pub fn form_error() -> Style {
Style::default().fg(NEON_RED())
}
pub fn form_note() -> Style {
Style::default()
.fg(TEXT_DIM())
.add_modifier(Modifier::ITALIC)
}
pub fn util_bg() -> Style {
Style::default().bg(BG_PANEL())
}
pub fn tab_active() -> Style {
Style::default()
.fg(BG_DEEP())
.bg(ACCENT_DIM())
.add_modifier(Modifier::BOLD)
}
pub fn tab_inactive_bg() -> Color {
BG_PANEL()
}
pub fn status_indicator_connected() -> (&'static str, Style) {
(INDICATOR_CONNECTED, Style::default().fg(NEON_GREEN()))
}
pub fn status_indicator_connecting() -> (&'static str, Style) {
(INDICATOR_CONNECTING, Style::default().fg(NEON_AMBER()))
}
pub fn status_indicator_disconnected() -> (&'static str, Style) {
(INDICATOR_DISCONNECTED, Style::default().fg(TEXT_DIM()))
}
pub fn status_indicator_error() -> (&'static str, Style) {
(INDICATOR_ERROR, Style::default().fg(NEON_RED()))
}
pub fn status_hint() -> Style {
Style::default().fg(TEXT_DIM())
}
pub fn status_operation() -> Style {
Style::default().fg(NEON_CYAN())
}
pub fn message_warning() -> (Style, Style) {
let style = Style::default().fg(NEON_AMBER());
let bg = Style::default().bg(Color::Rgb(35, 30, 15));
(style, bg)
}
pub fn message_error() -> (Style, Style) {
let style = Style::default().fg(NEON_RED());
let bg = Style::default().bg(Color::Rgb(35, 15, 15));
(style, bg)
}
pub fn message_info() -> (Style, Style) {
let style = Style::default().fg(NEON_CYAN());
let bg = Style::default().bg(Color::Rgb(15, 25, 35));
(style, bg)
}
pub fn message_success() -> (Style, Style) {
let style = Style::default().fg(NEON_GREEN());
let bg = Style::default().bg(Color::Rgb(15, 35, 20));
(style, bg)
}
use ratatui::layout::{Constraint, Direction, Layout};
pub fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
let popup_layout = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Percentage((100 - percent_y) / 2),
Constraint::Percentage(percent_y),
Constraint::Percentage((100 - percent_y) / 2),
])
.split(r);
Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Percentage((100 - percent_x) / 2),
Constraint::Percentage(percent_x),
Constraint::Percentage((100 - percent_x) / 2),
])
.split(popup_layout[1])[1]
}
pub fn centered_rect_fixed(width: u16, height: u16, r: Rect) -> Rect {
let x = r.x + r.width.saturating_sub(width) / 2;
let y = r.y + r.height.saturating_sub(height) / 2;
Rect::new(x, y, width.min(r.width), height.min(r.height))
}
pub fn separator_line(width: u16) -> Line<'static> {
let bar = "─".repeat(width as usize);
Line::from(Span::styled(bar, Style::default().fg(BORDER_DIM())))
}