refactor: use THEME for all colors, add theme fields, fix forge installer
This commit is contained in:
1 parent
eeb4333b94
commit
d4ffcca61c
12 files changed
+134
-36
No files matched your search
+12
-2
@@ -16,5 +16,15 @@ foreground = "white"
|
|||||||
border_focused = "white"
|
border_focused = "white"
|
||||||
border_unfocused = "darkgray"
|
border_unfocused = "darkgray"
|
||||||
row_highlight = "yellow"
|
row_highlight = "yellow"
|
||||||
row_background = "darkgray"
|
row_background = "#1a1a1a"
|
||||||
row_alternate_bg = "#282828"
|
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"
|
||||||
@@ -118,6 +118,32 @@ pub struct Colors {
|
|||||||
pub row_background: Color,
|
pub row_background: Color,
|
||||||
#[serde(deserialize_with = "deserialize_color")]
|
#[serde(deserialize_with = "deserialize_color")]
|
||||||
pub row_alternate_bg: 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 {
|
impl Default for Colors {
|
||||||
@@ -130,10 +156,60 @@ impl Default for Colors {
|
|||||||
row_highlight: Color::White,
|
row_highlight: Color::White,
|
||||||
row_background: Color::Reset,
|
row_background: Color::Reset,
|
||||||
row_alternate_bg: 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 {
|
pub fn parse_color(color: &str) -> Color {
|
||||||
match color.to_lowercase().as_str() {
|
match color.to_lowercase().as_str() {
|
||||||
"black" => Color::Black,
|
"black" => Color::Black,
|
||||||
|
|||||||
+3
-3
@@ -142,8 +142,8 @@ pub async fn download_forge_installer(
|
|||||||
|
|
||||||
/// Run the Forge installer JAR to install Forge into the instance directory.
|
/// Run the Forge installer JAR to install Forge into the instance directory.
|
||||||
///
|
///
|
||||||
/// Requires a Java runtime. The installer is invoked with `--installClient` pointing
|
/// Requires a Java runtime. The installer is invoked with `--installClient` from
|
||||||
/// at the instance's `.minecraft` subdirectory.
|
/// the instance directory.
|
||||||
pub async fn run_forge_installer(
|
pub async fn run_forge_installer(
|
||||||
installer_path: &Path,
|
installer_path: &Path,
|
||||||
instance_dir: &Path,
|
instance_dir: &Path,
|
||||||
@@ -157,7 +157,7 @@ pub async fn run_forge_installer(
|
|||||||
.arg("-jar")
|
.arg("-jar")
|
||||||
.arg(installer_path)
|
.arg(installer_path)
|
||||||
.arg("--installClient")
|
.arg("--installClient")
|
||||||
.arg(instance_dir.join(".minecraft"))
|
.current_dir(instance_dir)
|
||||||
.output()
|
.output()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
|
|||||||
+1
-1
@@ -185,7 +185,7 @@ pub async fn run_neoforge_installer(
|
|||||||
.arg("-jar")
|
.arg("-jar")
|
||||||
.arg(installer_path)
|
.arg(installer_path)
|
||||||
.arg("--installClient")
|
.arg("--installClient")
|
||||||
.arg(instance_dir.join(".minecraft"))
|
.current_dir(instance_dir)
|
||||||
.output()
|
.output()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
|
|||||||
+4
-2
@@ -398,6 +398,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn sync_error_effects(&mut self, events: &[error_buffer::ErrorEvent]) {
|
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();
|
let active_ids: std::collections::HashSet<u64> = events.iter().map(|event| event.id).collect();
|
||||||
self.error_effects.retain(|id, _| active_ids.contains(id));
|
self.error_effects.retain(|id, _| active_ids.contains(id));
|
||||||
|
|
||||||
@@ -407,7 +408,7 @@ impl App {
|
|||||||
Motion::RightToLeft,
|
Motion::RightToLeft,
|
||||||
8,
|
8,
|
||||||
0,
|
0,
|
||||||
ratatui::style::Color::Reset,
|
THEME.colors.popup_bg,
|
||||||
(300, Interpolation::SineOut),
|
(300, Interpolation::SineOut),
|
||||||
))
|
))
|
||||||
});
|
});
|
||||||
@@ -421,6 +422,7 @@ impl App {
|
|||||||
event: &error_buffer::ErrorEvent,
|
event: &error_buffer::ErrorEvent,
|
||||||
elapsed_ms: u128,
|
elapsed_ms: u128,
|
||||||
) {
|
) {
|
||||||
|
use crate::tui::theme::THEME;
|
||||||
const FADE_OUT_MS: u128 = 500;
|
const FADE_OUT_MS: u128 = 500;
|
||||||
let fade_start_ms = error_buffer::AUTO_DISMISS_MS.saturating_sub(FADE_OUT_MS);
|
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);
|
let entry = self.error_effects.entry(event.id).or_insert(ErrorEffectState::Idle);
|
||||||
if !matches!(entry, ErrorEffectState::FadingOut(_)) {
|
if !matches!(entry, ErrorEffectState::FadingOut(_)) {
|
||||||
*entry = ErrorEffectState::FadingOut(tachyonfx::fx::fade_to_fg(
|
*entry = ErrorEffectState::FadingOut(tachyonfx::fx::fade_to_fg(
|
||||||
ratatui::style::Color::DarkGray,
|
THEME.colors.fade_to,
|
||||||
(FADE_OUT_MS as u32, Interpolation::SineIn),
|
(FADE_OUT_MS as u32, Interpolation::SineIn),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::Rect,
|
layout::Rect,
|
||||||
style::{Color, Style},
|
style::Style,
|
||||||
widgets::{Block, BorderType, Borders, Paragraph},
|
widgets::{Block, BorderType, Borders, Paragraph},
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::tui::layout::FocusedArea;
|
use crate::tui::layout::FocusedArea;
|
||||||
|
use crate::tui::theme::THEME;
|
||||||
|
|
||||||
use super::styled_title;
|
use super::styled_title;
|
||||||
|
|
||||||
pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea) {
|
pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea) {
|
||||||
let color = if focused == FocusedArea::Account {
|
let color = if focused == FocusedArea::Account {
|
||||||
Color::White
|
THEME.colors.border_focused
|
||||||
} else {
|
} else {
|
||||||
Color::DarkGray
|
THEME.colors.border_unfocused
|
||||||
};
|
};
|
||||||
|
|
||||||
let block = Block::default()
|
let block = Block::default()
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::Rect,
|
layout::Rect,
|
||||||
style::{Color, Style},
|
style::Style,
|
||||||
widgets::{Block, BorderType, Borders, Paragraph},
|
widgets::{Block, BorderType, Borders, Paragraph},
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::tui::layout::FocusedArea;
|
use crate::tui::layout::FocusedArea;
|
||||||
|
use crate::tui::theme::THEME;
|
||||||
|
|
||||||
use super::styled_title;
|
use super::styled_title;
|
||||||
|
|
||||||
pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea) {
|
pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea) {
|
||||||
let color = if focused == FocusedArea::Content {
|
let color = if focused == FocusedArea::Content {
|
||||||
Color::White
|
THEME.colors.border_focused
|
||||||
} else {
|
} else {
|
||||||
Color::DarkGray
|
THEME.colors.border_unfocused
|
||||||
};
|
};
|
||||||
|
|
||||||
let block = Block::default()
|
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) {
|
pub fn title(frame: &mut Frame, area: Rect, focused: FocusedArea) {
|
||||||
let color = if focused == FocusedArea::Content {
|
let color = if focused == FocusedArea::Content {
|
||||||
Color::White
|
THEME.colors.border_focused
|
||||||
} else {
|
} else {
|
||||||
Color::DarkGray
|
THEME.colors.border_unfocused
|
||||||
};
|
};
|
||||||
|
|
||||||
let block = Block::default()
|
let block = Block::default()
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::Rect,
|
layout::Rect,
|
||||||
style::{Color, Style},
|
style::Style,
|
||||||
widgets::{Block, BorderType, Borders, Paragraph},
|
widgets::{Block, BorderType, Borders, Paragraph},
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::tui::layout::FocusedArea;
|
use crate::tui::layout::FocusedArea;
|
||||||
|
use crate::tui::theme::THEME;
|
||||||
|
|
||||||
use super::styled_title;
|
use super::styled_title;
|
||||||
|
|
||||||
pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea) {
|
pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea) {
|
||||||
let color = if focused == FocusedArea::Details {
|
let color = if focused == FocusedArea::Details {
|
||||||
Color::White
|
THEME.colors.border_focused
|
||||||
} else {
|
} else {
|
||||||
Color::DarkGray
|
THEME.colors.border_unfocused
|
||||||
};
|
};
|
||||||
|
|
||||||
let block = Block::default()
|
let block = Block::default()
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
use crossterm::event::KeyEvent;
|
use crossterm::event::KeyEvent;
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
style::{Color, Style},
|
style::Style,
|
||||||
text::{Line, Span},
|
text::{Line, Span},
|
||||||
};
|
};
|
||||||
|
use crate::tui::theme::THEME;
|
||||||
|
|
||||||
pub mod account;
|
pub mod account;
|
||||||
pub mod content;
|
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 first = chars.next().unwrap_or_default().to_string();
|
||||||
let rest: String = chars.collect();
|
let rest: String = chars.collect();
|
||||||
Line::from(vec![
|
Line::from(vec![
|
||||||
Span::styled(first, Style::default().fg(Color::Yellow)),
|
Span::styled(first, Style::default().fg(THEME.colors.accent)),
|
||||||
Span::raw(rest),
|
Span::raw(rest),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use ratatui::{
|
use ratatui::{
|
||||||
buffer::Buffer,
|
buffer::Buffer,
|
||||||
layout::Rect,
|
layout::Rect,
|
||||||
style::{Color, Modifier, Style},
|
style::{Modifier, Style},
|
||||||
text::{Line, Span},
|
text::{Line, Span},
|
||||||
widgets::{Paragraph, Widget, Wrap},
|
widgets::{Paragraph, Widget, Wrap},
|
||||||
};
|
};
|
||||||
@@ -24,15 +24,15 @@ impl ErrorPopup {
|
|||||||
impl Widget for ErrorPopup {
|
impl Widget for ErrorPopup {
|
||||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||||
let (border_color, label) = match self.event.level {
|
let (border_color, label) = match self.event.level {
|
||||||
Level::ERROR => (Color::Red, "ERROR"),
|
Level::ERROR => (THEME.colors.error, "ERROR"),
|
||||||
Level::WARN => (Color::Yellow, "WARN"),
|
Level::WARN => (THEME.colors.warn, "WARN"),
|
||||||
_ => (THEME.colors.border_focused, "INFO"),
|
_ => (THEME.colors.border_focused, "INFO"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let title = Line::from(vec![Span::styled(
|
let title = Line::from(vec![Span::styled(
|
||||||
format!(" {} ", label),
|
format!(" {} ", label),
|
||||||
Style::default()
|
Style::default()
|
||||||
.fg(Color::Black)
|
.fg(THEME.colors.badge_text)
|
||||||
.bg(border_color)
|
.bg(border_color)
|
||||||
.add_modifier(Modifier::BOLD),
|
.add_modifier(Modifier::BOLD),
|
||||||
)]);
|
)]);
|
||||||
@@ -41,7 +41,7 @@ impl Widget for ErrorPopup {
|
|||||||
let popup = PopupFrame {
|
let popup = PopupFrame {
|
||||||
title,
|
title,
|
||||||
border_color,
|
border_color,
|
||||||
bg: None,
|
bg: Some(THEME.colors.popup_bg),
|
||||||
keybinds: None,
|
keybinds: None,
|
||||||
search_line: None,
|
search_line: None,
|
||||||
content: Box::new(move |inner, buf| {
|
content: Box::new(move |inner, buf| {
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ pub fn render(frame: &mut Frame, area: Rect, _focused: FocusedArea) {
|
|||||||
let popup = PopupFrame {
|
let popup = PopupFrame {
|
||||||
title: wizard_title(&snapshot),
|
title: wizard_title(&snapshot),
|
||||||
border_color: THEME.colors.border_focused,
|
border_color: THEME.colors.border_focused,
|
||||||
bg: None,
|
bg: Some(THEME.colors.popup_bg),
|
||||||
keybinds: Some(keybinds),
|
keybinds: Some(keybinds),
|
||||||
search_line,
|
search_line,
|
||||||
content: Box::new(move |popup_area, buf| {
|
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) => {
|
LoadState::Error(message) => {
|
||||||
Paragraph::new(message.as_str())
|
Paragraph::new(message.as_str())
|
||||||
.wrap(Wrap { trim: true })
|
.wrap(Wrap { trim: true })
|
||||||
.style(Style::default().fg(ratatui::style::Color::Red))
|
.style(Style::default().fg(THEME.colors.error))
|
||||||
.render(area, buf);
|
.render(area, buf);
|
||||||
}
|
}
|
||||||
LoadState::Loaded(_) => {
|
LoadState::Loaded(_) => {
|
||||||
@@ -588,7 +588,7 @@ fn render_loader_version_step(
|
|||||||
LoadState::Error(message) => {
|
LoadState::Error(message) => {
|
||||||
Paragraph::new(message.as_str())
|
Paragraph::new(message.as_str())
|
||||||
.wrap(Wrap { trim: true })
|
.wrap(Wrap { trim: true })
|
||||||
.style(Style::default().fg(ratatui::style::Color::Red))
|
.style(Style::default().fg(THEME.colors.error))
|
||||||
.render(area, buf);
|
.render(area, buf);
|
||||||
}
|
}
|
||||||
LoadState::Loaded(versions) => {
|
LoadState::Loaded(versions) => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::{Constraint, Layout, Rect},
|
layout::{Constraint, Layout, Rect},
|
||||||
style::{Color, Modifier, Style},
|
style::{Modifier, Style},
|
||||||
text::Span,
|
text::Span,
|
||||||
widgets::{Block, BorderType, Borders, Gauge, Paragraph},
|
widgets::{Block, BorderType, Borders, Gauge, Paragraph},
|
||||||
Frame,
|
Frame,
|
||||||
@@ -20,9 +20,9 @@ pub fn render(
|
|||||||
throbber_state: &mut ThrobberState,
|
throbber_state: &mut ThrobberState,
|
||||||
) {
|
) {
|
||||||
let border_color = if focused == FocusedArea::Status {
|
let border_color = if focused == FocusedArea::Status {
|
||||||
Color::White
|
THEME.colors.border_focused
|
||||||
} else {
|
} else {
|
||||||
Color::DarkGray
|
THEME.colors.border_unfocused
|
||||||
};
|
};
|
||||||
|
|
||||||
let block = Block::default()
|
let block = Block::default()
|
||||||
@@ -34,14 +34,20 @@ pub fn render(
|
|||||||
let state = match PROGRESS.lock() {
|
let state = match PROGRESS.lock() {
|
||||||
Ok(s) => s.clone(),
|
Ok(s) => s.clone(),
|
||||||
Err(_) => {
|
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);
|
frame.render_widget(idle.block(block), area);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if state.current_action.is_none() {
|
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);
|
frame.render_widget(idle.block(block), area);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -70,8 +76,8 @@ pub fn render(
|
|||||||
let gauge = Gauge::default()
|
let gauge = Gauge::default()
|
||||||
.gauge_style(
|
.gauge_style(
|
||||||
Style::default()
|
Style::default()
|
||||||
.fg(Color::Green)
|
.fg(THEME.colors.progress_fill)
|
||||||
.bg(Color::DarkGray)
|
.bg(THEME.colors.progress_track)
|
||||||
.add_modifier(Modifier::BOLD),
|
.add_modifier(Modifier::BOLD),
|
||||||
)
|
)
|
||||||
.percent(pct);
|
.percent(pct);
|
||||||
|
|||||||
Reference in new issue
Block a user