feat(theme): add palette system and per-element theming

This commit is contained in:
objz committed 2026-01-24 19:18:09 +01:00
1 parent ecc2b2bb23
commit 80210364d5
40 files changed
+2900 -1120

No files matched your search

-3
View File
@@ -6,9 +6,6 @@ use std::time::Instant;
use once_cell::sync::Lazy;
use tracing::Level;
pub const AUTO_DISMISS_MS: u128 = 5000;
pub const SLIDE_START_MS: u128 = 3500;
const MAX_ERROR_EVENTS: usize = 50;
static NEXT_ERROR_ID: AtomicU64 = AtomicU64::new(1);
+87 -58
View File
@@ -6,8 +6,8 @@ use super::{
use crate::instance::{InstanceConfig, InstanceManager};
use crate::tui::error_buffer;
use crate::tui::progress;
use crate::tui::widgets::popups::confirm::{confirm_popup_area, ConfirmPopup};
use crate::tui::widgets::popups::confirm as confirm_popup;
use crate::tui::widgets::popups::confirm::{confirm_popup_area, ConfirmPopup};
use crate::tui::widgets::popups::error::{popup_area, ErrorPopup};
use color_eyre::eyre::Context;
use crossterm::event::{self, Event};
@@ -150,7 +150,7 @@ impl App {
if self.throbber_tick % 8 == 0 {
self.throbber_state.calc_next();
}
terminal.draw(|frame| self.render_frame(frame))?;
self.handle_events().wrap_err("handle events failed")?;
@@ -212,7 +212,12 @@ impl App {
])
.split(main_chunks[2]);
widgets::account::render(frame, bottom_chunks[0], self.focused, &mut self.account_state);
widgets::account::render(
frame,
bottom_chunks[0],
self.focused,
&mut self.account_state,
);
widgets::details::render(
frame,
bottom_chunks[1],
@@ -220,7 +225,12 @@ impl App {
self.profiles_state.selected_instance(),
&self.instance_manager.instances_dir,
);
widgets::status::render(frame, bottom_chunks[2], self.focused, &mut self.throbber_state);
widgets::status::render(
frame,
bottom_chunks[2],
self.focused,
&mut self.throbber_state,
);
if self.focused == FocusedArea::OverviewExpanded {
self.render_log_overlay(frame);
@@ -257,18 +267,16 @@ impl App {
fn handle_events(&mut self) -> color_eyre::Result<()> {
match crossterm::event::poll(Duration::from_millis(16)) {
Ok(true) => {
match event::read() {
Ok(Event::Key(key_event)) if key_event.kind == KeyEventKind::Press => self
.handle_key_event(key_event)
.wrap_err_with(|| format!("handling key event failed:\n{key_event:#?}")),
Ok(_) => Ok(()),
Err(e) => {
tracing::error!("Event read error: {}", e);
Ok(())
}
Ok(true) => match event::read() {
Ok(Event::Key(key_event)) if key_event.kind == KeyEventKind::Press => self
.handle_key_event(key_event)
.wrap_err_with(|| format!("handling key event failed:\n{key_event:#?}")),
Ok(_) => Ok(()),
Err(e) => {
tracing::error!("Event read error: {}", e);
Ok(())
}
}
},
Ok(false) => Ok(()),
Err(e) => {
tracing::error!("Event poll error: {}", e);
@@ -363,17 +371,11 @@ impl App {
return Ok(());
}
} else if self.content_tab == widgets::content::ContentTab::Screenshots {
if widgets::screenshots_grid::handle_key(
&key_event,
&mut self.screenshots_state,
) {
if widgets::screenshots_grid::handle_key(&key_event, &mut self.screenshots_state) {
return Ok(());
}
} else if self.content_tab == widgets::content::ContentTab::Worlds {
if widgets::content_list::handle_key_no_toggle(
&key_event,
&mut self.worlds_state,
) {
if widgets::content_list::handle_key_no_toggle(&key_event, &mut self.worlds_state) {
return Ok(());
}
} else {
@@ -427,7 +429,12 @@ impl App {
let old_name = inst.name.clone();
match self.instance_manager.rename(&old_name, &new_name) {
Ok(()) => {
if let Some(inst) = self.profiles_state.instances.iter_mut().find(|i| i.name == old_name) {
if let Some(inst) = self
.profiles_state
.instances
.iter_mut()
.find(|i| i.name == old_name)
{
inst.name = new_name.trim().to_string();
}
}
@@ -496,7 +503,9 @@ impl App {
&& key_event.modifiers.contains(KeyModifiers::SHIFT) =>
{
if let Some(instance) = self.profiles_state.selected_instance() {
let dir = self.instance_manager.instances_dir
let dir = self
.instance_manager
.instances_dir
.join(&instance.name)
.join(".minecraft");
if let Err(e) = std::process::Command::new("xdg-open")
@@ -601,7 +610,9 @@ impl App {
fn run_editor(terminal: &mut ratatui::DefaultTerminal, path: &std::path::Path) {
use ratatui::crossterm::{
terminal::{disable_raw_mode, enable_raw_mode, LeaveAlternateScreen, EnterAlternateScreen},
terminal::{
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen,
},
ExecutableCommand,
};
use std::io::stdout;
@@ -612,7 +623,17 @@ impl App {
let is_tui_editor = matches!(
editor.rsplit('/').next().unwrap_or(&editor),
"vi" | "vim" | "nvim" | "neovim" | "nano" | "micro" | "helix" | "hx" | "emacs" | "ne" | "joe" | "mcedit"
"vi" | "vim"
| "nvim"
| "neovim"
| "nano"
| "micro"
| "helix"
| "hx"
| "emacs"
| "ne"
| "joe"
| "mcedit"
);
if is_tui_editor {
@@ -666,9 +687,13 @@ impl App {
}
fn dismiss_expired_errors(&self) {
use crate::config::SETTINGS;
loop {
match error_buffer::peek_error() {
Some(event) if event.pushed_at.elapsed().as_millis() >= error_buffer::AUTO_DISMISS_MS => {
Some(event)
if event.pushed_at.elapsed().as_millis()
>= SETTINGS.ui.error_auto_dismiss_ms as u128 =>
{
error_buffer::pop_error();
}
_ => break,
@@ -715,9 +740,7 @@ impl App {
layout::{Alignment, Margin},
style::{Modifier, Style},
text::Line,
widgets::{
Block, BorderType, Clear, Paragraph, Scrollbar, ScrollbarOrientation,
},
widgets::{Block, Clear, Paragraph, Scrollbar, ScrollbarOrientation},
};
let area = frame.area();
@@ -732,30 +755,30 @@ impl App {
.collect();
let visible_height = overlay.height.saturating_sub(2) as usize;
let was_at_bottom = self.log_overlay_scroll >= self.log_overlay_max_scroll.saturating_sub(1);
let was_at_bottom =
self.log_overlay_scroll >= self.log_overlay_max_scroll.saturating_sub(1);
self.log_overlay_max_scroll = filtered.len().saturating_sub(visible_height);
if was_at_bottom {
self.log_overlay_scroll = self.log_overlay_max_scroll;
} else if self.log_overlay_scroll > self.log_overlay_max_scroll {
if was_at_bottom || self.log_overlay_scroll > self.log_overlay_max_scroll {
self.log_overlay_scroll = self.log_overlay_max_scroll;
}
self.log_overlay_scrollbar = ratatui::widgets::ScrollbarState::new(
self.log_overlay_max_scroll,
)
.position(self.log_overlay_scroll);
self.log_overlay_scrollbar =
ratatui::widgets::ScrollbarState::new(self.log_overlay_max_scroll)
.position(self.log_overlay_scroll);
let mut block = Block::bordered()
.title_top(Line::from(" Logs ").style(
Style::default()
.fg(THEME.colors.foreground)
.add_modifier(Modifier::BOLD),
))
.title_top(
Line::from(" Logs ").style(
Style::default()
.fg(THEME.log_overlay.text_fg)
.add_modifier(Modifier::BOLD),
),
)
.title_bottom(
crate::tui::widgets::popups::keybind_line(&[("O", " close"), ("/", " search")])
.alignment(Alignment::Right),
)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(THEME.colors.border_focused));
.border_type(THEME.general.border_type.to_border_type())
.border_style(Style::default().fg(THEME.log_overlay.border_fg));
if let Some(sl) = self.log_overlay_search.title_line() {
block = block.title_top(sl);
@@ -771,13 +794,13 @@ impl App {
.take(visible_height)
.map(|line| {
let style = if line.contains("ERROR") || line.contains("FATAL") {
Style::default().fg(THEME.colors.error)
Style::default().fg(THEME.log_overlay.error_fg)
} else if line.contains("WARN") {
Style::default().fg(THEME.colors.warn)
Style::default().fg(THEME.log_overlay.warn_fg)
} else if line.contains("DEBUG") || line.contains("TRACE") {
Style::default().fg(THEME.colors.text_idle)
Style::default().fg(THEME.log_overlay.debug_fg)
} else {
Style::default().fg(THEME.colors.foreground)
Style::default().fg(THEME.log_overlay.text_fg)
};
search.highlight_line(line, style)
})
@@ -797,7 +820,7 @@ impl App {
.begin_symbol(Some("\u{25b2}"))
.style(
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.log_overlay.border_fg)
.add_modifier(Modifier::BOLD),
)
.thumb_symbol("\u{2503}")
@@ -810,7 +833,8 @@ 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();
let active_ids: std::collections::HashSet<u64> =
events.iter().map(|event| event.id).collect();
self.error_effects.retain(|id, _| active_ids.contains(id));
for event in events {
@@ -819,7 +843,7 @@ impl App {
Motion::RightToLeft,
8,
0,
THEME.colors.popup_bg,
THEME.log_overlay.bg,
(300, Interpolation::SineOut),
))
});
@@ -833,19 +857,24 @@ impl App {
event: &error_buffer::ErrorEvent,
elapsed_ms: u128,
) {
use crate::config::SETTINGS;
use crate::tui::theme::THEME;
const FLY_OUT_MS: u128 = 300;
let fly_start_ms = error_buffer::AUTO_DISMISS_MS.saturating_sub(FLY_OUT_MS);
let fly_out_ms = SETTINGS.ui.error_fly_out_ms as u128;
let fly_start_ms = SETTINGS.ui.error_auto_dismiss_ms as u128
- fly_out_ms.min(SETTINGS.ui.error_auto_dismiss_ms as u128);
if elapsed_ms >= fly_start_ms {
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(_)) {
*entry = ErrorEffectState::FadingOut(fx::slide_out(
Motion::LeftToRight,
8,
0,
THEME.colors.popup_bg,
(FLY_OUT_MS as u32, Interpolation::SineIn),
THEME.log_overlay.bg,
(fly_out_ms as u32, Interpolation::SineIn),
));
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
pub mod error_buffer;
pub mod layout;
pub mod logging;
pub mod error_buffer;
pub mod progress;
pub mod theme;
pub mod widgets;
+1515 -2
View File
File diff suppressed because it is too large. Load diff
+51 -45
View File
@@ -5,7 +5,7 @@ use ratatui::{
layout::Rect,
style::{Color, Modifier, Style},
text::{Line, Span},
widgets::{Block, BorderType, Borders, Paragraph, Widget},
widgets::{Block, Borders, Paragraph, Widget},
Frame,
};
use tui_widget_list::{ListBuilder, ListState as TuiListState, ListView};
@@ -214,15 +214,15 @@ pub fn drain_device_code(state: &mut AccountState) {
pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut AccountState) {
let color = if focused == FocusedArea::Account {
THEME.colors.border_focused
THEME.account.border_focused_fg
} else {
THEME.colors.border_unfocused
THEME.account.border_unfocused_fg
};
let mut block = Block::default()
.title(styled_title("Accounts", true))
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_type(THEME.general.border_type.to_border_type())
.border_style(Style::default().fg(color));
if focused == FocusedArea::Account {
@@ -240,7 +240,8 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut A
if state.store.accounts.is_empty() {
frame.render_widget(
Paragraph::new("No accounts.").style(Style::default().fg(THEME.colors.text_idle)),
Paragraph::new("No accounts.")
.style(Style::default().fg(THEME.account.text_secondary_fg)),
inner,
);
} else {
@@ -284,14 +285,10 @@ fn render_account_list(
let (username, acc_type, is_active) = &accounts[context.index];
let show_selected = is_focused && context.is_selected;
let stripe_bg = if context.index % 2 == 0 {
Color::Reset
} else {
THEME.colors.row_alternate_bg
};
let stripe_bg = Color::Reset;
let bg = if show_selected {
THEME.colors.row_background
THEME.account.selected_bg
} else {
stripe_bg
};
@@ -299,27 +296,33 @@ fn render_account_list(
let active_marker = if *is_active { "\u{25b8} " } else { " " };
let style = if show_selected {
Style::default()
.fg(THEME.colors.row_highlight)
.add_modifier(Modifier::BOLD)
let mut s = Style::default().fg(THEME.account.selected_fg);
if THEME.account.selected_bold {
s = s.add_modifier(Modifier::BOLD);
}
s
} else if *is_active {
Style::default()
.fg(THEME.colors.foreground)
.fg(THEME.account.text_fg)
.add_modifier(Modifier::BOLD)
} else {
Style::default().fg(THEME.colors.foreground)
Style::default().fg(THEME.account.text_fg)
};
let mut spans = vec![
Span::styled(active_marker, Style::default().fg(THEME.colors.accent)),
Span::styled(active_marker, Style::default().fg(THEME.account.active_fg)),
Span::styled(username.clone(), style),
];
if *acc_type == AccountType::Offline {
let offline_style = if show_selected {
Style::default().fg(THEME.colors.row_highlight)
let mut s = Style::default().fg(THEME.account.selected_fg);
if THEME.account.selected_bold {
s = s.add_modifier(Modifier::BOLD);
}
s
} else {
Style::default().fg(THEME.colors.text_idle)
Style::default().fg(THEME.account.text_secondary_fg)
};
spans.push(Span::styled(" (Offline)", offline_style));
}
@@ -350,11 +353,11 @@ fn render_choose_popup(frame: &mut Frame) {
PopupFrame {
title: Line::from(" Add Account ").centered(),
border_color: THEME.colors.border_focused,
border_color: THEME.account.border_focused_fg,
bg: None,
keybinds: Some(Line::from(Span::styled(
" Esc: cancel ",
Style::default().fg(THEME.colors.text_idle),
Style::default().fg(THEME.account.text_secondary_fg),
))),
search_line: None,
content: Box::new(|inner, buf| {
@@ -364,24 +367,24 @@ fn render_choose_popup(frame: &mut Frame) {
Span::styled(
" [m] ",
Style::default()
.fg(THEME.colors.accent)
.fg(THEME.account.active_fg)
.add_modifier(Modifier::BOLD),
),
Span::styled(
"Microsoft Account",
Style::default().fg(THEME.colors.foreground),
Style::default().fg(THEME.account.text_fg),
),
]),
Line::from(vec![
Span::styled(
" [o] ",
Style::default()
.fg(THEME.colors.accent)
.fg(THEME.account.active_fg)
.add_modifier(Modifier::BOLD),
),
Span::styled(
"Offline Account",
Style::default().fg(THEME.colors.foreground),
Style::default().fg(THEME.account.text_fg),
),
]),
];
@@ -400,12 +403,12 @@ fn render_offline_popup(frame: &mut Frame, name: &str) {
title: Line::from(Span::styled(
" Offline Account ",
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.account.border_focused_fg)
.add_modifier(Modifier::BOLD),
))
.centered(),
border_color: THEME.colors.border_focused,
bg: Some(THEME.colors.popup_bg),
border_color: THEME.account.border_focused_fg,
bg: Some(THEME.account.popup_bg),
keybinds: Some(keybind_line(&[("Enter", " confirm"), ("Esc", " cancel")])),
search_line: None,
content: Box::new(move |inner, buf| {
@@ -413,22 +416,22 @@ fn render_offline_popup(frame: &mut Frame, name: &str) {
Line::from(vec![
Span::styled(
"Username...",
Style::default().fg(THEME.colors.border_unfocused),
Style::default().fg(THEME.account.border_unfocused_fg),
),
Span::styled(
"\u{2588}",
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.account.border_focused_fg)
.add_modifier(Modifier::SLOW_BLINK),
),
])
} else {
Line::from(vec![
Span::styled(name.as_str(), Style::default().fg(THEME.colors.foreground)),
Span::styled(name.as_str(), Style::default().fg(THEME.account.text_fg)),
Span::styled(
"\u{2588}",
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.account.border_focused_fg)
.add_modifier(Modifier::SLOW_BLINK),
),
])
@@ -451,7 +454,7 @@ fn render_confirm_delete(frame: &mut Frame, state: &AccountState, idx: usize) {
let title = Line::from(Span::styled(
format!(" Delete '{}' ", username),
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.account.border_focused_fg)
.add_modifier(Modifier::BOLD),
));
@@ -461,13 +464,13 @@ fn render_confirm_delete(frame: &mut Frame, state: &AccountState, idx: usize) {
PopupFrame {
title,
border_color: THEME.colors.border_focused,
bg: Some(THEME.colors.row_alternate_bg),
border_color: THEME.account.border_focused_fg,
bg: Some(THEME.account.popup_bg),
keybinds: Some(keybind_line(&[("Enter", " confirm")])),
search_line: None,
content: Box::new(|inner, buf| {
Paragraph::new("This will permanently remove this account")
.style(Style::default().fg(THEME.colors.foreground))
.style(Style::default().fg(THEME.account.text_fg))
.render(inner, buf);
}),
}
@@ -484,46 +487,49 @@ fn render_device_code_popup(frame: &mut Frame, info: &DeviceCodeInfo) {
title: Line::from(Span::styled(
" Microsoft Login ",
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.account.border_focused_fg)
.add_modifier(Modifier::BOLD),
))
.centered(),
border_color: THEME.colors.border_focused,
bg: Some(THEME.colors.popup_bg),
border_color: THEME.account.border_focused_fg,
bg: Some(THEME.account.popup_bg),
keybinds: Some(keybind_line(&[("Esc", " cancel")])),
search_line: None,
content: Box::new(move |inner, buf| {
let text = if code.is_empty() {
vec![Line::from(Span::styled(
"Connecting to Microsoft...",
Style::default().fg(THEME.colors.text_idle),
Style::default().fg(THEME.account.text_secondary_fg),
))]
} else {
vec![
Line::from(Span::styled(
"Open this URL in your browser:",
Style::default().fg(THEME.colors.text_idle),
Style::default().fg(THEME.account.text_secondary_fg),
)),
Line::from(Span::styled(
uri.as_str(),
Style::default()
.fg(THEME.colors.accent)
.fg(THEME.account.active_fg)
.add_modifier(Modifier::BOLD),
)),
Line::from(""),
Line::from(vec![
Span::styled("Enter code: ", Style::default().fg(THEME.colors.text_idle)),
Span::styled(
"Enter code: ",
Style::default().fg(THEME.account.text_secondary_fg),
),
Span::styled(
code.as_str(),
Style::default()
.fg(THEME.colors.success)
.fg(THEME.account.active_fg)
.add_modifier(Modifier::BOLD),
),
]),
Line::from(""),
Line::from(Span::styled(
"Waiting for authentication...",
Style::default().fg(THEME.colors.text_idle),
Style::default().fg(THEME.account.text_secondary_fg),
)),
]
};
+29 -29
View File
@@ -2,7 +2,7 @@ use ratatui::{
layout::{Alignment, Constraint, Layout, Rect},
style::{Modifier, Style},
text::{Line, Span},
widgets::{Block, BorderType, Borders, Paragraph},
widgets::{Block, Borders, Paragraph},
Frame,
};
use throbber_widgets_tui::{Throbber, ThrobberState};
@@ -79,9 +79,9 @@ pub fn render(
let is_focused = focused == FocusedArea::Content;
let border_color = if is_focused {
THEME.colors.border_focused
THEME.content.border_focused_fg
} else {
THEME.colors.border_unfocused
THEME.content.border_unfocused_fg
};
let tab_titles: Vec<Span> = ContentTab::ALL
@@ -92,21 +92,21 @@ pub fn render(
if i > 0 {
spans.push(Span::styled(
"\u{2022}",
Style::default().fg(THEME.colors.border_unfocused),
Style::default().fg(THEME.content.border_unfocused_fg),
));
}
if i == tab.index() {
spans.push(Span::styled(
format!(" {} ", t.label()),
Style::default()
.fg(THEME.colors.accent)
.bg(THEME.colors.row_background)
.add_modifier(Modifier::BOLD),
));
let mut style = Style::default()
.fg(THEME.content.tab_active_fg)
.bg(THEME.content.selected_bg);
if THEME.content.tab_active_bold {
style = style.add_modifier(Modifier::BOLD);
}
spans.push(Span::styled(format!(" {} ", t.label()), style));
} else {
spans.push(Span::styled(
format!(" {} ", t.label()),
Style::default().fg(THEME.colors.foreground),
Style::default().fg(THEME.content.text_fg),
));
}
spans
@@ -131,7 +131,7 @@ pub fn render(
let mut block = Block::default()
.title_top(Line::from(tab_titles))
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_type(THEME.general.border_type.to_border_type())
.border_style(Style::default().fg(border_color));
if let Some(sl) = search_line {
@@ -224,7 +224,7 @@ pub fn render(
} else {
frame.render_widget(
Paragraph::new("No instance selected.")
.style(Style::default().fg(THEME.colors.text_idle)),
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
content_area,
);
}
@@ -249,7 +249,7 @@ pub fn render(
} else {
frame.render_widget(
Paragraph::new("No instance selected.")
.style(Style::default().fg(THEME.colors.text_idle)),
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
content_area,
);
}
@@ -274,7 +274,7 @@ pub fn render(
} else {
frame.render_widget(
Paragraph::new("No instance selected.")
.style(Style::default().fg(THEME.colors.text_idle)),
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
content_area,
);
}
@@ -288,7 +288,7 @@ pub fn render(
} else {
frame.render_widget(
Paragraph::new("No instance selected.")
.style(Style::default().fg(THEME.colors.text_idle)),
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
content_area,
);
}
@@ -302,7 +302,7 @@ pub fn render(
} else {
frame.render_widget(
Paragraph::new("No instance selected.")
.style(Style::default().fg(THEME.colors.text_idle)),
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
content_area,
);
}
@@ -327,7 +327,7 @@ pub fn render(
} else {
frame.render_widget(
Paragraph::new("No instance selected.")
.style(Style::default().fg(THEME.colors.text_idle)),
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
content_area,
);
}
@@ -343,15 +343,15 @@ pub fn title(
throbber_state: &mut ThrobberState,
) {
let color = if focused == FocusedArea::Content {
THEME.colors.border_focused
THEME.content.border_focused_fg
} else {
THEME.colors.border_unfocused
THEME.content.border_unfocused_fg
};
let block = Block::default()
.title(styled_title("Content", true))
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_type(THEME.general.border_type.to_border_type())
.border_style(Style::default().fg(color));
let inner = block.inner(area);
@@ -361,7 +361,7 @@ pub fn title(
None => {
frame.render_widget(
Paragraph::new("No instance selected")
.style(Style::default().fg(THEME.colors.text_idle)),
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
inner,
);
}
@@ -380,12 +380,12 @@ pub fn title(
.label(inst.name.as_str())
.style(
Style::default()
.fg(THEME.colors.foreground)
.fg(THEME.content.text_fg)
.add_modifier(Modifier::BOLD),
)
.throbber_style(
Style::default()
.fg(THEME.colors.success)
.fg(THEME.general.success)
.add_modifier(Modifier::BOLD),
)
.throbber_set(throbber_widgets_tui::BRAILLE_EIGHT_DOUBLE)
@@ -398,13 +398,13 @@ pub fn title(
Span::styled(
"\u{2717} ",
Style::default()
.fg(THEME.colors.error)
.fg(THEME.general.error)
.add_modifier(Modifier::BOLD),
),
Span::styled(
inst.name.as_str(),
Style::default()
.fg(THEME.colors.foreground)
.fg(THEME.content.text_fg)
.add_modifier(Modifier::BOLD),
),
])),
@@ -416,7 +416,7 @@ pub fn title(
Paragraph::new(Span::styled(
inst.name.as_str(),
Style::default()
.fg(THEME.colors.foreground)
.fg(THEME.content.text_fg)
.add_modifier(Modifier::BOLD),
)),
left_area,
@@ -430,7 +430,7 @@ pub fn title(
};
frame.render_widget(
Paragraph::new(loader_str)
.style(Style::default().fg(THEME.colors.border_focused))
.style(Style::default().fg(THEME.content.border_focused_fg))
.alignment(Alignment::Right),
right_area,
);
+47 -49
View File
@@ -239,11 +239,7 @@ pub fn handle_key_no_toggle(key_event: &KeyEvent, state: &mut ContentListState)
true
}
KeyCode::Enter if key_event.modifiers.contains(KeyModifiers::SHIFT) => {
if let Some(&real_idx) = state
.list_state
.selected
.and_then(|i| filtered.get(i))
{
if let Some(&real_idx) = state.list_state.selected.and_then(|i| filtered.get(i)) {
if let Some(dir) = state.entries[real_idx].path.parent() {
if let Err(e) = std::process::Command::new("xdg-open")
.arg(dir)
@@ -285,11 +281,7 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut ContentListState) -> bool {
true
}
KeyCode::Enter if key_event.modifiers.contains(KeyModifiers::SHIFT) => {
if let Some(&real_idx) = state
.list_state
.selected
.and_then(|i| filtered.get(i))
{
if let Some(&real_idx) = state.list_state.selected.and_then(|i| filtered.get(i)) {
if let Some(dir) = state.entries[real_idx].path.parent() {
if let Err(e) = std::process::Command::new("xdg-open")
.arg(dir)
@@ -304,19 +296,11 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut ContentListState) -> bool {
true
}
KeyCode::Enter => {
if let Some(&real_idx) = state
.list_state
.selected
.and_then(|i| filtered.get(i))
{
if let Some(&real_idx) = state.list_state.selected.and_then(|i| filtered.get(i)) {
state.list_state.selected = Some(real_idx);
state.toggle_selected();
state.list_state.selected = Some(
filtered
.iter()
.position(|&i| i == real_idx)
.unwrap_or(0),
);
state.list_state.selected =
Some(filtered.iter().position(|&i| i == real_idx).unwrap_or(0));
}
true
}
@@ -334,7 +318,8 @@ pub fn render(
) {
if state.loading {
frame.render_widget(
Paragraph::new(loading_text).style(Style::default().fg(THEME.colors.text_idle)),
Paragraph::new(loading_text)
.style(Style::default().fg(THEME.content_list.text_secondary_fg)),
area,
);
return;
@@ -344,7 +329,8 @@ pub fn render(
if filtered.is_empty() {
frame.render_widget(
Paragraph::new(empty_text).style(Style::default().fg(THEME.colors.text_idle)),
Paragraph::new(empty_text)
.style(Style::default().fg(THEME.content_list.text_secondary_fg)),
area,
);
return;
@@ -373,38 +359,50 @@ pub fn render(
let stripe_bg = if context.index % 2 == 0 {
Color::Reset
} else {
THEME.colors.row_alternate_bg
THEME.content_list.row_alt_bg
};
let (name_style, description_style, background) = match (*enabled, show_selected) {
(true, true) => (
Style::default()
.fg(THEME.colors.row_highlight)
.add_modifier(Modifier::BOLD),
Style::default().fg(THEME.colors.row_highlight),
THEME.colors.row_background,
),
(true, true) => {
let mut ns = Style::default().fg(THEME.content_list.selected_fg);
if THEME.content_list.selected_bold {
ns = ns.add_modifier(Modifier::BOLD);
}
(
ns,
Style::default().fg(THEME.content_list.selected_fg),
THEME.content_list.selected_bg,
)
}
(true, false) => (
Style::default()
.fg(THEME.colors.foreground)
.fg(THEME.content_list.text_fg)
.add_modifier(Modifier::BOLD),
Style::default().fg(THEME.colors.text_idle),
stripe_bg,
),
(false, true) => (
Style::default()
.fg(THEME.colors.row_highlight)
.add_modifier(Modifier::CROSSED_OUT),
Style::default().fg(THEME.colors.row_highlight),
THEME.colors.row_background,
),
(false, false) => (
Style::default()
.fg(THEME.colors.text_idle)
.add_modifier(Modifier::CROSSED_OUT),
Style::default().fg(THEME.colors.text_idle),
Style::default().fg(THEME.content_list.text_secondary_fg),
stripe_bg,
),
(false, true) => {
let mut ns = Style::default().fg(THEME.content_list.selected_fg);
if THEME.content_list.disabled_crossed_out {
ns = ns.add_modifier(Modifier::CROSSED_OUT);
}
(
ns,
Style::default().fg(THEME.content_list.selected_fg),
THEME.content_list.selected_bg,
)
}
(false, false) => {
let mut ns = Style::default().fg(THEME.content_list.text_secondary_fg);
if THEME.content_list.disabled_crossed_out {
ns = ns.add_modifier(Modifier::CROSSED_OUT);
}
(
ns,
Style::default().fg(THEME.content_list.text_secondary_fg),
stripe_bg,
)
}
};
let has_icon = icon_pixels.is_some();
@@ -488,7 +486,7 @@ pub fn render(
.begin_symbol(Some("\u{25b2}"))
.style(
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.content_list.border_focused_fg)
.add_modifier(Modifier::BOLD),
)
.thumb_symbol("\u{2551}")
@@ -599,7 +597,7 @@ fn icon_spans(icon_pixels: Option<&Vec<Vec<IconCell>>>, row: usize) -> Vec<Span<
.collect(),
None => vec![Span::styled(
" ",
Style::default().fg(THEME.colors.text_idle),
Style::default().fg(THEME.content_list.text_secondary_fg),
)],
}
}
+8 -8
View File
@@ -2,7 +2,7 @@ use ratatui::{
layout::Rect,
style::{Modifier, Style},
text::{Line, Span},
widgets::{Block, BorderType, Borders, Paragraph},
widgets::{Block, Borders, Paragraph},
Frame,
};
@@ -20,15 +20,15 @@ pub fn render(
_instances_dir: &std::path::Path,
) {
let color = if focused == FocusedArea::Settings {
THEME.colors.border_focused
THEME.details.border_focused_fg
} else {
THEME.colors.border_unfocused
THEME.details.border_unfocused_fg
};
let mut block = Block::default()
.title(styled_title("Settings", true))
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_type(THEME.general.border_type.to_border_type())
.border_style(Style::default().fg(color));
if focused == FocusedArea::Settings {
@@ -47,17 +47,17 @@ pub fn render(
let Some(inst) = instance else {
frame.render_widget(
Paragraph::new("No instance selected.")
.style(Style::default().fg(THEME.colors.text_idle)),
.style(Style::default().fg(THEME.details.label_fg)),
inner,
);
return;
};
let label_style = Style::default().fg(THEME.colors.text_idle);
let label_style = Style::default().fg(THEME.details.label_fg);
let value_style = Style::default()
.fg(THEME.colors.foreground)
.fg(THEME.details.value_fg)
.add_modifier(Modifier::BOLD);
let dim_style = Style::default().fg(THEME.colors.border_unfocused);
let dim_style = Style::default().fg(THEME.details.border_unfocused_fg);
let memory_min = inst.memory_min.as_deref().unwrap_or("512M");
let memory_max = inst.memory_max.as_deref().unwrap_or("2G");
+39 -33
View File
@@ -6,9 +6,7 @@ use ratatui::{
layout::{Constraint, Layout, Rect},
style::{Color, Modifier, Style},
text::{Line, Span},
widgets::{
Block, BorderType, Borders, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState,
},
widgets::{Block, Borders, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState},
Frame,
};
use tui_widget_list::{ListBuilder, ListState as TuiListState, ListView};
@@ -246,27 +244,27 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut LogsState) -> bool {
KeyCode::Char('j') | KeyCode::Down => {
if state.viewer_scroll < state.viewer_max_scroll {
state.viewer_scroll += 1;
state.viewer_scrollbar_state = ScrollbarState::new(state.viewer_max_scroll)
.position(state.viewer_scroll);
state.viewer_scrollbar_state =
ScrollbarState::new(state.viewer_max_scroll).position(state.viewer_scroll);
}
true
}
KeyCode::Char('k') | KeyCode::Up => {
state.viewer_scroll = state.viewer_scroll.saturating_sub(1);
state.viewer_scrollbar_state = ScrollbarState::new(state.viewer_max_scroll)
.position(state.viewer_scroll);
state.viewer_scrollbar_state =
ScrollbarState::new(state.viewer_max_scroll).position(state.viewer_scroll);
true
}
KeyCode::Char('G') => {
state.viewer_scroll = state.viewer_max_scroll;
state.viewer_scrollbar_state = ScrollbarState::new(state.viewer_max_scroll)
.position(state.viewer_scroll);
state.viewer_scrollbar_state =
ScrollbarState::new(state.viewer_max_scroll).position(state.viewer_scroll);
true
}
KeyCode::Char('g') => {
state.viewer_scroll = 0;
state.viewer_scrollbar_state = ScrollbarState::new(state.viewer_max_scroll)
.position(state.viewer_scroll);
state.viewer_scrollbar_state =
ScrollbarState::new(state.viewer_max_scroll).position(state.viewer_scroll);
true
}
KeyCode::Esc => {
@@ -344,7 +342,7 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut LogsState) -> bool {
pub fn render(frame: &mut Frame, area: Rect, state: &mut LogsState, is_focused: bool) {
if state.loading {
frame.render_widget(
Paragraph::new("Loading logs...").style(Style::default().fg(THEME.colors.text_idle)),
Paragraph::new("Loading logs...").style(Style::default().fg(THEME.logs.text_fg)),
area,
);
return;
@@ -355,7 +353,7 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut LogsState, is_focused:
if display_count == 0 {
frame.render_widget(
Paragraph::new("No logs yet.").style(Style::default().fg(THEME.colors.text_idle)),
Paragraph::new("No logs yet.").style(Style::default().fg(THEME.logs.text_fg)),
area,
);
return;
@@ -382,14 +380,14 @@ fn render_list(
) {
let list_focused = is_focused && !state.viewer_focused;
let border_color = if list_focused {
THEME.colors.border_focused
THEME.logs.border_focused_fg
} else {
THEME.colors.border_unfocused
THEME.logs.border_unfocused_fg
};
let block = Block::default()
.borders(Borders::RIGHT)
.border_type(BorderType::Rounded)
.border_type(THEME.general.border_type.to_border_type())
.border_style(Style::default().fg(border_color));
let inner = block.inner(area);
@@ -413,25 +411,31 @@ fn render_list(
let show_selected = list_focused && context.is_selected;
let style = if *is_live && show_selected {
Style::default()
.fg(THEME.colors.success)
.add_modifier(Modifier::BOLD)
let s = Style::default().fg(THEME.logs.running_fg);
if THEME.logs.selected_bold {
s.add_modifier(Modifier::BOLD)
} else {
s
}
} else if *is_live {
Style::default().fg(THEME.colors.success)
Style::default().fg(THEME.logs.running_fg)
} else if show_selected {
Style::default()
.fg(THEME.colors.row_highlight)
.add_modifier(Modifier::BOLD)
let s = Style::default().fg(THEME.logs.selected_fg);
if THEME.logs.selected_bold {
s.add_modifier(Modifier::BOLD)
} else {
s
}
} else {
Style::default().fg(THEME.colors.text_idle)
Style::default().fg(THEME.logs.text_fg)
};
let bg = if show_selected {
THEME.colors.row_background
THEME.logs.selected_bg
} else if context.index % 2 == 0 {
Color::Reset
} else {
THEME.colors.row_alternate_bg
THEME.logs.row_alt_bg
};
let item = ratatui::text::Text::from(Line::from(Span::styled(name.clone(), style)))
@@ -454,7 +458,7 @@ fn render_list(
.begin_symbol(Some("\u{25b2}"))
.style(
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.logs.border_focused_fg)
.add_modifier(Modifier::BOLD),
)
.thumb_symbol("\u{2551}")
@@ -522,7 +526,7 @@ fn render_viewer(
.begin_symbol(Some("\u{25b2}"))
.style(
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.logs.border_focused_fg)
.add_modifier(Modifier::BOLD),
)
.thumb_symbol("\u{2551}")
@@ -536,12 +540,14 @@ fn render_viewer(
fn line_level_style(line: &str) -> Style {
let upper = line.to_uppercase();
if upper.contains("ERROR") || upper.contains("FATAL") || upper.contains("[STDERR]") {
Style::default().fg(THEME.colors.error)
Style::default().fg(THEME.logs.error_fg)
} else if upper.contains("WARN") {
Style::default().fg(THEME.colors.warn)
} else if upper.contains("DEBUG") || upper.contains("TRACE") {
Style::default().fg(THEME.colors.text_idle)
Style::default().fg(THEME.logs.warn_fg)
} else if upper.contains("DEBUG") {
Style::default().fg(THEME.logs.debug_fg)
} else if upper.contains("TRACE") {
Style::default().fg(THEME.logs.trace_fg)
} else {
Style::default().fg(THEME.colors.foreground)
Style::default().fg(THEME.logs.text_fg)
}
}
+3 -3
View File
@@ -1,18 +1,18 @@
use crate::tui::theme::THEME;
use crossterm::event::KeyEvent;
use ratatui::{
style::Style,
text::{Line, Span},
};
use crate::tui::theme::THEME;
pub mod account;
pub mod content;
pub mod content_list;
pub mod details;
pub mod logs_viewer;
pub mod screenshots_grid;
pub mod popups;
pub mod profiles;
pub mod screenshots_grid;
pub mod search;
pub mod status;
@@ -24,7 +24,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(THEME.colors.accent)),
Span::styled(first, Style::default().fg(THEME.general.accent)),
Span::raw(rest),
])
}
+4 -2
View File
@@ -3,9 +3,11 @@ use ratatui::{
layout::{Alignment, Rect},
style::{Color, Style},
text::Line,
widgets::{Block, BorderType, Clear, Widget},
widgets::{Block, Clear, Widget},
};
use crate::tui::theme::THEME;
pub struct PopupFrame<'a> {
pub title: Line<'a>,
pub border_color: Color,
@@ -25,7 +27,7 @@ impl<'a> Widget for PopupFrame<'a> {
let mut block = Block::bordered()
.title_top(self.title)
.border_type(BorderType::Rounded)
.border_type(THEME.general.border_type.to_border_type())
.border_style(Style::default().fg(self.border_color));
if let Some(sl) = self.search_line {
+4 -4
View File
@@ -66,20 +66,20 @@ impl Widget for ConfirmPopup {
let title = Line::from(vec![Span::styled(
format!(" Delete '{}' ", self.instance_name),
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.popup_confirm.border_fg)
.add_modifier(Modifier::BOLD),
)]);
let kb = keybind_line(&[("Enter", " confirm")]);
let popup = PopupFrame {
title,
border_color: THEME.colors.border_focused,
bg: Some(THEME.colors.row_alternate_bg),
border_color: THEME.popup_confirm.border_fg,
bg: Some(THEME.popup_confirm.highlight_bg),
keybinds: Some(kb),
search_line: None,
content: Box::new(|inner, buf| {
Paragraph::new("This will permanently remove the instance")
.style(Style::default().fg(THEME.colors.foreground))
.style(Style::default().fg(THEME.popup_confirm.text_fg))
.render(inner, buf);
}),
};
+9 -8
View File
@@ -8,7 +8,8 @@ use ratatui::{
use tracing::Level;
use super::base::PopupFrame;
use crate::tui::error_buffer::{ErrorEvent, AUTO_DISMISS_MS};
use crate::config::SETTINGS;
use crate::tui::error_buffer::ErrorEvent;
use crate::tui::theme::THEME;
pub struct ErrorPopup {
@@ -24,15 +25,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 => (THEME.colors.error, "ERROR"),
Level::WARN => (THEME.colors.warn, "WARN"),
_ => (THEME.colors.border_focused, "INFO"),
Level::ERROR => (THEME.popup_error.error_fg, "ERROR"),
Level::WARN => (THEME.popup_error.warn_fg, "WARN"),
_ => (THEME.popup_error.border_fg, "INFO"),
};
let title = Line::from(vec![Span::styled(
format!(" {} ", label),
Style::default()
.fg(THEME.colors.badge_text)
.fg(THEME.popup_error.badge_text_fg)
.bg(border_color)
.add_modifier(Modifier::BOLD),
)]);
@@ -41,13 +42,13 @@ impl Widget for ErrorPopup {
let popup = PopupFrame {
title,
border_color,
bg: Some(THEME.colors.popup_bg),
bg: Some(THEME.popup_error.bg),
keybinds: None,
search_line: None,
content: Box::new(move |inner, buf| {
Paragraph::new(message.as_str())
.wrap(Wrap { trim: true })
.style(Style::default().fg(THEME.colors.foreground))
.style(Style::default().fg(THEME.popup_error.text_fg))
.render(inner, buf);
}),
};
@@ -62,7 +63,7 @@ pub fn popup_area(frame_area: Rect, message: &str, base_y: u16, elapsed_ms: u128
const MAX_W: usize = 58;
const MIN_W: usize = 22;
if elapsed_ms >= AUTO_DISMISS_MS {
if elapsed_ms >= SETTINGS.ui.error_auto_dismiss_ms as u128 {
return None;
}
+29 -12
View File
@@ -46,17 +46,26 @@ pub fn top_right_rect(frame: Rect, inner_w: usize, inner_h: usize) -> Rect {
let popup_h = popup_h.min(frame.height.saturating_sub(2));
let x = frame.width.saturating_sub(popup_w + 2);
let y = 1u16;
Rect { x, y, width: popup_w, height: popup_h }
Rect {
x,
y,
width: popup_w,
height: popup_h,
}
}
pub fn keybind_line(binds: &[(&str, &str)]) -> ratatui::text::Line<'static> {
use ratatui::{style::{Modifier, Style}, text::{Line, Span}};
use crate::tui::theme::THEME;
use ratatui::{
style::{Modifier, Style},
text::{Line, Span},
};
let key_style = Style::default()
.fg(THEME.colors.border_focused)
.add_modifier(Modifier::BOLD);
let dim_style = Style::default().fg(THEME.colors.border_unfocused);
let mut key_style = Style::default().fg(THEME.popup.keybind_active_fg);
if THEME.popup.keybind_active_bold {
key_style = key_style.add_modifier(Modifier::BOLD);
}
let dim_style = Style::default().fg(THEME.popup.keybind_inactive_fg);
let mut spans: Vec<Span<'static>> = Vec::new();
for (i, (key, label)) in binds.iter().enumerate() {
@@ -75,20 +84,28 @@ pub fn keybind_lines_wrapped(
binds: &[(&str, &str)],
max_width: u16,
) -> Vec<ratatui::text::Line<'static>> {
use ratatui::{style::{Modifier, Style}, text::{Line, Span}};
use crate::tui::theme::THEME;
use ratatui::{
style::{Modifier, Style},
text::{Line, Span},
};
let key_style = Style::default()
.fg(THEME.colors.border_focused)
.add_modifier(Modifier::BOLD);
let dim_style = Style::default().fg(THEME.colors.border_unfocused);
let mut key_style = Style::default().fg(THEME.popup.keybind_active_fg);
if THEME.popup.keybind_active_bold {
key_style = key_style.add_modifier(Modifier::BOLD);
}
let dim_style = Style::default().fg(THEME.popup.keybind_inactive_fg);
let mut rows: Vec<Line<'static>> = Vec::new();
let mut current_spans: Vec<Span<'static>> = Vec::new();
let mut current_width: usize = 0;
for (i, (key, label)) in binds.iter().enumerate() {
let sep_w = if i > 0 && !current_spans.is_empty() { 2 } else { 0 };
let sep_w = if i > 0 && !current_spans.is_empty() {
2
} else {
0
};
let item_w = key.len() + 2 + label.len();
let needed = sep_w + item_w;
+58 -53
View File
@@ -1,5 +1,8 @@
use super::base::PopupFrame;
use crate::instance::{loader::{get_installer, GameVersion}, models::ModLoader};
use crate::instance::{
loader::{get_installer, GameVersion},
models::ModLoader,
};
use crate::tui::layout::FocusedArea;
use crate::tui::theme::THEME;
use crate::tui::widgets::profiles;
@@ -15,8 +18,10 @@ use ratatui::{
use std::sync::{Arc, Mutex};
use tui_prompts::{FocusState, State as PromptState, TextState};
static WIZARD_STATE: Lazy<Arc<Mutex<WizardState>>> = Lazy::new(|| Arc::new(Mutex::new(WizardState::default())));
static WIZARD_RESULT: Lazy<Arc<Mutex<Option<WizardParams>>>> = Lazy::new(|| Arc::new(Mutex::new(None)));
static WIZARD_STATE: Lazy<Arc<Mutex<WizardState>>> =
Lazy::new(|| Arc::new(Mutex::new(WizardState::default())));
static WIZARD_RESULT: Lazy<Arc<Mutex<Option<WizardParams>>>> =
Lazy::new(|| Arc::new(Mutex::new(None)));
#[derive(Debug, Clone)]
pub struct WizardParams {
@@ -151,8 +156,8 @@ pub fn render(frame: &mut Frame, area: Rect, _focused: FocusedArea) {
let popup = PopupFrame {
title: wizard_title(&snapshot),
border_color: THEME.colors.border_focused,
bg: Some(THEME.colors.popup_bg),
border_color: THEME.popup_new_instance.border_fg,
bg: Some(THEME.popup_new_instance.bg),
keybinds: Some(keybinds),
search_line,
content: Box::new(move |popup_area, buf| {
@@ -188,7 +193,9 @@ pub fn handle_key(key_event: &KeyEvent, profiles_state: &mut profiles::State) {
WizardStep::Name => handle_name_key(&mut state, key_event, profiles_state),
WizardStep::Version => handle_version_key(&mut state, key_event, profiles_state),
WizardStep::Loader => handle_loader_key(&mut state, key_event, profiles_state),
WizardStep::LoaderVersion => handle_loader_version_key(&mut state, key_event, profiles_state),
WizardStep::LoaderVersion => {
handle_loader_version_key(&mut state, key_event, profiles_state)
}
WizardStep::Confirm => handle_confirm_key(&mut state, key_event, profiles_state),
}
}
@@ -216,7 +223,9 @@ pub fn popup_rect(frame_area: Rect) -> Rect {
frame_area.centered(w, Constraint::Length(h))
}
WizardStep::Version | WizardStep::LoaderVersion => {
let h = (frame_area.height * 2 / 3).max(10).min(frame_area.height.saturating_sub(4));
let h = (frame_area.height * 2 / 3)
.max(10)
.min(frame_area.height.saturating_sub(4));
frame_area.centered(w, Constraint::Length(h))
}
WizardStep::Loader => {
@@ -455,40 +464,44 @@ fn wizard_title(_state: &WizardState) -> Line<'static> {
fn step_keybinds(state: &WizardState) -> ratatui::text::Line<'static> {
use super::keybind_line;
match state.step {
WizardStep::Name => keybind_line(&[("Enter", " continue")]),
WizardStep::Loader => keybind_line(&[("h", " back"), ("Enter", " select")]),
WizardStep::Version => keybind_line(&[("/", " search"), ("s", " snap"), ("h", " back"), ("Enter", " select")]),
WizardStep::Name => keybind_line(&[("Enter", " continue")]),
WizardStep::Loader => keybind_line(&[("h", " back"), ("Enter", " select")]),
WizardStep::Version => keybind_line(&[
("/", " search"),
("s", " snap"),
("h", " back"),
("Enter", " select"),
]),
WizardStep::LoaderVersion => keybind_line(&[("h", " back"), ("Enter", " select")]),
WizardStep::Confirm => keybind_line(&[("h", " back"), ("Enter", " create")]),
WizardStep::Confirm => keybind_line(&[("h", " back"), ("Enter", " create")]),
}
}
fn render_name_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
use ratatui::text::{Line, Span};
use ratatui::style::Modifier;
use ratatui::text::{Line, Span};
let value = state.name_state.value();
let line = if value.is_empty() {
Line::from(vec![
Span::styled(
"Instance name...",
Style::default()
.fg(THEME.colors.border_unfocused),
Style::default().fg(THEME.popup_new_instance.field_inactive_border_fg),
),
Span::styled(
"\u{2588}",
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.popup_new_instance.border_fg)
.add_modifier(Modifier::SLOW_BLINK),
),
])
} else {
Line::from(vec![
Span::styled(value, Style::default().fg(THEME.colors.foreground)),
Span::styled(value, Style::default().fg(THEME.popup_new_instance.text_fg)),
Span::styled(
"\u{2588}",
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.popup_new_instance.border_fg)
.add_modifier(Modifier::SLOW_BLINK),
),
])
@@ -501,13 +514,13 @@ fn render_version_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffe
match &state.versions {
LoadState::Idle | LoadState::Loading => {
Paragraph::new("Loading versions...")
.style(Style::default().fg(THEME.colors.border_unfocused))
.style(Style::default().fg(THEME.popup_new_instance.field_inactive_border_fg))
.render(area, buf);
}
LoadState::Error(message) => {
Paragraph::new(message.as_str())
.wrap(Wrap { trim: true })
.style(Style::default().fg(THEME.colors.error))
.style(Style::default().fg(THEME.popup_new_instance.error_fg))
.render(area, buf);
}
LoadState::Loaded(_) => {
@@ -521,7 +534,7 @@ fn render_version_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffe
};
ListItem::new(Line::from(Span::styled(
format!("{}{}", version.id, suffix),
Style::default().fg(THEME.colors.foreground),
Style::default().fg(THEME.popup_new_instance.text_fg),
)))
})
.collect();
@@ -529,7 +542,7 @@ fn render_version_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffe
let list = List::new(items)
.highlight_style(
Style::default()
.fg(THEME.colors.accent)
.fg(THEME.popup_new_instance.accent_fg)
.add_modifier(Modifier::BOLD),
)
.highlight_symbol("▶ ");
@@ -554,7 +567,7 @@ fn render_loader_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer
.map(|loader| {
ListItem::new(Line::from(Span::styled(
loader.to_string(),
Style::default().fg(THEME.colors.foreground),
Style::default().fg(THEME.popup_new_instance.text_fg),
)))
})
.collect();
@@ -562,7 +575,7 @@ fn render_loader_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer
let list = List::new(items)
.highlight_style(
Style::default()
.fg(THEME.colors.accent)
.fg(THEME.popup_new_instance.accent_fg)
.add_modifier(Modifier::BOLD),
)
.highlight_symbol("▶ ");
@@ -571,14 +584,10 @@ fn render_loader_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer
StatefulWidget::render(list, area, buf, &mut list_state);
}
fn render_loader_version_step(
state: &WizardState,
area: Rect,
buf: &mut ratatui::buffer::Buffer,
) {
fn render_loader_version_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
if state.selected_loader() == ModLoader::Vanilla {
Paragraph::new("Vanilla has no loader version.")
.style(Style::default().fg(THEME.colors.border_unfocused))
.style(Style::default().fg(THEME.popup_new_instance.field_inactive_border_fg))
.render(area, buf);
return;
}
@@ -586,13 +595,13 @@ fn render_loader_version_step(
match &state.loader_versions {
LoadState::Idle | LoadState::Loading => {
Paragraph::new(format!("Loading {} versions...", state.selected_loader()))
.style(Style::default().fg(THEME.colors.border_unfocused))
.style(Style::default().fg(THEME.popup_new_instance.field_inactive_border_fg))
.render(area, buf);
}
LoadState::Error(message) => {
Paragraph::new(message.as_str())
.wrap(Wrap { trim: true })
.style(Style::default().fg(THEME.colors.error))
.style(Style::default().fg(THEME.popup_new_instance.error_fg))
.render(area, buf);
}
LoadState::Loaded(versions) => {
@@ -601,7 +610,7 @@ fn render_loader_version_step(
.map(|version| {
ListItem::new(Line::from(Span::styled(
version.clone(),
Style::default().fg(THEME.colors.foreground),
Style::default().fg(THEME.popup_new_instance.text_fg),
)))
})
.collect();
@@ -609,7 +618,7 @@ fn render_loader_version_step(
let list = List::new(items)
.highlight_style(
Style::default()
.fg(THEME.colors.accent)
.fg(THEME.popup_new_instance.accent_fg)
.add_modifier(Modifier::BOLD),
)
.highlight_symbol("▶ ");
@@ -634,7 +643,7 @@ fn render_confirm_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffe
.unwrap_or_else(|| "<not selected>".to_string())
};
let label_style = Style::default().fg(THEME.colors.border_focused);
let label_style = Style::default().fg(THEME.popup_new_instance.border_fg);
Paragraph::new(vec![
Line::from(vec![
@@ -654,7 +663,7 @@ fn render_confirm_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffe
Span::raw(loader_version),
]),
])
.style(Style::default().fg(THEME.colors.foreground))
.style(Style::default().fg(THEME.popup_new_instance.text_fg))
.wrap(Wrap { trim: true })
.render(area, buf);
}
@@ -715,16 +724,14 @@ fn ensure_versions_loaded(state: &mut WizardState) {
tracing::error!("Wizard state lock poisoned: {}", e);
}
},
Err(e) => {
match versions_arc.lock() {
Ok(mut s) => {
s.versions = LoadState::Error(e.to_string());
}
Err(lock_error) => {
tracing::error!("Wizard state lock poisoned: {}", lock_error);
}
Err(e) => match versions_arc.lock() {
Ok(mut s) => {
s.versions = LoadState::Error(e.to_string());
}
}
Err(lock_error) => {
tracing::error!("Wizard state lock poisoned: {}", lock_error);
}
},
}
});
}
@@ -749,16 +756,14 @@ fn ensure_loader_versions_loaded(state: &mut WizardState, loader: ModLoader, gam
tracing::error!("Wizard state lock poisoned: {}", e);
}
},
Err(e) => {
match versions_arc.lock() {
Ok(mut s) => {
s.loader_versions = LoadState::Error(e.to_string());
}
Err(lock_error) => {
tracing::error!("Wizard state lock poisoned: {}", lock_error);
}
Err(e) => match versions_arc.lock() {
Ok(mut s) => {
s.loader_versions = LoadState::Error(e.to_string());
}
}
Err(lock_error) => {
tracing::error!("Wizard state lock poisoned: {}", lock_error);
}
},
}
});
}
+28 -26
View File
@@ -1,16 +1,17 @@
use crate::tui::theme::THEME;
use crossterm::event::KeyCode;
use ratatui::{
layout::Rect,
style::{Color, Modifier, Style},
style::{Modifier, Style},
text::{Line, Span, Text},
widgets::{Block, BorderType, Borders, Scrollbar, ScrollbarOrientation, ScrollbarState},
widgets::{Block, Borders, Scrollbar, ScrollbarOrientation, ScrollbarState},
Frame,
};
use tui_widget_list::{ListBuilder, ListState as TuiListState, ListView};
use crate::instance::models::InstanceConfig;
use crate::running::{get as get_run_state, RunState};
use crate::tui::{layout::FocusedArea, theme::THEME};
use crate::tui::layout::FocusedArea;
use super::{search::SearchState, styled_title, WidgetKey};
@@ -34,13 +35,12 @@ fn format_last_played(last_played: Option<chrono::DateTime<chrono::Utc>>) -> Str
fn loader_color(loader: crate::instance::models::ModLoader) -> ratatui::style::Color {
use crate::instance::models::ModLoader;
use ratatui::style::Color;
match loader {
ModLoader::Vanilla => Color::Green,
ModLoader::Fabric => Color::Rgb(0x71, 0xa5, 0xde),
ModLoader::Forge => Color::Rgb(0xe0, 0x7b, 0x39),
ModLoader::NeoForge => Color::Rgb(0xe0, 0x54, 0x1b),
ModLoader::Quilt => Color::Rgb(0xa6, 0x5c, 0xcb),
ModLoader::Vanilla => THEME.profiles.loader_vanilla,
ModLoader::Fabric => THEME.profiles.loader_fabric,
ModLoader::Forge => THEME.profiles.loader_forge,
ModLoader::NeoForge => THEME.profiles.loader_neoforge,
ModLoader::Quilt => THEME.profiles.loader_quilt,
}
}
@@ -194,15 +194,15 @@ impl WidgetKey for State {
pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut State) {
let color = if focused == FocusedArea::Profiles {
THEME.colors.border_focused
THEME.profiles.border_focused_fg
} else {
THEME.colors.border_unfocused
THEME.profiles.border_unfocused_fg
};
let mut block = Block::default()
.title(styled_title("Profiles", true))
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_type(THEME.general.border_type.to_border_type())
.border_style(Style::default().fg(color));
if let Some(search_line) = state.search.title_line() {
@@ -224,25 +224,27 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
let instance = &state.instances[idx];
let stripe_bg = if context.index % 2 == 0 {
Color::Reset
THEME.general.bg
} else {
THEME.colors.row_alternate_bg
THEME.profiles.row_alt_bg
};
let (name_style, meta_style, bg) = if context.is_selected {
let mut style = Style::default().fg(THEME.profiles.selected_fg);
if THEME.profiles.selected_bold {
style = style.add_modifier(Modifier::BOLD);
}
(
Style::default()
.fg(THEME.colors.row_highlight)
.add_modifier(Modifier::BOLD),
Style::default().fg(THEME.colors.row_highlight),
THEME.colors.row_background,
style,
Style::default().fg(THEME.profiles.selected_fg),
THEME.profiles.selected_bg,
)
} else {
(
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.profiles.border_focused_fg)
.add_modifier(Modifier::BOLD),
Style::default().fg(THEME.colors.border_unfocused),
Style::default().fg(THEME.profiles.border_unfocused_fg),
stripe_bg,
)
};
@@ -257,11 +259,11 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
let rename_val = state.renaming.as_deref().unwrap_or("");
Line::from(vec![
stripe.clone(),
Span::styled(rename_val, Style::default().fg(THEME.colors.foreground)),
Span::styled(rename_val, Style::default().fg(THEME.profiles.text_fg)),
Span::styled(
"\u{2588}",
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.profiles.border_focused_fg)
.add_modifier(Modifier::SLOW_BLINK),
),
])
@@ -275,11 +277,11 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
let (meta_text, meta_text_style) = match get_run_state(&instance.name) {
Some(RunState::Authenticating) => (
"Authenticating".to_string(),
Style::default().fg(THEME.colors.success),
Style::default().fg(THEME.profiles.running_fg),
),
Some(RunState::Running) | Some(RunState::Starting) => (
"Playing".to_string(),
Style::default().fg(THEME.colors.success),
Style::default().fg(THEME.profiles.running_fg),
),
_ => (format_last_played(instance.last_played), meta_style),
};
@@ -300,7 +302,7 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
.begin_symbol(Some("\u{25b2}"))
.style(
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.profiles.border_focused_fg)
.add_modifier(Modifier::BOLD),
)
.thumb_symbol("\u{2551}")
+16 -20
View File
@@ -237,16 +237,12 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut ScreenshotsState) -> bool {
}
true
}
KeyCode::Char('H') | KeyCode::Left
if key_event.modifiers.contains(KeyModifiers::SHIFT) =>
{
KeyCode::Char('H') | KeyCode::Left if key_event.modifiers.contains(KeyModifiers::SHIFT) => {
state.selected = state.selected.saturating_sub(1);
state.ensure_visible();
true
}
KeyCode::Char('J') | KeyCode::Down
if key_event.modifiers.contains(KeyModifiers::SHIFT) =>
{
KeyCode::Char('J') | KeyCode::Down if key_event.modifiers.contains(KeyModifiers::SHIFT) => {
let next = state.selected + cols;
if next < count {
state.selected = next;
@@ -254,9 +250,7 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut ScreenshotsState) -> bool {
state.ensure_visible();
true
}
KeyCode::Char('K') | KeyCode::Up
if key_event.modifiers.contains(KeyModifiers::SHIFT) =>
{
KeyCode::Char('K') | KeyCode::Up if key_event.modifiers.contains(KeyModifiers::SHIFT) => {
state.selected = state.selected.saturating_sub(cols);
state.ensure_visible();
true
@@ -280,7 +274,7 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut ScreenshotsState, is_fo
if state.loading {
frame.render_widget(
Paragraph::new("Loading screenshots...")
.style(Style::default().fg(THEME.colors.text_idle)),
.style(Style::default().fg(THEME.screenshots.label_fg)),
area,
);
return;
@@ -288,7 +282,8 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut ScreenshotsState, is_fo
if state.entries.is_empty() {
frame.render_widget(
Paragraph::new("No screenshots.").style(Style::default().fg(THEME.colors.text_idle)),
Paragraph::new("No screenshots.")
.style(Style::default().fg(THEME.screenshots.label_fg)),
area,
);
return;
@@ -305,7 +300,10 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut ScreenshotsState, is_fo
.first()
.map(|e| (e.width, e.height))
.unwrap_or((1920, 1080));
let (fw, fh) = (state.font_size.0.max(1) as u32, state.font_size.1.max(1) as u32);
let (fw, fh) = (
state.font_size.0.max(1) as u32,
state.font_size.1.max(1) as u32,
);
let img_rows = (cell_width as u32 * fw * img_h / (fh * img_w)).max(2) as u16;
let cell_height = img_rows + NAME_ROW_HEIGHT + GAP;
let visible_rows = (area.height / cell_height).max(1) as usize;
@@ -339,11 +337,9 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut ScreenshotsState, is_fo
let is_selected = is_focused && idx == state.selected;
let [img_area, name_area] = Layout::vertical([
Constraint::Min(0),
Constraint::Length(NAME_ROW_HEIGHT),
])
.areas(cell);
let [img_area, name_area] =
Layout::vertical([Constraint::Min(0), Constraint::Length(NAME_ROW_HEIGHT)])
.areas(cell);
if let Some(proto) = state.protocols.get_mut(&idx) {
let widget: StatefulImage<StatefulProtocol> =
@@ -354,10 +350,10 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut ScreenshotsState, is_fo
let name = &state.entries[idx].name;
let name_style = if is_selected {
Style::default()
.fg(THEME.colors.accent)
.fg(THEME.screenshots.selected_border_fg)
.add_modifier(Modifier::BOLD)
} else {
Style::default().fg(THEME.colors.text_idle)
Style::default().fg(THEME.screenshots.label_fg)
};
let truncated = if name.len() > cell_width as usize {
@@ -384,7 +380,7 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut ScreenshotsState, is_fo
.begin_symbol(Some("\u{25b2}"))
.style(
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.screenshots.border_focused_fg)
.add_modifier(Modifier::BOLD),
)
.thumb_symbol("\u{2551}")
+2 -2
View File
@@ -77,9 +77,9 @@ impl SearchState {
return None;
}
let dim = Style::default().fg(THEME.colors.border_unfocused);
let dim = Style::default().fg(THEME.search.border_unfocused_fg);
let accent = Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.search.border_focused_fg)
.add_modifier(Modifier::BOLD);
let mut spans = vec![
+13 -15
View File
@@ -2,7 +2,7 @@ use ratatui::{
layout::{Constraint, Layout, Rect},
style::{Modifier, Style},
text::Span,
widgets::{Block, BorderType, Borders, Gauge, Paragraph},
widgets::{Block, Borders, Gauge, Paragraph},
Frame,
};
use throbber_widgets_tui::{Throbber, ThrobberState};
@@ -20,15 +20,15 @@ pub fn render(
throbber_state: &mut ThrobberState,
) {
let border_color = if focused == FocusedArea::Overview {
THEME.colors.border_focused
THEME.status.border_focused_fg
} else {
THEME.colors.border_unfocused
THEME.status.border_unfocused_fg
};
let block = Block::default()
.title(styled_title("Overview", true))
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_type(THEME.general.border_type.to_border_type())
.border_style(Style::default().fg(border_color));
let state = match PROGRESS.lock() {
@@ -37,7 +37,7 @@ pub fn render(
frame.render_widget(
Paragraph::new(Span::styled(
"Ready",
Style::default().fg(THEME.colors.text_idle),
Style::default().fg(THEME.status.label_fg),
))
.block(block),
area,
@@ -50,7 +50,7 @@ pub fn render(
frame.render_widget(
Paragraph::new(Span::styled(
"Ready",
Style::default().fg(THEME.colors.text_idle),
Style::default().fg(THEME.status.label_fg),
))
.block(block),
area,
@@ -77,20 +77,19 @@ pub fn render(
let gauge = Gauge::default()
.gauge_style(
Style::default()
.fg(THEME.colors.progress_fill)
.bg(THEME.colors.progress_track)
.fg(THEME.status.progress_fill_fg)
.bg(THEME.status.progress_track_fg)
.add_modifier(Modifier::BOLD),
)
.percent((ratio * 100.0) as u16);
frame.render_widget(gauge, chunks[0]);
frame.render_widget(
Paragraph::new(action_text).style(Style::default().fg(THEME.colors.foreground)),
Paragraph::new(action_text).style(Style::default().fg(THEME.status.text_fg)),
chunks[1],
);
if !sub_text.is_empty() {
frame.render_widget(
Paragraph::new(sub_text)
.style(Style::default().fg(THEME.colors.border_unfocused)),
Paragraph::new(sub_text).style(Style::default().fg(THEME.status.label_fg)),
chunks[2],
);
}
@@ -100,17 +99,16 @@ pub fn render(
Layout::vertical([Constraint::Length(1), Constraint::Length(1)]).split(inner);
let throbber = Throbber::default()
.label(action_text)
.style(Style::default().fg(THEME.colors.foreground))
.style(Style::default().fg(THEME.status.text_fg))
.throbber_style(
Style::default()
.fg(THEME.colors.border_focused)
.fg(THEME.status.border_focused_fg)
.add_modifier(Modifier::BOLD),
);
frame.render_stateful_widget(throbber, chunks[0], throbber_state);
if !sub_text.is_empty() {
frame.render_widget(
Paragraph::new(sub_text)
.style(Style::default().fg(THEME.colors.border_unfocused)),
Paragraph::new(sub_text).style(Style::default().fg(THEME.status.label_fg)),
chunks[1],
);
}