feat: Initial support for custom user-defined themes

This commit is contained in:
2025-03-04 18:09:09 -07:00
parent 847de75713
commit 5cb60c317d
11 changed files with 582 additions and 67 deletions
+17 -9
View File
@@ -1,22 +1,30 @@
use crate::ui::styles::ManagarrStyle;
use crate::ui::THEME;
use ratatui::layout::{Alignment, Constraint, Layout, Rect};
use ratatui::style::{Color, Style, Stylize};
use ratatui::style::{Style, Stylize};
use ratatui::symbols;
use ratatui::text::{Line, Span, Text};
use ratatui::widgets::{Block, BorderType, Borders, LineGauge, ListItem, Paragraph, Wrap};
pub const COLOR_TEAL: Color = Color::Rgb(35, 50, 55);
#[cfg(test)]
#[path = "utils_tests.rs"]
mod utils_tests;
pub fn background_block<'a>() -> Block<'a> {
Block::new().white().bg(COLOR_TEAL)
THEME.with(|theme| {
let background = theme.get().background.unwrap();
if background.enabled.unwrap() {
Block::new().white().bg(background.color.unwrap())
} else {
Block::new().white()
}
})
}
pub fn layout_block<'a>() -> Block<'a> {
Block::new()
.default()
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
}
@@ -30,11 +38,11 @@ pub fn layout_block_top_border_with_title(title_span: Span<'_>) -> Block<'_> {
}
pub fn layout_block_top_border<'a>() -> Block<'a> {
Block::new().borders(Borders::TOP)
Block::new().borders(Borders::TOP).default()
}
pub fn layout_block_bottom_border<'a>() -> Block<'a> {
Block::new().borders(Borders::BOTTOM)
Block::new().borders(Borders::BOTTOM).default()
}
pub fn layout_paragraph_borderless(string: &str) -> Paragraph<'_> {
@@ -47,7 +55,7 @@ pub fn layout_paragraph_borderless(string: &str) -> Paragraph<'_> {
}
pub fn borderless_block<'a>() -> Block<'a> {
Block::new()
Block::new().default()
}
pub fn style_block_highlight(is_selected: bool) -> Style {
@@ -98,7 +106,7 @@ pub fn centered_rect(percent_x: u16, percent_y: u16, area: Rect) -> Rect {
pub fn line_gauge_with_title(title: &str, ratio: f64) -> LineGauge<'_> {
LineGauge::new()
.block(Block::new().title(title))
.filled_style(Style::new().cyan())
.filled_style(Style::new().primary())
.line_set(symbols::line::THICK)
.ratio(ratio)
.label(Line::from(format!("{:.0}%", ratio * 100.0)))
@@ -107,7 +115,7 @@ pub fn line_gauge_with_title(title: &str, ratio: f64) -> LineGauge<'_> {
pub fn line_gauge_with_label(title: &str, ratio: f64) -> LineGauge<'_> {
LineGauge::new()
.block(Block::new())
.filled_style(Style::new().cyan())
.filled_style(Style::new().primary())
.line_set(symbols::line::THICK)
.ratio(ratio)
.label(Line::from(format!("{title}: {:.0}%", ratio * 100.0)))