From d4ffcca61cc7bfe0f299814fe67d0798d3a99aa3 Mon Sep 17 00:00:00 2001 From: objz Date: Sat, 4 Oct 2025 19:15:38 +0200 Subject: [PATCH] refactor: use THEME for all colors, add theme fields, fix forge installer --- assets/default.toml | 24 +++++--- src/config/types.rs | 76 ++++++++++++++++++++++++++ src/net/forge.rs | 6 +- src/net/neoforge.rs | 2 +- src/tui/layout.rs | 6 +- src/tui/widgets/account.rs | 7 ++- src/tui/widgets/content.rs | 11 ++-- src/tui/widgets/details.rs | 7 ++- src/tui/widgets/mod.rs | 5 +- src/tui/widgets/popups/error.rs | 10 ++-- src/tui/widgets/popups/new_instance.rs | 6 +- src/tui/widgets/status.rs | 20 ++++--- 12 files changed, 139 insertions(+), 41 deletions(-) diff --git a/assets/default.toml b/assets/default.toml index ed9e9a3..08458cc 100644 --- a/assets/default.toml +++ b/assets/default.toml @@ -11,10 +11,20 @@ memory_min = "512M" memory_max = "2G" [colors] -background = "#1e1e1e" -foreground = "white" -border_focused = "white" -border_unfocused = "darkgray" -row_highlight = "yellow" -row_background = "darkgray" -row_alternate_bg = "#282828" +background = "#1e1e1e" +foreground = "white" +border_focused = "white" +border_unfocused = "darkgray" +row_highlight = "yellow" +row_background = "#1a1a1a" +row_alternate_bg = "#242424" +popup_bg = "#1e1e1e" +error = "red" +warn = "yellow" +success = "green" +accent = "yellow" +text_idle = "darkgray" +progress_fill = "green" +progress_track = "darkgray" +badge_text = "black" +fade_to = "darkgray" diff --git a/src/config/types.rs b/src/config/types.rs index 8707de8..bfcd449 100644 --- a/src/config/types.rs +++ b/src/config/types.rs @@ -118,6 +118,32 @@ pub struct Colors { pub row_background: Color, #[serde(deserialize_with = "deserialize_color")] pub row_alternate_bg: Color, + #[serde(deserialize_with = "deserialize_color", default = "default_popup_bg")] + pub popup_bg: Color, + #[serde(deserialize_with = "deserialize_color", default = "default_error")] + pub error: Color, + #[serde(deserialize_with = "deserialize_color", default = "default_warn")] + pub warn: Color, + #[serde(deserialize_with = "deserialize_color", default = "default_success")] + pub success: Color, + #[serde(deserialize_with = "deserialize_color", default = "default_accent")] + pub accent: Color, + #[serde(deserialize_with = "deserialize_color", default = "default_text_idle")] + pub text_idle: Color, + #[serde( + deserialize_with = "deserialize_color", + default = "default_progress_fill" + )] + pub progress_fill: Color, + #[serde( + deserialize_with = "deserialize_color", + default = "default_progress_track" + )] + pub progress_track: Color, + #[serde(deserialize_with = "deserialize_color", default = "default_badge_text")] + pub badge_text: Color, + #[serde(deserialize_with = "deserialize_color", default = "default_fade_to")] + pub fade_to: Color, } impl Default for Colors { @@ -130,10 +156,60 @@ impl Default for Colors { row_highlight: Color::White, row_background: Color::Reset, row_alternate_bg: Color::Reset, + popup_bg: default_popup_bg(), + error: default_error(), + warn: default_warn(), + success: default_success(), + accent: default_accent(), + text_idle: default_text_idle(), + progress_fill: default_progress_fill(), + progress_track: default_progress_track(), + badge_text: default_badge_text(), + fade_to: default_fade_to(), } } } +fn default_popup_bg() -> Color { + Color::Rgb(0x1e, 0x1e, 0x1e) +} + +fn default_error() -> Color { + Color::Red +} + +fn default_warn() -> Color { + Color::Yellow +} + +fn default_success() -> Color { + Color::Green +} + +fn default_accent() -> Color { + Color::Yellow +} + +fn default_text_idle() -> Color { + Color::DarkGray +} + +fn default_progress_fill() -> Color { + Color::Green +} + +fn default_progress_track() -> Color { + Color::DarkGray +} + +fn default_badge_text() -> Color { + Color::Black +} + +fn default_fade_to() -> Color { + Color::DarkGray +} + pub fn parse_color(color: &str) -> Color { match color.to_lowercase().as_str() { "black" => Color::Black, diff --git a/src/net/forge.rs b/src/net/forge.rs index 7dea791..0e68613 100644 --- a/src/net/forge.rs +++ b/src/net/forge.rs @@ -142,8 +142,8 @@ pub async fn download_forge_installer( /// Run the Forge installer JAR to install Forge into the instance directory. /// -/// Requires a Java runtime. The installer is invoked with `--installClient` pointing -/// at the instance's `.minecraft` subdirectory. +/// Requires a Java runtime. The installer is invoked with `--installClient` from +/// the instance directory. pub async fn run_forge_installer( installer_path: &Path, instance_dir: &Path, @@ -157,7 +157,7 @@ pub async fn run_forge_installer( .arg("-jar") .arg(installer_path) .arg("--installClient") - .arg(instance_dir.join(".minecraft")) + .current_dir(instance_dir) .output() .await { diff --git a/src/net/neoforge.rs b/src/net/neoforge.rs index 60f9c48..332d54a 100644 --- a/src/net/neoforge.rs +++ b/src/net/neoforge.rs @@ -185,7 +185,7 @@ pub async fn run_neoforge_installer( .arg("-jar") .arg(installer_path) .arg("--installClient") - .arg(instance_dir.join(".minecraft")) + .current_dir(instance_dir) .output() .await { diff --git a/src/tui/layout.rs b/src/tui/layout.rs index 0ecbe2b..9821f4f 100644 --- a/src/tui/layout.rs +++ b/src/tui/layout.rs @@ -398,6 +398,7 @@ impl App { } fn sync_error_effects(&mut self, events: &[error_buffer::ErrorEvent]) { + use crate::tui::theme::THEME; let active_ids: std::collections::HashSet = events.iter().map(|event| event.id).collect(); self.error_effects.retain(|id, _| active_ids.contains(id)); @@ -407,7 +408,7 @@ impl App { Motion::RightToLeft, 8, 0, - ratatui::style::Color::Reset, + THEME.colors.popup_bg, (300, Interpolation::SineOut), )) }); @@ -421,6 +422,7 @@ impl App { event: &error_buffer::ErrorEvent, elapsed_ms: u128, ) { + use crate::tui::theme::THEME; const FADE_OUT_MS: u128 = 500; let fade_start_ms = error_buffer::AUTO_DISMISS_MS.saturating_sub(FADE_OUT_MS); @@ -428,7 +430,7 @@ impl App { let entry = self.error_effects.entry(event.id).or_insert(ErrorEffectState::Idle); if !matches!(entry, ErrorEffectState::FadingOut(_)) { *entry = ErrorEffectState::FadingOut(tachyonfx::fx::fade_to_fg( - ratatui::style::Color::DarkGray, + THEME.colors.fade_to, (FADE_OUT_MS as u32, Interpolation::SineIn), )); } diff --git a/src/tui/widgets/account.rs b/src/tui/widgets/account.rs index f471590..aa2bc1d 100644 --- a/src/tui/widgets/account.rs +++ b/src/tui/widgets/account.rs @@ -1,19 +1,20 @@ use ratatui::{ layout::Rect, - style::{Color, Style}, + style::Style, widgets::{Block, BorderType, Borders, Paragraph}, Frame, }; use crate::tui::layout::FocusedArea; +use crate::tui::theme::THEME; use super::styled_title; pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea) { let color = if focused == FocusedArea::Account { - Color::White + THEME.colors.border_focused } else { - Color::DarkGray + THEME.colors.border_unfocused }; let block = Block::default() diff --git a/src/tui/widgets/content.rs b/src/tui/widgets/content.rs index 9fb9e76..e3c92ef 100644 --- a/src/tui/widgets/content.rs +++ b/src/tui/widgets/content.rs @@ -1,19 +1,20 @@ use ratatui::{ layout::Rect, - style::{Color, Style}, + style::Style, widgets::{Block, BorderType, Borders, Paragraph}, Frame, }; use crate::tui::layout::FocusedArea; +use crate::tui::theme::THEME; use super::styled_title; pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea) { let color = if focused == FocusedArea::Content { - Color::White + THEME.colors.border_focused } else { - Color::DarkGray + THEME.colors.border_unfocused }; let block = Block::default() @@ -28,9 +29,9 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea) { pub fn title(frame: &mut Frame, area: Rect, focused: FocusedArea) { let color = if focused == FocusedArea::Content { - Color::White + THEME.colors.border_focused } else { - Color::DarkGray + THEME.colors.border_unfocused }; let block = Block::default() diff --git a/src/tui/widgets/details.rs b/src/tui/widgets/details.rs index d9468ac..bc68d7d 100644 --- a/src/tui/widgets/details.rs +++ b/src/tui/widgets/details.rs @@ -1,19 +1,20 @@ use ratatui::{ layout::Rect, - style::{Color, Style}, + style::Style, widgets::{Block, BorderType, Borders, Paragraph}, Frame, }; use crate::tui::layout::FocusedArea; +use crate::tui::theme::THEME; use super::styled_title; pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea) { let color = if focused == FocusedArea::Details { - Color::White + THEME.colors.border_focused } else { - Color::DarkGray + THEME.colors.border_unfocused }; let block = Block::default() diff --git a/src/tui/widgets/mod.rs b/src/tui/widgets/mod.rs index f3c34bd..f9da06a 100644 --- a/src/tui/widgets/mod.rs +++ b/src/tui/widgets/mod.rs @@ -1,8 +1,9 @@ use crossterm::event::KeyEvent; use ratatui::{ - style::{Color, Style}, + style::Style, text::{Line, Span}, }; +use crate::tui::theme::THEME; pub mod account; pub mod content; @@ -20,7 +21,7 @@ pub fn styled_title(title: &str, highlight: bool) -> Line<'_> { let first = chars.next().unwrap_or_default().to_string(); let rest: String = chars.collect(); Line::from(vec![ - Span::styled(first, Style::default().fg(Color::Yellow)), + Span::styled(first, Style::default().fg(THEME.colors.accent)), Span::raw(rest), ]) } diff --git a/src/tui/widgets/popups/error.rs b/src/tui/widgets/popups/error.rs index 8843aad..5613442 100644 --- a/src/tui/widgets/popups/error.rs +++ b/src/tui/widgets/popups/error.rs @@ -1,7 +1,7 @@ use ratatui::{ buffer::Buffer, layout::Rect, - style::{Color, Modifier, Style}, + style::{Modifier, Style}, text::{Line, Span}, widgets::{Paragraph, Widget, Wrap}, }; @@ -24,15 +24,15 @@ impl ErrorPopup { impl Widget for ErrorPopup { fn render(self, area: Rect, buf: &mut Buffer) { let (border_color, label) = match self.event.level { - Level::ERROR => (Color::Red, "ERROR"), - Level::WARN => (Color::Yellow, "WARN"), + Level::ERROR => (THEME.colors.error, "ERROR"), + Level::WARN => (THEME.colors.warn, "WARN"), _ => (THEME.colors.border_focused, "INFO"), }; let title = Line::from(vec![Span::styled( format!(" {} ", label), Style::default() - .fg(Color::Black) + .fg(THEME.colors.badge_text) .bg(border_color) .add_modifier(Modifier::BOLD), )]); @@ -41,7 +41,7 @@ impl Widget for ErrorPopup { let popup = PopupFrame { title, border_color, - bg: None, + bg: Some(THEME.colors.popup_bg), keybinds: None, search_line: None, content: Box::new(move |inner, buf| { diff --git a/src/tui/widgets/popups/new_instance.rs b/src/tui/widgets/popups/new_instance.rs index a55ba2d..8cd37ce 100644 --- a/src/tui/widgets/popups/new_instance.rs +++ b/src/tui/widgets/popups/new_instance.rs @@ -152,7 +152,7 @@ pub fn render(frame: &mut Frame, area: Rect, _focused: FocusedArea) { let popup = PopupFrame { title: wizard_title(&snapshot), border_color: THEME.colors.border_focused, - bg: None, + bg: Some(THEME.colors.popup_bg), keybinds: Some(keybinds), search_line, content: Box::new(move |popup_area, buf| { @@ -511,7 +511,7 @@ fn render_version_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffe LoadState::Error(message) => { Paragraph::new(message.as_str()) .wrap(Wrap { trim: true }) - .style(Style::default().fg(ratatui::style::Color::Red)) + .style(Style::default().fg(THEME.colors.error)) .render(area, buf); } LoadState::Loaded(_) => { @@ -588,7 +588,7 @@ fn render_loader_version_step( LoadState::Error(message) => { Paragraph::new(message.as_str()) .wrap(Wrap { trim: true }) - .style(Style::default().fg(ratatui::style::Color::Red)) + .style(Style::default().fg(THEME.colors.error)) .render(area, buf); } LoadState::Loaded(versions) => { diff --git a/src/tui/widgets/status.rs b/src/tui/widgets/status.rs index 4354a2d..9a4f049 100644 --- a/src/tui/widgets/status.rs +++ b/src/tui/widgets/status.rs @@ -1,6 +1,6 @@ use ratatui::{ layout::{Constraint, Layout, Rect}, - style::{Color, Modifier, Style}, + style::{Modifier, Style}, text::Span, widgets::{Block, BorderType, Borders, Gauge, Paragraph}, Frame, @@ -20,9 +20,9 @@ pub fn render( throbber_state: &mut ThrobberState, ) { let border_color = if focused == FocusedArea::Status { - Color::White + THEME.colors.border_focused } else { - Color::DarkGray + THEME.colors.border_unfocused }; let block = Block::default() @@ -34,14 +34,20 @@ pub fn render( let state = match PROGRESS.lock() { Ok(s) => s.clone(), Err(_) => { - let idle = Paragraph::new(Span::styled("Ready", Style::default().fg(Color::DarkGray))); + let idle = Paragraph::new(Span::styled( + "Ready", + Style::default().fg(THEME.colors.text_idle), + )); frame.render_widget(idle.block(block), area); return; } }; if state.current_action.is_none() { - let idle = Paragraph::new(Span::styled("Ready", Style::default().fg(Color::DarkGray))); + let idle = Paragraph::new(Span::styled( + "Ready", + Style::default().fg(THEME.colors.text_idle), + )); frame.render_widget(idle.block(block), area); return; } @@ -70,8 +76,8 @@ pub fn render( let gauge = Gauge::default() .gauge_style( Style::default() - .fg(Color::Green) - .bg(Color::DarkGray) + .fg(THEME.colors.progress_fill) + .bg(THEME.colors.progress_track) .add_modifier(Modifier::BOLD), ) .percent(pct);