refactor: use THEME for all colors, add theme fields, fix forge installer

This commit is contained in:
objz committed 2025-10-04 19:15:38 +02:00
1 parent eeb4333b94
commit d4ffcca61c
12 files changed
+139 -41

No files matched your search

+17 -7
View File
@@ -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"
+76
View File
@@ -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,
+3 -3
View File
@@ -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
{
+1 -1
View File
@@ -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
{
+4 -2
View File
@@ -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<u64> = 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),
));
}
+4 -3
View File
@@ -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()
+6 -5
View File
@@ -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()
+4 -3
View File
@@ -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()
+3 -2
View File
@@ -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),
])
}
+5 -5
View File
@@ -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| {
+3 -3
View File
@@ -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) => {
+13 -7
View File
@@ -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);