refactor: upgrade crates and restructure project
This commit is contained in:
1 parent
ea093c044f
commit
47dad69321
80 files changed
+6094
-6125
No files matched your search
+68
-55
@@ -3,7 +3,7 @@ use std::sync::{Arc, Mutex};
|
||||
use crossterm::event::{KeyCode, KeyEvent};
|
||||
use ratatui::{
|
||||
layout::Rect,
|
||||
style::{Color, Modifier, Style},
|
||||
style::{Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, Borders, Paragraph, Widget},
|
||||
Frame,
|
||||
@@ -11,8 +11,8 @@ use ratatui::{
|
||||
use tui_widget_list::{ListBuilder, ListState as TuiListState, ListView};
|
||||
|
||||
use crate::auth::{self, AccountStore, AccountType, AuthResult, DeviceCodeInfo};
|
||||
use crate::tui::layout::FocusedArea;
|
||||
use crate::tui::theme::THEME;
|
||||
use crate::tui::app::FocusedArea;
|
||||
use crate::config::theme::{THEME, BORDER_STYLE};
|
||||
|
||||
use super::styled_title;
|
||||
|
||||
@@ -213,16 +213,17 @@ pub fn drain_device_code(state: &mut AccountState) {
|
||||
}
|
||||
|
||||
pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut AccountState) {
|
||||
let theme = THEME.as_ref();
|
||||
let color = if focused == FocusedArea::Account {
|
||||
THEME.account.border_focused_fg
|
||||
theme.accent()
|
||||
} else {
|
||||
THEME.account.border_unfocused_fg
|
||||
theme.border()
|
||||
};
|
||||
|
||||
let mut block = Block::default()
|
||||
.title(styled_title("Accounts", true))
|
||||
.borders(Borders::ALL)
|
||||
.border_type(THEME.general.border_type.to_border_type())
|
||||
.border_type(BORDER_STYLE.to_border_type())
|
||||
.border_style(Style::default().fg(color));
|
||||
|
||||
if focused == FocusedArea::Account {
|
||||
@@ -241,7 +242,7 @@ 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.account.text_secondary_fg)),
|
||||
.style(Style::default().fg(theme.text_dim())),
|
||||
inner,
|
||||
);
|
||||
} else {
|
||||
@@ -282,47 +283,36 @@ fn render_account_list(
|
||||
let count = accounts.len();
|
||||
|
||||
let builder = ListBuilder::new(move |context| {
|
||||
let theme = THEME.as_ref();
|
||||
let (username, acc_type, is_active) = &accounts[context.index];
|
||||
let show_selected = is_focused && context.is_selected;
|
||||
|
||||
let stripe_bg = Color::Reset;
|
||||
let stripe_bg = theme.background();
|
||||
|
||||
let bg = if show_selected {
|
||||
THEME.account.selected_bg
|
||||
} else {
|
||||
stripe_bg
|
||||
};
|
||||
let bg = stripe_bg;
|
||||
|
||||
let active_marker = if *is_active { "\u{25b8} " } else { " " };
|
||||
|
||||
let style = if show_selected {
|
||||
let mut s = Style::default().fg(THEME.account.selected_fg);
|
||||
if THEME.account.selected_bold {
|
||||
s = s.add_modifier(Modifier::BOLD);
|
||||
}
|
||||
s
|
||||
Style::default().fg(theme.accent()).add_modifier(Modifier::BOLD)
|
||||
} else if *is_active {
|
||||
Style::default()
|
||||
.fg(THEME.account.text_fg)
|
||||
.fg(theme.text())
|
||||
.add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
Style::default().fg(THEME.account.text_fg)
|
||||
Style::default().fg(theme.text())
|
||||
};
|
||||
|
||||
let mut spans = vec![
|
||||
Span::styled(active_marker, Style::default().fg(THEME.account.active_fg)),
|
||||
Span::styled(active_marker, Style::default().fg(theme.success())),
|
||||
Span::styled(username.clone(), style),
|
||||
];
|
||||
|
||||
if *acc_type == AccountType::Offline {
|
||||
let offline_style = if show_selected {
|
||||
let mut s = Style::default().fg(THEME.account.selected_fg);
|
||||
if THEME.account.selected_bold {
|
||||
s = s.add_modifier(Modifier::BOLD);
|
||||
}
|
||||
s
|
||||
Style::default().fg(theme.accent()).add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
Style::default().fg(THEME.account.text_secondary_fg)
|
||||
Style::default().fg(theme.text_dim())
|
||||
};
|
||||
spans.push(Span::styled(" (Offline)", offline_style));
|
||||
}
|
||||
@@ -349,42 +339,48 @@ fn popup_area(frame: &Frame, width: u16, height: u16) -> Rect {
|
||||
|
||||
fn render_choose_popup(frame: &mut Frame) {
|
||||
use super::popups::base::PopupFrame;
|
||||
let theme = THEME.as_ref();
|
||||
let area = popup_area(frame, 40, 7);
|
||||
|
||||
let border_color = theme.text_dim();
|
||||
let dim_color = theme.text_dim();
|
||||
let accent_color = theme.success();
|
||||
let text_color = theme.text();
|
||||
|
||||
PopupFrame {
|
||||
title: Line::from(" Add Account ").centered(),
|
||||
border_color: THEME.account.border_focused_fg,
|
||||
border_color,
|
||||
bg: None,
|
||||
keybinds: Some(Line::from(Span::styled(
|
||||
" Esc: cancel ",
|
||||
Style::default().fg(THEME.account.text_secondary_fg),
|
||||
Style::default().fg(dim_color),
|
||||
))),
|
||||
search_line: None,
|
||||
content: Box::new(|inner, buf| {
|
||||
content: Box::new(move |inner, buf| {
|
||||
let text = vec![
|
||||
Line::from(""),
|
||||
Line::from(vec![
|
||||
Span::styled(
|
||||
" [m] ",
|
||||
Style::default()
|
||||
.fg(THEME.account.active_fg)
|
||||
.fg(accent_color)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
Span::styled(
|
||||
"Microsoft Account",
|
||||
Style::default().fg(THEME.account.text_fg),
|
||||
Style::default().fg(text_color),
|
||||
),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled(
|
||||
" [o] ",
|
||||
Style::default()
|
||||
.fg(THEME.account.active_fg)
|
||||
.fg(accent_color)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
Span::styled(
|
||||
"Offline Account",
|
||||
Style::default().fg(THEME.account.text_fg),
|
||||
Style::default().fg(text_color),
|
||||
),
|
||||
]),
|
||||
];
|
||||
@@ -396,19 +392,25 @@ fn render_choose_popup(frame: &mut Frame) {
|
||||
|
||||
fn render_offline_popup(frame: &mut Frame, name: &str) {
|
||||
use super::popups::{base::PopupFrame, keybind_line};
|
||||
let theme = THEME.as_ref();
|
||||
let area = popup_area(frame, 40, 5);
|
||||
let name = name.to_string();
|
||||
|
||||
let border_color = theme.text_dim();
|
||||
let bg_color = theme.surface();
|
||||
let dim_color = theme.text_dim();
|
||||
let text_color = theme.text();
|
||||
|
||||
PopupFrame {
|
||||
title: Line::from(Span::styled(
|
||||
" Offline Account ",
|
||||
Style::default()
|
||||
.fg(THEME.account.border_focused_fg)
|
||||
.fg(border_color)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
))
|
||||
.centered(),
|
||||
border_color: THEME.account.border_focused_fg,
|
||||
bg: Some(THEME.account.popup_bg),
|
||||
border_color,
|
||||
bg: Some(bg_color),
|
||||
keybinds: Some(keybind_line(&[("Enter", " confirm"), ("Esc", " cancel")])),
|
||||
search_line: None,
|
||||
content: Box::new(move |inner, buf| {
|
||||
@@ -416,22 +418,22 @@ fn render_offline_popup(frame: &mut Frame, name: &str) {
|
||||
Line::from(vec![
|
||||
Span::styled(
|
||||
"Username...",
|
||||
Style::default().fg(THEME.account.border_unfocused_fg),
|
||||
Style::default().fg(dim_color),
|
||||
),
|
||||
Span::styled(
|
||||
"\u{2588}",
|
||||
Style::default()
|
||||
.fg(THEME.account.border_focused_fg)
|
||||
.fg(border_color)
|
||||
.add_modifier(Modifier::SLOW_BLINK),
|
||||
),
|
||||
])
|
||||
} else {
|
||||
Line::from(vec![
|
||||
Span::styled(name.as_str(), Style::default().fg(THEME.account.text_fg)),
|
||||
Span::styled(name.as_str(), Style::default().fg(text_color)),
|
||||
Span::styled(
|
||||
"\u{2588}",
|
||||
Style::default()
|
||||
.fg(THEME.account.border_focused_fg)
|
||||
.fg(border_color)
|
||||
.add_modifier(Modifier::SLOW_BLINK),
|
||||
),
|
||||
])
|
||||
@@ -444,6 +446,7 @@ fn render_offline_popup(frame: &mut Frame, name: &str) {
|
||||
|
||||
fn render_confirm_delete(frame: &mut Frame, state: &AccountState, idx: usize) {
|
||||
use super::popups::{base::PopupFrame, keybind_line};
|
||||
let theme = THEME.as_ref();
|
||||
let username = state
|
||||
.store
|
||||
.accounts
|
||||
@@ -451,10 +454,11 @@ fn render_confirm_delete(frame: &mut Frame, state: &AccountState, idx: usize) {
|
||||
.map(|a| a.username.as_str())
|
||||
.unwrap_or("?");
|
||||
|
||||
let border_color = theme.text_dim();
|
||||
let title = Line::from(Span::styled(
|
||||
format!(" Delete '{}' ", username),
|
||||
Style::default()
|
||||
.fg(THEME.account.border_focused_fg)
|
||||
.fg(border_color)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
));
|
||||
|
||||
@@ -462,15 +466,18 @@ fn render_confirm_delete(frame: &mut Frame, state: &AccountState, idx: usize) {
|
||||
let popup_w = (username.len() + 14).max(body.len() + 2).min(48) as u16 + 2;
|
||||
let area = popup_area(frame, popup_w, 3);
|
||||
|
||||
let bg_color = theme.surface();
|
||||
let text_color = theme.text();
|
||||
|
||||
PopupFrame {
|
||||
title,
|
||||
border_color: THEME.account.border_focused_fg,
|
||||
bg: Some(THEME.account.popup_bg),
|
||||
border_color,
|
||||
bg: Some(bg_color),
|
||||
keybinds: Some(keybind_line(&[("Enter", " confirm")])),
|
||||
search_line: None,
|
||||
content: Box::new(|inner, buf| {
|
||||
content: Box::new(move |inner, buf| {
|
||||
Paragraph::new("This will permanently remove this account")
|
||||
.style(Style::default().fg(THEME.account.text_fg))
|
||||
.style(Style::default().fg(text_color))
|
||||
.render(inner, buf);
|
||||
}),
|
||||
}
|
||||
@@ -479,57 +486,63 @@ fn render_confirm_delete(frame: &mut Frame, state: &AccountState, idx: usize) {
|
||||
|
||||
fn render_device_code_popup(frame: &mut Frame, info: &DeviceCodeInfo) {
|
||||
use super::popups::{base::PopupFrame, keybind_line};
|
||||
let theme = THEME.as_ref();
|
||||
let area = popup_area(frame, 50, 8);
|
||||
let uri = info.verification_uri.clone();
|
||||
let code = info.user_code.clone();
|
||||
|
||||
let border_color = theme.text_dim();
|
||||
let bg_color = theme.surface();
|
||||
let dim_color = theme.text_dim();
|
||||
let accent_color = theme.success();
|
||||
|
||||
PopupFrame {
|
||||
title: Line::from(Span::styled(
|
||||
" Microsoft Login ",
|
||||
Style::default()
|
||||
.fg(THEME.account.border_focused_fg)
|
||||
.fg(border_color)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
))
|
||||
.centered(),
|
||||
border_color: THEME.account.border_focused_fg,
|
||||
bg: Some(THEME.account.popup_bg),
|
||||
border_color,
|
||||
bg: Some(bg_color),
|
||||
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.account.text_secondary_fg),
|
||||
Style::default().fg(dim_color),
|
||||
))]
|
||||
} else {
|
||||
vec![
|
||||
Line::from(Span::styled(
|
||||
"Open this URL in your browser:",
|
||||
Style::default().fg(THEME.account.text_secondary_fg),
|
||||
Style::default().fg(dim_color),
|
||||
)),
|
||||
Line::from(Span::styled(
|
||||
uri.as_str(),
|
||||
Style::default()
|
||||
.fg(THEME.account.active_fg)
|
||||
.fg(accent_color)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)),
|
||||
Line::from(""),
|
||||
Line::from(vec![
|
||||
Span::styled(
|
||||
"Enter code: ",
|
||||
Style::default().fg(THEME.account.text_secondary_fg),
|
||||
Style::default().fg(dim_color),
|
||||
),
|
||||
Span::styled(
|
||||
code.as_str(),
|
||||
Style::default()
|
||||
.fg(THEME.account.active_fg)
|
||||
.fg(accent_color)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
]),
|
||||
Line::from(""),
|
||||
Line::from(Span::styled(
|
||||
"Waiting for authentication...",
|
||||
Style::default().fg(THEME.account.text_secondary_fg),
|
||||
Style::default().fg(dim_color),
|
||||
)),
|
||||
]
|
||||
};
|
||||
|
||||
@@ -12,27 +12,29 @@ use ratatui::{
|
||||
};
|
||||
use tui_widget_list::{ListBuilder, ListState as TuiListState, ListView};
|
||||
|
||||
use crate::instance::mods::ModEntry;
|
||||
use crate::tui::theme::THEME;
|
||||
use crate::instance::content::mods::{ContentEntry, IconCell};
|
||||
use crate::config::theme::THEME;
|
||||
|
||||
type IconCell = (u8, u8, u8, u8, u8, u8);
|
||||
type PendingContent = Arc<Mutex<Option<(String, Vec<ModEntry>)>>>;
|
||||
type PendingContent = Arc<Mutex<Option<(String, Vec<ContentEntry>)>>>;
|
||||
type SnapshotRow = (String, String, bool, Option<Vec<Vec<IconCell>>>);
|
||||
|
||||
struct CachedList {
|
||||
entries: Vec<ModEntry>,
|
||||
entries: Vec<ContentEntry>,
|
||||
selected: Option<usize>,
|
||||
}
|
||||
|
||||
pub struct ContentListState {
|
||||
pub entries: Vec<ModEntry>,
|
||||
pub entries: Vec<ContentEntry>,
|
||||
pub list_state: TuiListState,
|
||||
pub scrollbar_state: ScrollbarState,
|
||||
pub loaded_for: Option<String>,
|
||||
pub loading: bool,
|
||||
pub search: super::search::SearchState,
|
||||
pub search: crate::tui::widgets::search::SearchState,
|
||||
cache: HashMap<String, CachedList>,
|
||||
pending: PendingContent,
|
||||
check_counter: u16,
|
||||
watched_dir: Option<std::path::PathBuf>,
|
||||
last_dir_mtime: Option<std::time::SystemTime>,
|
||||
}
|
||||
|
||||
impl Default for ContentListState {
|
||||
@@ -43,14 +45,50 @@ impl Default for ContentListState {
|
||||
scrollbar_state: ScrollbarState::default(),
|
||||
loaded_for: None,
|
||||
loading: false,
|
||||
search: super::search::SearchState::default(),
|
||||
search: crate::tui::widgets::search::SearchState::default(),
|
||||
cache: HashMap::new(),
|
||||
pending: Arc::new(Mutex::new(None)),
|
||||
check_counter: 0,
|
||||
watched_dir: None,
|
||||
last_dir_mtime: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentListState {
|
||||
/// Check if the content directory changed (files added/removed).
|
||||
/// Only triggers a rescan when the directory's modification time differs.
|
||||
pub fn try_rescan(&mut self) {
|
||||
self.check_counter = self.check_counter.wrapping_add(1);
|
||||
// Check every ~2 seconds (120 ticks at 16ms)
|
||||
if !self.check_counter.is_multiple_of(120) {
|
||||
return;
|
||||
}
|
||||
|
||||
let Some(dir) = &self.watched_dir else {
|
||||
return;
|
||||
};
|
||||
|
||||
let current_mtime = std::fs::metadata(dir)
|
||||
.ok()
|
||||
.and_then(|m| m.modified().ok());
|
||||
|
||||
if current_mtime != self.last_dir_mtime {
|
||||
self.last_dir_mtime = current_mtime;
|
||||
// Directory changed — invalidate so next render triggers start_load
|
||||
if let Some(name) = &self.loaded_for {
|
||||
self.cache.remove(name);
|
||||
self.loaded_for = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the directory to watch for changes. Call after start_load.
|
||||
pub fn watch_dir(&mut self, dir: std::path::PathBuf) {
|
||||
self.last_dir_mtime = std::fs::metadata(&dir).ok().and_then(|m| m.modified().ok());
|
||||
self.watched_dir = Some(dir);
|
||||
}
|
||||
|
||||
pub fn filtered_indices(&self) -> Vec<usize> {
|
||||
self.entries
|
||||
.iter()
|
||||
@@ -64,7 +102,7 @@ impl ContentListState {
|
||||
impl ContentListState {
|
||||
pub fn start_load<F>(&mut self, instances_dir: &Path, instance_name: &str, scan_fn: F)
|
||||
where
|
||||
F: FnOnce(&Path, &str) -> Vec<ModEntry> + Send + 'static,
|
||||
F: FnOnce(&Path, &str) -> Vec<ContentEntry> + Send + 'static,
|
||||
{
|
||||
if let Some(prev) = self.loaded_for.take() {
|
||||
if !self.entries.is_empty() {
|
||||
@@ -243,12 +281,7 @@ pub fn handle_key_no_toggle(key_event: &KeyEvent, state: &mut ContentListState)
|
||||
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(dir) = state.entries[real_idx].path.parent() {
|
||||
if let Err(e) = std::process::Command::new("xdg-open")
|
||||
.arg(dir)
|
||||
.stdout(std::process::Stdio::null())
|
||||
.stderr(std::process::Stdio::null())
|
||||
.spawn()
|
||||
{
|
||||
if let Err(e) = open::that(dir) {
|
||||
tracing::error!("Failed to open directory: {}", e);
|
||||
}
|
||||
}
|
||||
@@ -285,12 +318,7 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut ContentListState) -> bool {
|
||||
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(dir) = state.entries[real_idx].path.parent() {
|
||||
if let Err(e) = std::process::Command::new("xdg-open")
|
||||
.arg(dir)
|
||||
.stdout(std::process::Stdio::null())
|
||||
.stderr(std::process::Stdio::null())
|
||||
.spawn()
|
||||
{
|
||||
if let Err(e) = open::that(dir) {
|
||||
tracing::error!("Failed to open directory: {}", e);
|
||||
}
|
||||
}
|
||||
@@ -318,10 +346,11 @@ pub fn render(
|
||||
loading_text: &str,
|
||||
empty_text: &str,
|
||||
) {
|
||||
let theme = THEME.as_ref();
|
||||
if state.loading {
|
||||
frame.render_widget(
|
||||
Paragraph::new(loading_text)
|
||||
.style(Style::default().fg(THEME.content_list.text_secondary_fg)),
|
||||
.style(Style::default().fg(theme.text_dim())),
|
||||
area,
|
||||
);
|
||||
return;
|
||||
@@ -332,7 +361,7 @@ pub fn render(
|
||||
if filtered.is_empty() {
|
||||
frame.render_widget(
|
||||
Paragraph::new(empty_text)
|
||||
.style(Style::default().fg(THEME.content_list.text_secondary_fg)),
|
||||
.style(Style::default().fg(theme.text_dim())),
|
||||
area,
|
||||
);
|
||||
return;
|
||||
@@ -354,67 +383,57 @@ pub fn render(
|
||||
.collect();
|
||||
|
||||
let builder = ListBuilder::new(move |context| {
|
||||
let theme = THEME.as_ref();
|
||||
let (name, description, enabled, icon_pixels) = &snapshot[context.index];
|
||||
let show_selected = is_focused && context.is_selected;
|
||||
let use_mc_colors = *enabled && !show_selected;
|
||||
let use_mc_colors = *enabled;
|
||||
|
||||
let stripe_bg = if context.index % 2 == 0 {
|
||||
Color::Reset
|
||||
theme.background()
|
||||
} else {
|
||||
THEME.content_list.row_alt_bg
|
||||
theme.stripe()
|
||||
};
|
||||
|
||||
let (name_style, description_style, background) = match (*enabled, show_selected) {
|
||||
(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.content_list.text_fg)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
Style::default().fg(THEME.content_list.text_secondary_fg),
|
||||
(true, true) => (
|
||||
Style::default().fg(theme.accent()).add_modifier(Modifier::BOLD),
|
||||
Style::default().fg(theme.text_dim()),
|
||||
stripe_bg,
|
||||
),
|
||||
(true, false) => (
|
||||
Style::default()
|
||||
.fg(theme.text())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
Style::default().fg(theme.text_dim()),
|
||||
stripe_bg,
|
||||
),
|
||||
(false, true) => (
|
||||
Style::default().fg(theme.accent()).add_modifier(Modifier::CROSSED_OUT),
|
||||
Style::default().fg(theme.text_dim()),
|
||||
stripe_bg,
|
||||
),
|
||||
(false, false) => (
|
||||
Style::default().fg(theme.text_dim()).add_modifier(Modifier::CROSSED_OUT),
|
||||
Style::default().fg(theme.text_dim()),
|
||||
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();
|
||||
let stripped_desc = strip_mc_codes(description);
|
||||
let has_description = !stripped_desc.trim().is_empty();
|
||||
let full_desc = strip_mc_codes(description);
|
||||
let stripped_desc = full_desc.lines().next().unwrap_or("").trim().to_string();
|
||||
let has_description = !stripped_desc.is_empty();
|
||||
let compact = !has_icon && !has_description;
|
||||
|
||||
let selector = if show_selected {
|
||||
Span::styled("\u{258c}", Style::default().fg(theme.accent()))
|
||||
} else {
|
||||
Span::raw(" ")
|
||||
};
|
||||
|
||||
if compact {
|
||||
let mut line = Vec::new();
|
||||
line.push(Span::raw(" "));
|
||||
line.push(selector.clone());
|
||||
if use_mc_colors {
|
||||
line.extend(parse_mc_text(name, name_style));
|
||||
} else {
|
||||
@@ -425,9 +444,17 @@ pub fn render(
|
||||
(item, 1)
|
||||
} else if has_icon {
|
||||
let icon_row_count = icon_pixels.as_ref().map(|r| r.len()).unwrap_or(0);
|
||||
let height = icon_row_count.max(2) as u16;
|
||||
let text_rows = if has_description { 2 } else { 1 }; // name + optional description
|
||||
let height = icon_row_count.max(text_rows) as u16;
|
||||
|
||||
let mut line_0 = icon_spans(icon_pixels.as_ref(), 0);
|
||||
let pad = if show_selected {
|
||||
Span::styled("\u{258c}", Style::default().fg(theme.accent()))
|
||||
} else {
|
||||
Span::raw(" ")
|
||||
};
|
||||
|
||||
let mut line_0 = vec![selector.clone()];
|
||||
line_0.extend(icon_spans(icon_pixels.as_ref(), 0));
|
||||
line_0.push(Span::raw(" "));
|
||||
if use_mc_colors {
|
||||
line_0.extend(parse_mc_text(name, name_style));
|
||||
@@ -435,41 +462,51 @@ pub fn render(
|
||||
line_0.push(Span::styled(strip_mc_codes(name), name_style));
|
||||
}
|
||||
|
||||
let mut line_1 = icon_spans(icon_pixels.as_ref(), 1);
|
||||
line_1.push(Span::raw(" "));
|
||||
if use_mc_colors {
|
||||
line_1.extend(parse_mc_text(description, description_style));
|
||||
} else {
|
||||
line_1.push(Span::styled(stripped_desc, description_style));
|
||||
let mut lines = vec![Line::from(line_0)];
|
||||
|
||||
if has_description {
|
||||
let mut row = vec![pad.clone()];
|
||||
row.extend(icon_spans(icon_pixels.as_ref(), 1));
|
||||
row.push(Span::raw(" "));
|
||||
row.push(Span::styled(stripped_desc.clone(), description_style));
|
||||
lines.push(Line::from(row));
|
||||
}
|
||||
|
||||
let mut lines = vec![Line::from(line_0), Line::from(line_1)];
|
||||
for r in 2..icon_row_count {
|
||||
lines.push(Line::from(icon_spans(icon_pixels.as_ref(), r)));
|
||||
let desc_rows = if has_description { 1 } else { 0 };
|
||||
for r in (1 + desc_rows)..icon_row_count {
|
||||
let mut row = vec![pad.clone()];
|
||||
row.extend(icon_spans(icon_pixels.as_ref(), r));
|
||||
lines.push(Line::from(row));
|
||||
}
|
||||
|
||||
let item = Text::from(lines).style(Style::default().bg(background));
|
||||
(item, height)
|
||||
} else {
|
||||
let mut line_0 = Vec::new();
|
||||
line_0.push(Span::raw(" "));
|
||||
line_0.push(selector.clone());
|
||||
if use_mc_colors {
|
||||
line_0.extend(parse_mc_text(name, name_style));
|
||||
} else {
|
||||
line_0.push(Span::styled(strip_mc_codes(name), name_style));
|
||||
}
|
||||
|
||||
let mut line_1 = Vec::new();
|
||||
line_1.push(Span::raw(" "));
|
||||
if use_mc_colors {
|
||||
line_1.extend(parse_mc_text(description, description_style));
|
||||
} else {
|
||||
line_1.push(Span::styled(stripped_desc, description_style));
|
||||
let mut lines = vec![Line::from(line_0)];
|
||||
|
||||
if has_description {
|
||||
let pad = if show_selected {
|
||||
Span::styled("\u{258c}", Style::default().fg(theme.accent()))
|
||||
} else {
|
||||
Span::raw(" ")
|
||||
};
|
||||
lines.push(Line::from(vec![
|
||||
pad,
|
||||
Span::styled(stripped_desc.clone(), description_style),
|
||||
]));
|
||||
}
|
||||
|
||||
let item = Text::from(vec![Line::from(line_0), Line::from(line_1)])
|
||||
.style(Style::default().bg(background));
|
||||
(item, 2)
|
||||
let height = lines.len() as u16;
|
||||
let item = Text::from(lines).style(Style::default().bg(background));
|
||||
(item, height)
|
||||
}
|
||||
});
|
||||
|
||||
@@ -488,7 +525,7 @@ pub fn render(
|
||||
.begin_symbol(Some("\u{25b2}"))
|
||||
.style(
|
||||
Style::default()
|
||||
.fg(THEME.content_list.border_focused_fg)
|
||||
.fg(theme.text_dim())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.thumb_symbol("\u{2551}")
|
||||
@@ -588,18 +625,21 @@ fn icon_spans(icon_pixels: Option<&Vec<Vec<IconCell>>>, row: usize) -> Vec<Span<
|
||||
match icon_pixels.and_then(|rows| rows.get(row)) {
|
||||
Some(cols) => cols
|
||||
.iter()
|
||||
.map(|&(fg_r, fg_g, fg_b, bg_r, bg_g, bg_b)| {
|
||||
.map(|cell| {
|
||||
Span::styled(
|
||||
"\u{2584}",
|
||||
Style::default()
|
||||
.fg(Color::Rgb(fg_r, fg_g, fg_b))
|
||||
.bg(Color::Rgb(bg_r, bg_g, bg_b)),
|
||||
.fg(Color::Rgb(cell.fg_r, cell.fg_g, cell.fg_b))
|
||||
.bg(Color::Rgb(cell.bg_r, cell.bg_g, cell.bg_b)),
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
None => vec![Span::styled(
|
||||
" ",
|
||||
Style::default().fg(THEME.content_list.text_secondary_fg),
|
||||
)],
|
||||
None => {
|
||||
let theme = THEME.as_ref();
|
||||
vec![Span::styled(
|
||||
" ",
|
||||
Style::default().fg(theme.text_dim()),
|
||||
)]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
pub mod list;
|
||||
pub mod tabs;
|
||||
|
||||
pub use tabs::{ContentTab, render, title};
|
||||
pub use list::{ContentListState, handle_key, handle_key_no_toggle};
|
||||
@@ -7,10 +7,10 @@ use ratatui::{
|
||||
};
|
||||
use throbber_widgets_tui::{Throbber, ThrobberState};
|
||||
|
||||
use crate::tui::layout::FocusedArea;
|
||||
use crate::tui::theme::THEME;
|
||||
use crate::tui::app::FocusedArea;
|
||||
use crate::config::theme::{THEME, BORDER_STYLE};
|
||||
|
||||
use super::styled_title;
|
||||
use crate::tui::widgets::styled_title;
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ContentTab {
|
||||
@@ -69,20 +69,21 @@ pub fn render(
|
||||
focused: FocusedArea,
|
||||
tab: ContentTab,
|
||||
instance: Option<&crate::instance::InstanceConfig>,
|
||||
mods_state: &mut super::content_list::ContentListState,
|
||||
resource_packs_state: &mut super::content_list::ContentListState,
|
||||
shaders_state: &mut super::content_list::ContentListState,
|
||||
worlds_state: &mut super::content_list::ContentListState,
|
||||
screenshots_state: &mut super::screenshots_grid::ScreenshotsState,
|
||||
logs_state: &mut super::logs_viewer::LogsState,
|
||||
mods_state: &mut super::list::ContentListState,
|
||||
resource_packs_state: &mut super::list::ContentListState,
|
||||
shaders_state: &mut super::list::ContentListState,
|
||||
worlds_state: &mut super::list::ContentListState,
|
||||
screenshots_state: &mut crate::tui::widgets::screenshots_grid::ScreenshotsState,
|
||||
logs_state: &mut crate::tui::widgets::logs_viewer::LogsState,
|
||||
instances_dir: &std::path::Path,
|
||||
) {
|
||||
let theme = THEME.as_ref();
|
||||
let is_focused = focused == FocusedArea::Content;
|
||||
|
||||
let border_color = if is_focused {
|
||||
THEME.content.border_focused_fg
|
||||
theme.accent()
|
||||
} else {
|
||||
THEME.content.border_unfocused_fg
|
||||
theme.border()
|
||||
};
|
||||
|
||||
let tab_titles: Vec<Span> = ContentTab::ALL
|
||||
@@ -93,21 +94,18 @@ pub fn render(
|
||||
if i > 0 {
|
||||
spans.push(Span::styled(
|
||||
"\u{2022}",
|
||||
Style::default().fg(THEME.content.border_unfocused_fg),
|
||||
Style::default().fg(theme.text_dim()),
|
||||
));
|
||||
}
|
||||
if i == tab.index() {
|
||||
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);
|
||||
}
|
||||
let style = Style::default()
|
||||
.fg(theme.accent())
|
||||
.add_modifier(Modifier::BOLD);
|
||||
spans.push(Span::styled(format!(" {} ", t.label()), style));
|
||||
} else {
|
||||
spans.push(Span::styled(
|
||||
format!(" {} ", t.label()),
|
||||
Style::default().fg(THEME.content.text_fg),
|
||||
Style::default().fg(theme.text()),
|
||||
));
|
||||
}
|
||||
spans
|
||||
@@ -132,7 +130,7 @@ pub fn render(
|
||||
let mut block = Block::default()
|
||||
.title_top(Line::from(tab_titles))
|
||||
.borders(Borders::ALL)
|
||||
.border_type(THEME.general.border_type.to_border_type())
|
||||
.border_type(BORDER_STYLE.to_border_type())
|
||||
.border_style(Style::default().fg(border_color));
|
||||
|
||||
if let Some(sl) = search_line {
|
||||
@@ -179,7 +177,7 @@ pub fn render(
|
||||
}
|
||||
}
|
||||
})
|
||||
} else if focused == FocusedArea::Profiles {
|
||||
} else if focused == FocusedArea::Instances {
|
||||
Some(&[
|
||||
("l", " launch"),
|
||||
("⏎", " content"),
|
||||
@@ -196,7 +194,7 @@ pub fn render(
|
||||
};
|
||||
|
||||
if let Some(kb) = kb {
|
||||
let lines = super::popups::keybind_lines_wrapped(kb, area.width.saturating_sub(2));
|
||||
let lines = crate::tui::widgets::popups::keybind_lines_wrapped(kb, area.width.saturating_sub(2));
|
||||
for line in lines {
|
||||
block = block.title_bottom(line);
|
||||
}
|
||||
@@ -214,8 +212,9 @@ pub fn render(
|
||||
&instance.name,
|
||||
crate::instance::scan_mods,
|
||||
);
|
||||
mods_state.watch_dir(instances_dir.join(&instance.name).join(".minecraft").join("mods"));
|
||||
}
|
||||
super::content_list::render(
|
||||
super::list::render(
|
||||
frame,
|
||||
content_area,
|
||||
mods_state,
|
||||
@@ -226,7 +225,7 @@ pub fn render(
|
||||
} else {
|
||||
frame.render_widget(
|
||||
Paragraph::new("No instance selected.")
|
||||
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
|
||||
.style(Style::default().fg(theme.text_dim())),
|
||||
content_area,
|
||||
);
|
||||
}
|
||||
@@ -239,8 +238,9 @@ pub fn render(
|
||||
&instance.name,
|
||||
crate::instance::scan_resource_packs,
|
||||
);
|
||||
resource_packs_state.watch_dir(instances_dir.join(&instance.name).join(".minecraft").join("resourcepacks"));
|
||||
}
|
||||
super::content_list::render(
|
||||
super::list::render(
|
||||
frame,
|
||||
content_area,
|
||||
resource_packs_state,
|
||||
@@ -251,7 +251,7 @@ pub fn render(
|
||||
} else {
|
||||
frame.render_widget(
|
||||
Paragraph::new("No instance selected.")
|
||||
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
|
||||
.style(Style::default().fg(theme.text_dim())),
|
||||
content_area,
|
||||
);
|
||||
}
|
||||
@@ -264,8 +264,9 @@ pub fn render(
|
||||
&instance.name,
|
||||
crate::instance::scan_shaders,
|
||||
);
|
||||
shaders_state.watch_dir(instances_dir.join(&instance.name).join(".minecraft").join("shaderpacks"));
|
||||
}
|
||||
super::content_list::render(
|
||||
super::list::render(
|
||||
frame,
|
||||
content_area,
|
||||
shaders_state,
|
||||
@@ -276,7 +277,7 @@ pub fn render(
|
||||
} else {
|
||||
frame.render_widget(
|
||||
Paragraph::new("No instance selected.")
|
||||
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
|
||||
.style(Style::default().fg(theme.text_dim())),
|
||||
content_area,
|
||||
);
|
||||
}
|
||||
@@ -286,11 +287,11 @@ pub fn render(
|
||||
if logs_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
|
||||
logs_state.start_load(instances_dir, &instance.name);
|
||||
}
|
||||
super::logs_viewer::render(frame, content_area, logs_state, is_focused);
|
||||
crate::tui::widgets::logs_viewer::render(frame, content_area, logs_state, is_focused);
|
||||
} else {
|
||||
frame.render_widget(
|
||||
Paragraph::new("No instance selected.")
|
||||
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
|
||||
.style(Style::default().fg(theme.text_dim())),
|
||||
content_area,
|
||||
);
|
||||
}
|
||||
@@ -300,11 +301,11 @@ pub fn render(
|
||||
if screenshots_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
|
||||
screenshots_state.start_load(instances_dir, &instance.name);
|
||||
}
|
||||
super::screenshots_grid::render(frame, content_area, screenshots_state, is_focused);
|
||||
crate::tui::widgets::screenshots_grid::render(frame, content_area, screenshots_state, is_focused);
|
||||
} else {
|
||||
frame.render_widget(
|
||||
Paragraph::new("No instance selected.")
|
||||
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
|
||||
.style(Style::default().fg(theme.text_dim())),
|
||||
content_area,
|
||||
);
|
||||
}
|
||||
@@ -317,8 +318,9 @@ pub fn render(
|
||||
&instance.name,
|
||||
crate::instance::scan_worlds,
|
||||
);
|
||||
worlds_state.watch_dir(instances_dir.join(&instance.name).join(".minecraft").join("saves"));
|
||||
}
|
||||
super::content_list::render(
|
||||
super::list::render(
|
||||
frame,
|
||||
content_area,
|
||||
worlds_state,
|
||||
@@ -329,7 +331,7 @@ pub fn render(
|
||||
} else {
|
||||
frame.render_widget(
|
||||
Paragraph::new("No instance selected.")
|
||||
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
|
||||
.style(Style::default().fg(theme.text_dim())),
|
||||
content_area,
|
||||
);
|
||||
}
|
||||
@@ -344,16 +346,17 @@ pub fn title(
|
||||
instance: Option<&crate::instance::InstanceConfig>,
|
||||
throbber_state: &mut ThrobberState,
|
||||
) {
|
||||
let theme = THEME.as_ref();
|
||||
let color = if focused == FocusedArea::Content {
|
||||
THEME.content.border_focused_fg
|
||||
theme.accent()
|
||||
} else {
|
||||
THEME.content.border_unfocused_fg
|
||||
theme.border()
|
||||
};
|
||||
|
||||
let block = Block::default()
|
||||
.title(styled_title("Content", true))
|
||||
.borders(Borders::ALL)
|
||||
.border_type(THEME.general.border_type.to_border_type())
|
||||
.border_type(BORDER_STYLE.to_border_type())
|
||||
.border_style(Style::default().fg(color));
|
||||
|
||||
let inner = block.inner(area);
|
||||
@@ -363,7 +366,7 @@ pub fn title(
|
||||
None => {
|
||||
frame.render_widget(
|
||||
Paragraph::new("No instance selected")
|
||||
.style(Style::default().fg(THEME.content.tab_inactive_fg)),
|
||||
.style(Style::default().fg(theme.text_dim())),
|
||||
inner,
|
||||
);
|
||||
}
|
||||
@@ -382,12 +385,12 @@ pub fn title(
|
||||
.label(inst.name.as_str())
|
||||
.style(
|
||||
Style::default()
|
||||
.fg(THEME.content.text_fg)
|
||||
.fg(theme.text())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.throbber_style(
|
||||
Style::default()
|
||||
.fg(THEME.general.success)
|
||||
.fg(theme.success())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.throbber_set(throbber_widgets_tui::BRAILLE_EIGHT_DOUBLE)
|
||||
@@ -400,13 +403,13 @@ pub fn title(
|
||||
Span::styled(
|
||||
"\u{2717} ",
|
||||
Style::default()
|
||||
.fg(THEME.general.error)
|
||||
.fg(theme.error())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
Span::styled(
|
||||
inst.name.as_str(),
|
||||
Style::default()
|
||||
.fg(THEME.content.text_fg)
|
||||
.fg(theme.text())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])),
|
||||
@@ -418,7 +421,7 @@ pub fn title(
|
||||
Paragraph::new(Span::styled(
|
||||
inst.name.as_str(),
|
||||
Style::default()
|
||||
.fg(THEME.content.text_fg)
|
||||
.fg(theme.text())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)),
|
||||
left_area,
|
||||
@@ -432,7 +435,7 @@ pub fn title(
|
||||
};
|
||||
frame.render_widget(
|
||||
Paragraph::new(loader_str)
|
||||
.style(Style::default().fg(THEME.content.border_focused_fg))
|
||||
.style(Style::default().fg(theme.text_dim()))
|
||||
.alignment(Alignment::Right),
|
||||
right_area,
|
||||
);
|
||||
@@ -7,8 +7,8 @@ use ratatui::{
|
||||
};
|
||||
|
||||
use crate::instance::models::InstanceConfig;
|
||||
use crate::tui::layout::FocusedArea;
|
||||
use crate::tui::theme::THEME;
|
||||
use crate::tui::app::FocusedArea;
|
||||
use crate::config::theme::{THEME, BORDER_STYLE};
|
||||
|
||||
use super::styled_title;
|
||||
|
||||
@@ -19,16 +19,17 @@ pub fn render(
|
||||
instance: Option<&InstanceConfig>,
|
||||
_instances_dir: &std::path::Path,
|
||||
) {
|
||||
let theme = THEME.as_ref();
|
||||
let color = if focused == FocusedArea::Settings {
|
||||
THEME.details.border_focused_fg
|
||||
theme.accent()
|
||||
} else {
|
||||
THEME.details.border_unfocused_fg
|
||||
theme.border()
|
||||
};
|
||||
|
||||
let mut block = Block::default()
|
||||
.title(styled_title("Settings", true))
|
||||
.borders(Borders::ALL)
|
||||
.border_type(THEME.general.border_type.to_border_type())
|
||||
.border_type(BORDER_STYLE.to_border_type())
|
||||
.border_style(Style::default().fg(color));
|
||||
|
||||
if focused == FocusedArea::Settings {
|
||||
@@ -51,17 +52,17 @@ pub fn render(
|
||||
let Some(inst) = instance else {
|
||||
frame.render_widget(
|
||||
Paragraph::new("No instance selected.")
|
||||
.style(Style::default().fg(THEME.details.label_fg)),
|
||||
.style(Style::default().fg(theme.text_dim())),
|
||||
inner,
|
||||
);
|
||||
return;
|
||||
};
|
||||
|
||||
let label_style = Style::default().fg(THEME.details.label_fg);
|
||||
let label_style = Style::default().fg(theme.text_dim());
|
||||
let value_style = Style::default()
|
||||
.fg(THEME.details.value_fg)
|
||||
.fg(theme.text())
|
||||
.add_modifier(Modifier::BOLD);
|
||||
let dim_style = Style::default().fg(THEME.details.border_unfocused_fg);
|
||||
let dim_style = Style::default().fg(theme.text_dim());
|
||||
|
||||
let memory_min = inst.memory_min.as_deref().unwrap_or("512M");
|
||||
let memory_max = inst.memory_max.as_deref().unwrap_or("2G");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::tui::theme::THEME;
|
||||
use crate::config::theme::{THEME, BORDER_STYLE};
|
||||
use crossterm::event::KeyCode;
|
||||
use ratatui::{
|
||||
layout::Rect,
|
||||
@@ -11,7 +11,7 @@ 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;
|
||||
use crate::tui::app::FocusedArea;
|
||||
|
||||
use super::{search::SearchState, styled_title, WidgetKey};
|
||||
|
||||
@@ -33,17 +33,6 @@ 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;
|
||||
match loader {
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct State {
|
||||
pub instances: Vec<InstanceConfig>,
|
||||
@@ -202,16 +191,17 @@ impl WidgetKey for State {
|
||||
}
|
||||
|
||||
pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut State) {
|
||||
let color = if focused == FocusedArea::Profiles {
|
||||
THEME.profiles.border_focused_fg
|
||||
let theme = THEME.as_ref();
|
||||
let color = if focused == FocusedArea::Instances {
|
||||
theme.accent()
|
||||
} else {
|
||||
THEME.profiles.border_unfocused_fg
|
||||
theme.border()
|
||||
};
|
||||
|
||||
let mut block = Block::default()
|
||||
.title(styled_title("Profiles", true))
|
||||
.title(styled_title("Instances", true))
|
||||
.borders(Borders::ALL)
|
||||
.border_type(THEME.general.border_type.to_border_type())
|
||||
.border_type(BORDER_STYLE.to_border_type())
|
||||
.border_style(Style::default().fg(color));
|
||||
|
||||
if let Some(search_line) = state.search.title_line() {
|
||||
@@ -229,56 +219,54 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
|
||||
let count = filtered.len();
|
||||
|
||||
let builder = ListBuilder::new(|context| {
|
||||
let theme = THEME.as_ref();
|
||||
let idx = filtered[context.index];
|
||||
let instance = &state.instances[idx];
|
||||
|
||||
let stripe_bg = if context.index % 2 == 0 {
|
||||
THEME.general.bg
|
||||
theme.background()
|
||||
} else {
|
||||
THEME.profiles.row_alt_bg
|
||||
theme.stripe()
|
||||
};
|
||||
|
||||
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,
|
||||
Style::default().fg(THEME.profiles.selected_fg),
|
||||
THEME.profiles.selected_bg,
|
||||
Style::default().fg(theme.accent()).add_modifier(Modifier::BOLD),
|
||||
Style::default().fg(theme.text_dim()),
|
||||
stripe_bg,
|
||||
)
|
||||
} else {
|
||||
(
|
||||
Style::default()
|
||||
.fg(THEME.profiles.border_focused_fg)
|
||||
.fg(theme.text())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
Style::default().fg(THEME.profiles.border_unfocused_fg),
|
||||
Style::default().fg(theme.text_dim()),
|
||||
stripe_bg,
|
||||
)
|
||||
};
|
||||
|
||||
let stripe = Span::styled(
|
||||
"\u{258c} ",
|
||||
Style::default().fg(loader_color(instance.loader)),
|
||||
);
|
||||
let selector = if context.is_selected {
|
||||
Span::styled("\u{258c} ", Style::default().fg(theme.accent()))
|
||||
} else {
|
||||
Span::raw(" ")
|
||||
};
|
||||
|
||||
let is_renaming = context.is_selected && state.renaming.is_some();
|
||||
let name_line = if is_renaming {
|
||||
let rename_val = state.renaming.as_deref().unwrap_or("");
|
||||
Line::from(vec![
|
||||
stripe.clone(),
|
||||
Span::styled(rename_val, Style::default().fg(THEME.profiles.text_fg)),
|
||||
selector.clone(),
|
||||
Span::styled(rename_val, Style::default().fg(theme.text())),
|
||||
Span::styled(
|
||||
"\u{2588}",
|
||||
Style::default()
|
||||
.fg(THEME.profiles.border_focused_fg)
|
||||
.fg(theme.text_dim())
|
||||
.add_modifier(Modifier::SLOW_BLINK),
|
||||
),
|
||||
])
|
||||
} else {
|
||||
Line::from(vec![
|
||||
stripe.clone(),
|
||||
selector.clone(),
|
||||
Span::styled(instance.name.as_str(), name_style),
|
||||
])
|
||||
};
|
||||
@@ -286,16 +274,16 @@ 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.profiles.running_fg),
|
||||
Style::default().fg(theme.success()),
|
||||
),
|
||||
Some(RunState::Running) | Some(RunState::Starting) => (
|
||||
"Playing".to_string(),
|
||||
Style::default().fg(THEME.profiles.running_fg),
|
||||
Style::default().fg(theme.success()),
|
||||
),
|
||||
_ => (format_last_played(instance.last_played), meta_style),
|
||||
};
|
||||
|
||||
let meta_line = Line::from(vec![stripe, Span::styled(meta_text, meta_text_style)]);
|
||||
let meta_line = Line::from(vec![selector.clone(), Span::styled(meta_text, meta_text_style)]);
|
||||
|
||||
let item = Text::from(vec![name_line, meta_line]).style(Style::default().bg(bg));
|
||||
(item, 2)
|
||||
@@ -311,7 +299,7 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut S
|
||||
.begin_symbol(Some("\u{25b2}"))
|
||||
.style(
|
||||
Style::default()
|
||||
.fg(THEME.profiles.border_focused_fg)
|
||||
.fg(theme.text_dim())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.thumb_symbol("\u{2551}")
|
||||
@@ -4,7 +4,7 @@ use std::sync::{Arc, Mutex};
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
use ratatui::{
|
||||
layout::{Constraint, Layout, Rect},
|
||||
style::{Color, Modifier, Style},
|
||||
style::{Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, Borders, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState},
|
||||
Frame,
|
||||
@@ -12,7 +12,7 @@ use ratatui::{
|
||||
use tui_widget_list::{ListBuilder, ListState as TuiListState, ListView};
|
||||
|
||||
use crate::instance::log_files::{read_log_file, scan_log_files, LogFileEntry};
|
||||
use crate::tui::theme::THEME;
|
||||
use crate::config::theme::{THEME, BORDER_STYLE};
|
||||
|
||||
type PendingLogs = Arc<Mutex<Option<(String, Vec<LogFileEntry>)>>>;
|
||||
|
||||
@@ -342,9 +342,10 @@ 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) {
|
||||
let theme = THEME.as_ref();
|
||||
if state.loading {
|
||||
frame.render_widget(
|
||||
Paragraph::new("Loading logs...").style(Style::default().fg(THEME.logs.text_fg)),
|
||||
Paragraph::new("Loading logs...").style(Style::default().fg(theme.text_dim())),
|
||||
area,
|
||||
);
|
||||
return;
|
||||
@@ -355,7 +356,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.logs.text_fg)),
|
||||
Paragraph::new("No logs yet.").style(Style::default().fg(theme.text_dim())),
|
||||
area,
|
||||
);
|
||||
return;
|
||||
@@ -380,16 +381,17 @@ fn render_list(
|
||||
is_focused: bool,
|
||||
has_live: bool,
|
||||
) {
|
||||
let theme = THEME.as_ref();
|
||||
let list_focused = is_focused && !state.viewer_focused;
|
||||
let border_color = if list_focused {
|
||||
THEME.logs.border_focused_fg
|
||||
theme.accent()
|
||||
} else {
|
||||
THEME.logs.border_unfocused_fg
|
||||
theme.border()
|
||||
};
|
||||
|
||||
let block = Block::default()
|
||||
.borders(Borders::RIGHT)
|
||||
.border_type(THEME.general.border_type.to_border_type())
|
||||
.border_type(BORDER_STYLE.to_border_type())
|
||||
.border_style(Style::default().fg(border_color));
|
||||
|
||||
let inner = block.inner(area);
|
||||
@@ -413,34 +415,27 @@ fn render_list(
|
||||
let show_selected = list_focused && context.is_selected;
|
||||
|
||||
let style = if *is_live && show_selected {
|
||||
let s = Style::default().fg(THEME.logs.running_fg);
|
||||
if THEME.logs.selected_bold {
|
||||
s.add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
s
|
||||
}
|
||||
Style::default().fg(theme.success()).add_modifier(Modifier::BOLD)
|
||||
} else if *is_live {
|
||||
Style::default().fg(THEME.logs.running_fg)
|
||||
Style::default().fg(theme.success())
|
||||
} else if show_selected {
|
||||
let s = Style::default().fg(THEME.logs.selected_fg);
|
||||
if THEME.logs.selected_bold {
|
||||
s.add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
s
|
||||
}
|
||||
Style::default().fg(theme.accent()).add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
Style::default().fg(THEME.logs.text_fg)
|
||||
Style::default().fg(theme.text())
|
||||
};
|
||||
|
||||
let bg = if show_selected {
|
||||
THEME.logs.selected_bg
|
||||
} else if context.index % 2 == 0 {
|
||||
Color::Reset
|
||||
let bg = if context.index % 2 == 0 {
|
||||
theme.background()
|
||||
} else {
|
||||
THEME.logs.row_alt_bg
|
||||
theme.stripe()
|
||||
};
|
||||
|
||||
let item = ratatui::text::Text::from(Line::from(Span::styled(name.clone(), style)))
|
||||
let selector = if show_selected {
|
||||
Span::styled("\u{258c} ", Style::default().fg(theme.accent()))
|
||||
} else {
|
||||
Span::raw(" ")
|
||||
};
|
||||
let item = ratatui::text::Text::from(Line::from(vec![selector, Span::styled(name.clone(), style)]))
|
||||
.style(Style::default().bg(bg));
|
||||
(item, 1)
|
||||
});
|
||||
@@ -460,7 +455,7 @@ fn render_list(
|
||||
.begin_symbol(Some("\u{25b2}"))
|
||||
.style(
|
||||
Style::default()
|
||||
.fg(THEME.logs.border_focused_fg)
|
||||
.fg(theme.accent())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.thumb_symbol("\u{2551}")
|
||||
@@ -478,6 +473,7 @@ fn render_viewer(
|
||||
_is_focused: bool,
|
||||
has_live: bool,
|
||||
) {
|
||||
let theme = THEME.as_ref();
|
||||
let is_live = has_live && state.list_state.selected == Some(0);
|
||||
|
||||
let all_lines: Vec<String> = if is_live {
|
||||
@@ -528,7 +524,7 @@ fn render_viewer(
|
||||
.begin_symbol(Some("\u{25b2}"))
|
||||
.style(
|
||||
Style::default()
|
||||
.fg(THEME.logs.border_focused_fg)
|
||||
.fg(theme.accent())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.thumb_symbol("\u{2551}")
|
||||
@@ -540,16 +536,15 @@ fn render_viewer(
|
||||
}
|
||||
|
||||
fn line_level_style(line: &str) -> Style {
|
||||
let theme = THEME.as_ref();
|
||||
let upper = line.to_uppercase();
|
||||
if upper.contains("ERROR") || upper.contains("FATAL") || upper.contains("[STDERR]") {
|
||||
Style::default().fg(THEME.logs.error_fg)
|
||||
Style::default().fg(theme.error())
|
||||
} else if upper.contains("WARN") {
|
||||
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)
|
||||
Style::default().fg(theme.warning())
|
||||
} else if upper.contains("DEBUG") || upper.contains("TRACE") {
|
||||
Style::default().fg(theme.text_dim())
|
||||
} else {
|
||||
Style::default().fg(THEME.logs.text_fg)
|
||||
Style::default().fg(theme.text())
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::tui::theme::THEME;
|
||||
use crate::config::theme::THEME;
|
||||
use crossterm::event::KeyEvent;
|
||||
use ratatui::{
|
||||
style::Style,
|
||||
@@ -7,16 +7,16 @@ use ratatui::{
|
||||
|
||||
pub mod account;
|
||||
pub mod content;
|
||||
pub mod content_list;
|
||||
pub mod details;
|
||||
pub mod logs_viewer;
|
||||
pub mod popups;
|
||||
pub mod profiles;
|
||||
pub mod instances;
|
||||
pub mod screenshots_grid;
|
||||
pub mod search;
|
||||
pub mod status;
|
||||
|
||||
pub fn styled_title(title: &str, highlight: bool) -> Line<'_> {
|
||||
let theme = THEME.as_ref();
|
||||
if !highlight || title.is_empty() {
|
||||
Line::from(Span::raw(title))
|
||||
} else {
|
||||
@@ -24,8 +24,8 @@ 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.general.accent)),
|
||||
Span::raw(rest),
|
||||
Span::styled(first, Style::default().fg(theme.accent())),
|
||||
Span::styled(rest, Style::default().fg(theme.text())),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use ratatui::{
|
||||
widgets::{Block, Clear, Widget},
|
||||
};
|
||||
|
||||
use crate::tui::theme::THEME;
|
||||
use crate::config::theme::BORDER_STYLE;
|
||||
|
||||
type ContentFn<'a> = Box<dyn Fn(Rect, &mut Buffer) + 'a>;
|
||||
|
||||
@@ -29,7 +29,7 @@ impl<'a> Widget for PopupFrame<'a> {
|
||||
|
||||
let mut block = Block::bordered()
|
||||
.title_top(self.title)
|
||||
.border_type(THEME.general.border_type.to_border_type())
|
||||
.border_type(BORDER_STYLE.to_border_type())
|
||||
.border_style(Style::default().fg(self.border_color));
|
||||
|
||||
if let Some(sl) = self.search_line {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use once_cell::sync::Lazy;
|
||||
use std::sync::LazyLock;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use ratatui::{
|
||||
@@ -9,9 +9,9 @@ use ratatui::{
|
||||
widgets::{Paragraph, Widget},
|
||||
};
|
||||
|
||||
use crate::tui::theme::THEME;
|
||||
use crate::config::theme::THEME;
|
||||
|
||||
static CONFIRM_STATE: Lazy<Mutex<ConfirmState>> = Lazy::new(|| Mutex::new(ConfirmState::default()));
|
||||
static CONFIRM_STATE: LazyLock<Mutex<ConfirmState>> = LazyLock::new(|| Mutex::new(ConfirmState::default()));
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct ConfirmState {
|
||||
@@ -63,23 +63,27 @@ impl Widget for ConfirmPopup {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
use super::{base::PopupFrame, keybind_line};
|
||||
|
||||
let theme = THEME.as_ref();
|
||||
let title = Line::from(vec![Span::styled(
|
||||
format!(" Delete '{}' ", self.instance_name),
|
||||
Style::default()
|
||||
.fg(THEME.popup_confirm.border_fg)
|
||||
.fg(theme.text_dim())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)]);
|
||||
let kb = keybind_line(&[("Enter", " confirm")]);
|
||||
|
||||
let border_color = theme.text_dim();
|
||||
let bg_color = theme.surface();
|
||||
let text_color = theme.text();
|
||||
let popup = PopupFrame {
|
||||
title,
|
||||
border_color: THEME.popup_confirm.border_fg,
|
||||
bg: Some(THEME.popup_confirm.highlight_bg),
|
||||
border_color,
|
||||
bg: Some(bg_color),
|
||||
keybinds: Some(kb),
|
||||
search_line: None,
|
||||
content: Box::new(|inner, buf| {
|
||||
content: Box::new(move |inner, buf| {
|
||||
Paragraph::new("This will permanently remove the instance")
|
||||
.style(Style::default().fg(THEME.popup_confirm.text_fg))
|
||||
.style(Style::default().fg(text_color))
|
||||
.render(inner, buf);
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -10,7 +10,7 @@ use tracing::Level;
|
||||
use super::base::PopupFrame;
|
||||
use crate::config::SETTINGS;
|
||||
use crate::tui::error_buffer::ErrorEvent;
|
||||
use crate::tui::theme::THEME;
|
||||
use crate::config::theme::THEME;
|
||||
|
||||
pub struct ErrorPopup {
|
||||
pub event: ErrorEvent,
|
||||
@@ -24,31 +24,34 @@ impl ErrorPopup {
|
||||
|
||||
impl Widget for ErrorPopup {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
let theme = THEME.as_ref();
|
||||
let (border_color, label) = match self.event.level {
|
||||
Level::ERROR => (THEME.popup_error.error_fg, "ERROR"),
|
||||
Level::WARN => (THEME.popup_error.warn_fg, "WARN"),
|
||||
_ => (THEME.popup_error.border_fg, "INFO"),
|
||||
Level::ERROR => (theme.error(), "ERROR"),
|
||||
Level::WARN => (theme.warning(), "WARN"),
|
||||
_ => (theme.text_dim(), "INFO"),
|
||||
};
|
||||
|
||||
let title = Line::from(vec![Span::styled(
|
||||
format!(" {} ", label),
|
||||
Style::default()
|
||||
.fg(THEME.popup_error.badge_text_fg)
|
||||
.fg(theme.text_bright())
|
||||
.bg(border_color)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)]);
|
||||
|
||||
let message = self.event.message.clone();
|
||||
let text_color = theme.text();
|
||||
let bg_color = theme.surface();
|
||||
let popup = PopupFrame {
|
||||
title,
|
||||
border_color,
|
||||
bg: Some(THEME.popup_error.bg),
|
||||
bg: Some(bg_color),
|
||||
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.popup_error.text_fg))
|
||||
.style(Style::default().fg(text_color))
|
||||
.render(inner, buf);
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
mod render;
|
||||
mod state;
|
||||
|
||||
pub use render::{popup_rect, render};
|
||||
pub use state::{handle_key, take_result, ImportResult, ImportStep, ImportWizardState};
|
||||
@@ -0,0 +1,254 @@
|
||||
use super::super::base::PopupFrame;
|
||||
use super::super::new_instance::LoadState;
|
||||
use super::state::{ImportStep, ImportWizardState, IMPORT_STATE};
|
||||
use crate::tui::app::FocusedArea;
|
||||
use crate::config::theme::THEME;
|
||||
use ratatui::{
|
||||
layout::{Constraint, Direction, Layout, Rect},
|
||||
style::{Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{List, ListItem, ListState, Paragraph, StatefulWidget, Widget, Wrap},
|
||||
Frame,
|
||||
};
|
||||
|
||||
pub fn render(frame: &mut Frame, area: Rect, _focused: FocusedArea) {
|
||||
let snapshot = match IMPORT_STATE.lock() {
|
||||
Ok(state) => state.clone(),
|
||||
Err(e) => {
|
||||
tracing::error!("Import state lock poisoned: {}", e);
|
||||
ImportWizardState::default()
|
||||
}
|
||||
};
|
||||
|
||||
let keybinds = step_keybinds(&snapshot);
|
||||
|
||||
let search_line = if snapshot.step == ImportStep::Version {
|
||||
snapshot.version_search.title_line()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let theme = THEME.as_ref();
|
||||
let popup = PopupFrame {
|
||||
title: wizard_title(&snapshot),
|
||||
border_color: theme.text_dim(),
|
||||
bg: Some(theme.surface()),
|
||||
keybinds: Some(keybinds),
|
||||
search_line,
|
||||
content: Box::new(move |popup_area, buf| {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([Constraint::Min(1)])
|
||||
.split(popup_area);
|
||||
|
||||
match snapshot.step {
|
||||
ImportStep::Input => render_input_step(&snapshot, chunks[0], buf),
|
||||
ImportStep::Fetching => render_fetching_step(chunks[0], buf),
|
||||
ImportStep::Version => render_version_step(&snapshot, chunks[0], buf),
|
||||
ImportStep::Confirm => render_confirm_step(&snapshot, chunks[0], buf),
|
||||
}
|
||||
}),
|
||||
};
|
||||
|
||||
frame.render_widget(popup, area);
|
||||
}
|
||||
|
||||
pub fn popup_rect(frame_area: Rect) -> Rect {
|
||||
let w = Constraint::Percentage(50);
|
||||
let step = match IMPORT_STATE.lock() {
|
||||
Ok(s) => s.step.clone(),
|
||||
Err(_) => ImportStep::Input,
|
||||
};
|
||||
|
||||
match step {
|
||||
ImportStep::Input => {
|
||||
let h = 8u16.min(frame_area.height.saturating_sub(4));
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
ImportStep::Fetching => {
|
||||
let h = 5u16.min(frame_area.height.saturating_sub(4));
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
ImportStep::Version => {
|
||||
let h = (frame_area.height * 2 / 3)
|
||||
.max(10)
|
||||
.min(frame_area.height.saturating_sub(4));
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
ImportStep::Confirm => {
|
||||
let h = 10u16.min(frame_area.height.saturating_sub(4));
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn render_input_step(
|
||||
state: &ImportWizardState,
|
||||
area: Rect,
|
||||
buf: &mut ratatui::buffer::Buffer,
|
||||
) {
|
||||
let theme = THEME.as_ref();
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(1),
|
||||
Constraint::Min(0),
|
||||
])
|
||||
.split(area);
|
||||
|
||||
let input_line = if state.input.is_empty() {
|
||||
Line::from(vec![
|
||||
Span::styled(
|
||||
"URL, slug, or .mrpack path...",
|
||||
Style::default().fg(theme.text_dim()),
|
||||
),
|
||||
Span::styled(
|
||||
"\u{2588}",
|
||||
Style::default()
|
||||
.fg(theme.text_dim())
|
||||
.add_modifier(Modifier::SLOW_BLINK),
|
||||
),
|
||||
])
|
||||
} else {
|
||||
Line::from(vec![
|
||||
Span::styled(
|
||||
state.input.clone(),
|
||||
Style::default().fg(theme.text()),
|
||||
),
|
||||
Span::styled(
|
||||
"\u{2588}",
|
||||
Style::default()
|
||||
.fg(theme.text_dim())
|
||||
.add_modifier(Modifier::SLOW_BLINK),
|
||||
),
|
||||
])
|
||||
};
|
||||
Paragraph::new(input_line).render(chunks[0], buf);
|
||||
}
|
||||
|
||||
fn render_fetching_step(area: Rect, buf: &mut ratatui::buffer::Buffer) {
|
||||
let theme = THEME.as_ref();
|
||||
Paragraph::new("Fetching modpack info...")
|
||||
.style(Style::default().fg(theme.text_dim()))
|
||||
.render(area, buf);
|
||||
}
|
||||
|
||||
fn render_version_step(
|
||||
state: &ImportWizardState,
|
||||
area: Rect,
|
||||
buf: &mut ratatui::buffer::Buffer,
|
||||
) {
|
||||
let theme = THEME.as_ref();
|
||||
match &state.versions {
|
||||
LoadState::Idle | LoadState::Loading => {
|
||||
Paragraph::new("Loading versions...")
|
||||
.style(Style::default().fg(theme.text_dim()))
|
||||
.render(area, buf);
|
||||
}
|
||||
LoadState::Error(message) => {
|
||||
Paragraph::new(message.as_str())
|
||||
.wrap(Wrap { trim: true })
|
||||
.style(Style::default().fg(theme.error()))
|
||||
.render(area, buf);
|
||||
}
|
||||
LoadState::Loaded(_) => {
|
||||
let items: Vec<ListItem> = super::state::visible_versions(state)
|
||||
.into_iter()
|
||||
.map(|version| {
|
||||
let game_ver = version.game_versions.first().cloned().unwrap_or_default();
|
||||
let loader = version.loaders.first().cloned().unwrap_or_default();
|
||||
ListItem::new(Line::from(Span::styled(
|
||||
format!("{} {} {}", version.version_number, game_ver, loader),
|
||||
Style::default().fg(theme.text()),
|
||||
)))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let list = List::new(items)
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.fg(theme.accent())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.highlight_symbol("\u{25b6} ");
|
||||
|
||||
let mut list_state = ListState::default().with_selected(Some(state.version_idx));
|
||||
StatefulWidget::render(list, area, buf, &mut list_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn render_confirm_step(
|
||||
state: &ImportWizardState,
|
||||
area: Rect,
|
||||
buf: &mut ratatui::buffer::Buffer,
|
||||
) {
|
||||
let theme = THEME.as_ref();
|
||||
let summary = match &state.summary {
|
||||
Some(s) => s,
|
||||
None => {
|
||||
Paragraph::new("No summary available")
|
||||
.style(Style::default().fg(theme.text_dim()))
|
||||
.render(area, buf);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let label_style = Style::default().fg(theme.text_dim());
|
||||
|
||||
let loader_display = if let Some(ref lv) = summary.loader_version {
|
||||
format!("{} {}", summary.loader, lv)
|
||||
} else {
|
||||
summary.loader.to_string()
|
||||
};
|
||||
|
||||
Paragraph::new(vec![
|
||||
Line::from(vec![
|
||||
Span::styled("Name: ", label_style),
|
||||
Span::raw(summary.name.clone()),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("Pack Version: ", label_style),
|
||||
Span::raw(summary.pack_version.clone()),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("MC Version: ", label_style),
|
||||
Span::raw(summary.game_version.clone()),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("Loader: ", label_style),
|
||||
Span::raw(loader_display),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("Mods: ", label_style),
|
||||
Span::raw(format!("{} files", summary.mod_count)),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("Overrides: ", label_style),
|
||||
Span::raw(format!("{} files", summary.override_count)),
|
||||
]),
|
||||
])
|
||||
.style(Style::default().fg(theme.text()))
|
||||
.wrap(Wrap { trim: true })
|
||||
.render(area, buf);
|
||||
}
|
||||
|
||||
fn wizard_title(_state: &ImportWizardState) -> Line<'static> {
|
||||
use crate::tui::widgets::styled_title;
|
||||
styled_title("Import Modpack", false)
|
||||
}
|
||||
|
||||
fn step_keybinds(state: &ImportWizardState) -> Line<'static> {
|
||||
use super::super::keybind_line;
|
||||
match state.step {
|
||||
ImportStep::Input => keybind_line(&[("Enter", " fetch")]),
|
||||
ImportStep::Fetching => keybind_line(&[("Esc", " cancel")]),
|
||||
ImportStep::Version => keybind_line(&[
|
||||
("/", " search"),
|
||||
("h", " back"),
|
||||
("Enter", " select"),
|
||||
]),
|
||||
ImportStep::Confirm => keybind_line(&[("h", " back"), ("Enter", " import")]),
|
||||
}
|
||||
}
|
||||
+35
-289
@@ -1,28 +1,18 @@
|
||||
use super::base::PopupFrame;
|
||||
use super::new_instance::LoadState;
|
||||
use super::super::new_instance::LoadState;
|
||||
use crate::instance::import::ImportSummary;
|
||||
use crate::net::modrinth::{self, ModrinthInput, VersionInfo};
|
||||
use crate::tui::layout::FocusedArea;
|
||||
use crate::tui::theme::THEME;
|
||||
use crate::tui::widgets::profiles;
|
||||
use crate::tui::widgets::instances;
|
||||
use crate::tui::widgets::search::SearchState;
|
||||
use crossterm::event::{KeyCode, KeyEvent};
|
||||
use once_cell::sync::Lazy;
|
||||
use ratatui::{
|
||||
layout::{Constraint, Direction, Layout, Rect},
|
||||
style::{Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{List, ListItem, ListState, Paragraph, StatefulWidget, Widget, Wrap},
|
||||
Frame,
|
||||
};
|
||||
use std::sync::LazyLock;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Instant;
|
||||
use tracing::Level;
|
||||
|
||||
static IMPORT_STATE: Lazy<Arc<Mutex<ImportWizardState>>> =
|
||||
Lazy::new(|| Arc::new(Mutex::new(ImportWizardState::default())));
|
||||
static IMPORT_RESULT: Lazy<Arc<Mutex<Option<ImportResult>>>> =
|
||||
Lazy::new(|| Arc::new(Mutex::new(None)));
|
||||
pub(super) static IMPORT_STATE: LazyLock<Arc<Mutex<ImportWizardState>>> =
|
||||
LazyLock::new(|| Arc::new(Mutex::new(ImportWizardState::default())));
|
||||
pub(super) static IMPORT_RESULT: LazyLock<Arc<Mutex<Option<ImportResult>>>> =
|
||||
LazyLock::new(|| Arc::new(Mutex::new(None)));
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ImportResult {
|
||||
@@ -69,91 +59,21 @@ impl ImportWizardState {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(frame: &mut Frame, area: Rect, _focused: FocusedArea) {
|
||||
let snapshot = match IMPORT_STATE.lock() {
|
||||
Ok(state) => state.clone(),
|
||||
Err(e) => {
|
||||
tracing::error!("Import state lock poisoned: {}", e);
|
||||
ImportWizardState::default()
|
||||
}
|
||||
};
|
||||
|
||||
let keybinds = step_keybinds(&snapshot);
|
||||
|
||||
let search_line = if snapshot.step == ImportStep::Version {
|
||||
snapshot.version_search.title_line()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let popup = PopupFrame {
|
||||
title: wizard_title(&snapshot),
|
||||
border_color: THEME.popup_import.border_fg,
|
||||
bg: Some(THEME.popup_import.bg),
|
||||
keybinds: Some(keybinds),
|
||||
search_line,
|
||||
content: Box::new(move |popup_area, buf| {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([Constraint::Min(1)])
|
||||
.split(popup_area);
|
||||
|
||||
match snapshot.step {
|
||||
ImportStep::Input => render_input_step(&snapshot, chunks[0], buf),
|
||||
ImportStep::Fetching => render_fetching_step(chunks[0], buf),
|
||||
ImportStep::Version => render_version_step(&snapshot, chunks[0], buf),
|
||||
ImportStep::Confirm => render_confirm_step(&snapshot, chunks[0], buf),
|
||||
}
|
||||
}),
|
||||
};
|
||||
|
||||
frame.render_widget(popup, area);
|
||||
}
|
||||
|
||||
pub fn popup_rect(frame_area: Rect) -> Rect {
|
||||
let w = Constraint::Percentage(50);
|
||||
let step = match IMPORT_STATE.lock() {
|
||||
Ok(s) => s.step.clone(),
|
||||
Err(_) => ImportStep::Input,
|
||||
};
|
||||
|
||||
match step {
|
||||
ImportStep::Input => {
|
||||
let h = 8u16.min(frame_area.height.saturating_sub(4));
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
ImportStep::Fetching => {
|
||||
let h = 5u16.min(frame_area.height.saturating_sub(4));
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
ImportStep::Version => {
|
||||
let h = (frame_area.height * 2 / 3)
|
||||
.max(10)
|
||||
.min(frame_area.height.saturating_sub(4));
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
ImportStep::Confirm => {
|
||||
let h = 10u16.min(frame_area.height.saturating_sub(4));
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_key(key_event: &KeyEvent, profiles_state: &mut profiles::State) {
|
||||
pub fn handle_key(key_event: &KeyEvent, instances_state: &mut instances::State) {
|
||||
let mut state = match IMPORT_STATE.lock() {
|
||||
Ok(state) => state,
|
||||
Err(e) => {
|
||||
tracing::error!("Import state lock poisoned: {}", e);
|
||||
profiles_state.show_import_popup = false;
|
||||
instances_state.show_import_popup = false;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
match state.step {
|
||||
ImportStep::Input => handle_input_key(&mut state, key_event, profiles_state),
|
||||
ImportStep::Fetching => handle_fetching_key(&mut state, key_event, profiles_state),
|
||||
ImportStep::Version => handle_version_key(&mut state, key_event, profiles_state),
|
||||
ImportStep::Confirm => handle_confirm_key(&mut state, key_event, profiles_state),
|
||||
ImportStep::Input => handle_input_key(&mut state, key_event, instances_state),
|
||||
ImportStep::Fetching => handle_fetching_key(&mut state, key_event, instances_state),
|
||||
ImportStep::Version => handle_version_key(&mut state, key_event, instances_state),
|
||||
ImportStep::Confirm => handle_confirm_key(&mut state, key_event, instances_state),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,10 +87,10 @@ pub fn take_result() -> Option<ImportResult> {
|
||||
fn handle_input_key(
|
||||
state: &mut ImportWizardState,
|
||||
key_event: &KeyEvent,
|
||||
profiles_state: &mut profiles::State,
|
||||
instances_state: &mut instances::State,
|
||||
) {
|
||||
match key_event.code {
|
||||
KeyCode::Esc => close_popup(state, profiles_state),
|
||||
KeyCode::Esc => close_popup(state, instances_state),
|
||||
KeyCode::Backspace => {
|
||||
state.input.pop();
|
||||
}
|
||||
@@ -190,17 +110,17 @@ fn handle_input_key(
|
||||
fn handle_fetching_key(
|
||||
state: &mut ImportWizardState,
|
||||
key_event: &KeyEvent,
|
||||
profiles_state: &mut profiles::State,
|
||||
instances_state: &mut instances::State,
|
||||
) {
|
||||
if key_event.code == KeyCode::Esc {
|
||||
close_popup(state, profiles_state);
|
||||
close_popup(state, instances_state);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_version_key(
|
||||
state: &mut ImportWizardState,
|
||||
key_event: &KeyEvent,
|
||||
profiles_state: &mut profiles::State,
|
||||
instances_state: &mut instances::State,
|
||||
) {
|
||||
if state.version_search.active {
|
||||
match key_event.code {
|
||||
@@ -232,7 +152,7 @@ fn handle_version_key(
|
||||
let visible_count = visible_versions(state).len();
|
||||
|
||||
match key_event.code {
|
||||
KeyCode::Esc => close_popup(state, profiles_state),
|
||||
KeyCode::Esc => close_popup(state, instances_state),
|
||||
KeyCode::Left | KeyCode::Char('h') if !state.version_search.active => {
|
||||
state.step = ImportStep::Input;
|
||||
state.versions = LoadState::Idle;
|
||||
@@ -265,10 +185,10 @@ fn handle_version_key(
|
||||
fn handle_confirm_key(
|
||||
state: &mut ImportWizardState,
|
||||
key_event: &KeyEvent,
|
||||
profiles_state: &mut profiles::State,
|
||||
instances_state: &mut instances::State,
|
||||
) {
|
||||
match key_event.code {
|
||||
KeyCode::Esc => close_popup(state, profiles_state),
|
||||
KeyCode::Esc => close_popup(state, instances_state),
|
||||
KeyCode::Left | KeyCode::Char('h') => {
|
||||
if matches!(state.versions, LoadState::Loaded(_)) {
|
||||
state.step = ImportStep::Version;
|
||||
@@ -291,7 +211,7 @@ fn handle_confirm_key(
|
||||
}
|
||||
}
|
||||
|
||||
close_popup(state, profiles_state);
|
||||
close_popup(state, instances_state);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -418,14 +338,7 @@ async fn resolve_version_id(
|
||||
}
|
||||
|
||||
fn resolve_local_file(state_arc: Arc<Mutex<ImportWizardState>>, path: &str) {
|
||||
let resolved = if let Some(stripped) = path.strip_prefix("~/") {
|
||||
match dirs_next::home_dir() {
|
||||
Some(home) => home.join(stripped),
|
||||
None => std::path::PathBuf::from(path),
|
||||
}
|
||||
} else {
|
||||
std::path::PathBuf::from(path)
|
||||
};
|
||||
let resolved = crate::config::settings::resolve_path(path);
|
||||
|
||||
match modrinth::parse_mrpack(&resolved) {
|
||||
Ok(index) => {
|
||||
@@ -506,157 +419,9 @@ fn start_version_download(state: &mut ImportWizardState) {
|
||||
});
|
||||
}
|
||||
|
||||
fn render_input_step(
|
||||
state: &ImportWizardState,
|
||||
area: Rect,
|
||||
buf: &mut ratatui::buffer::Buffer,
|
||||
) {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(1),
|
||||
Constraint::Min(0),
|
||||
])
|
||||
.split(area);
|
||||
|
||||
let input_line = if state.input.is_empty() {
|
||||
Line::from(vec![
|
||||
Span::styled(
|
||||
"URL, slug, or .mrpack path...",
|
||||
Style::default().fg(THEME.popup_import.field_inactive_border_fg),
|
||||
),
|
||||
Span::styled(
|
||||
"\u{2588}",
|
||||
Style::default()
|
||||
.fg(THEME.popup_import.border_fg)
|
||||
.add_modifier(Modifier::SLOW_BLINK),
|
||||
),
|
||||
])
|
||||
} else {
|
||||
Line::from(vec![
|
||||
Span::styled(
|
||||
state.input.clone(),
|
||||
Style::default().fg(THEME.popup_import.text_fg),
|
||||
),
|
||||
Span::styled(
|
||||
"\u{2588}",
|
||||
Style::default()
|
||||
.fg(THEME.popup_import.border_fg)
|
||||
.add_modifier(Modifier::SLOW_BLINK),
|
||||
),
|
||||
])
|
||||
};
|
||||
Paragraph::new(input_line).render(chunks[0], buf);
|
||||
}
|
||||
|
||||
fn render_fetching_step(area: Rect, buf: &mut ratatui::buffer::Buffer) {
|
||||
Paragraph::new("Fetching modpack info...")
|
||||
.style(Style::default().fg(THEME.popup_import.field_inactive_border_fg))
|
||||
.render(area, buf);
|
||||
}
|
||||
|
||||
fn render_version_step(
|
||||
state: &ImportWizardState,
|
||||
area: Rect,
|
||||
buf: &mut ratatui::buffer::Buffer,
|
||||
) {
|
||||
match &state.versions {
|
||||
LoadState::Idle | LoadState::Loading => {
|
||||
Paragraph::new("Loading versions...")
|
||||
.style(Style::default().fg(THEME.popup_import.field_inactive_border_fg))
|
||||
.render(area, buf);
|
||||
}
|
||||
LoadState::Error(message) => {
|
||||
Paragraph::new(message.as_str())
|
||||
.wrap(Wrap { trim: true })
|
||||
.style(Style::default().fg(THEME.general.error))
|
||||
.render(area, buf);
|
||||
}
|
||||
LoadState::Loaded(_) => {
|
||||
let items: Vec<ListItem> = visible_versions(state)
|
||||
.into_iter()
|
||||
.map(|version| {
|
||||
let game_ver = version.game_versions.first().cloned().unwrap_or_default();
|
||||
let loader = version.loaders.first().cloned().unwrap_or_default();
|
||||
ListItem::new(Line::from(Span::styled(
|
||||
format!("{} {} {}", version.version_number, game_ver, loader),
|
||||
Style::default().fg(THEME.popup_import.text_fg),
|
||||
)))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let list = List::new(items)
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.fg(THEME.popup_import.accent_fg)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.highlight_symbol("\u{25b6} ");
|
||||
|
||||
let mut list_state = ListState::default().with_selected(Some(state.version_idx));
|
||||
StatefulWidget::render(list, area, buf, &mut list_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn render_confirm_step(
|
||||
state: &ImportWizardState,
|
||||
area: Rect,
|
||||
buf: &mut ratatui::buffer::Buffer,
|
||||
) {
|
||||
let summary = match &state.summary {
|
||||
Some(s) => s,
|
||||
None => {
|
||||
Paragraph::new("No summary available")
|
||||
.style(Style::default().fg(THEME.popup_import.field_inactive_border_fg))
|
||||
.render(area, buf);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let label_style = Style::default().fg(THEME.popup_import.border_fg);
|
||||
|
||||
let loader_display = if let Some(ref lv) = summary.loader_version {
|
||||
format!("{} {}", summary.loader, lv)
|
||||
} else {
|
||||
summary.loader.to_string()
|
||||
};
|
||||
|
||||
Paragraph::new(vec![
|
||||
Line::from(vec![
|
||||
Span::styled("Name: ", label_style),
|
||||
Span::raw(summary.name.clone()),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("Pack Version: ", label_style),
|
||||
Span::raw(summary.pack_version.clone()),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("MC Version: ", label_style),
|
||||
Span::raw(summary.game_version.clone()),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("Loader: ", label_style),
|
||||
Span::raw(loader_display),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("Mods: ", label_style),
|
||||
Span::raw(format!("{} files", summary.mod_count)),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("Overrides: ", label_style),
|
||||
Span::raw(format!("{} files", summary.override_count)),
|
||||
]),
|
||||
])
|
||||
.style(Style::default().fg(THEME.popup_import.text_fg))
|
||||
.wrap(Wrap { trim: true })
|
||||
.render(area, buf);
|
||||
}
|
||||
|
||||
fn close_popup(state: &mut ImportWizardState, profiles_state: &mut profiles::State) {
|
||||
fn close_popup(state: &mut ImportWizardState, instances_state: &mut instances::State) {
|
||||
state.reset();
|
||||
profiles_state.show_import_popup = false;
|
||||
instances_state.show_import_popup = false;
|
||||
}
|
||||
|
||||
fn push_import_error(msg: String) {
|
||||
@@ -668,35 +433,7 @@ fn push_import_error(msg: String) {
|
||||
});
|
||||
}
|
||||
|
||||
fn wizard_title(_state: &ImportWizardState) -> Line<'static> {
|
||||
use crate::tui::widgets::styled_title;
|
||||
styled_title("Import Modpack", false)
|
||||
}
|
||||
|
||||
fn step_keybinds(state: &ImportWizardState) -> Line<'static> {
|
||||
use super::keybind_line;
|
||||
match state.step {
|
||||
ImportStep::Input => keybind_line(&[("Enter", " fetch")]),
|
||||
ImportStep::Fetching => keybind_line(&[("Esc", " cancel")]),
|
||||
ImportStep::Version => keybind_line(&[
|
||||
("/", " search"),
|
||||
("h", " back"),
|
||||
("Enter", " select"),
|
||||
]),
|
||||
ImportStep::Confirm => keybind_line(&[("h", " back"), ("Enter", " import")]),
|
||||
}
|
||||
}
|
||||
|
||||
fn selected_version(state: &ImportWizardState) -> Option<&VersionInfo> {
|
||||
if let LoadState::Loaded(ref versions) = state.versions {
|
||||
let visible: Vec<_> = visible_versions_ref(versions, &state.version_search);
|
||||
visible.get(state.version_idx).copied()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn visible_versions(state: &ImportWizardState) -> Vec<VersionInfo> {
|
||||
pub(super) fn visible_versions(state: &ImportWizardState) -> Vec<VersionInfo> {
|
||||
match &state.versions {
|
||||
LoadState::Loaded(versions) => {
|
||||
let q = state.version_search.query.to_lowercase();
|
||||
@@ -729,6 +466,15 @@ fn visible_versions_ref<'a>(
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn selected_version(state: &ImportWizardState) -> Option<&VersionInfo> {
|
||||
if let LoadState::Loaded(ref versions) = state.versions {
|
||||
let visible: Vec<_> = visible_versions_ref(versions, &state.version_search);
|
||||
visible.get(state.version_idx).copied()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn clamp_version_index(state: &mut ImportWizardState) {
|
||||
let count = visible_versions(state).len();
|
||||
if count == 0 {
|
||||
@@ -56,26 +56,23 @@ pub fn top_right_rect(frame: Rect, inner_w: usize, inner_h: usize) -> Rect {
|
||||
}
|
||||
|
||||
pub fn keybind_line(binds: &[(&str, &str)]) -> ratatui::text::Line<'static> {
|
||||
use crate::tui::theme::THEME;
|
||||
use crate::config::theme::THEME;
|
||||
use ratatui::{
|
||||
style::{Modifier, Style},
|
||||
text::{Line, Span},
|
||||
};
|
||||
|
||||
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 theme = THEME.as_ref();
|
||||
let key_style = Style::default().fg(theme.accent()).add_modifier(Modifier::BOLD);
|
||||
let label_style = Style::default().fg(theme.text());
|
||||
|
||||
let mut spans: Vec<Span<'static>> = Vec::new();
|
||||
for (i, (key, label)) in binds.iter().enumerate() {
|
||||
if i > 0 {
|
||||
spans.push(Span::styled(" ", dim_style));
|
||||
spans.push(Span::styled(" ", label_style));
|
||||
}
|
||||
spans.push(Span::styled(format!("[{}]", key), key_style));
|
||||
if !label.is_empty() {
|
||||
spans.push(Span::styled(label.to_string(), dim_style));
|
||||
spans.push(Span::styled(label.to_string(), label_style));
|
||||
}
|
||||
}
|
||||
Line::from(spans)
|
||||
@@ -85,17 +82,14 @@ pub fn keybind_lines_wrapped(
|
||||
binds: &[(&str, &str)],
|
||||
max_width: u16,
|
||||
) -> Vec<ratatui::text::Line<'static>> {
|
||||
use crate::tui::theme::THEME;
|
||||
use crate::config::theme::THEME;
|
||||
use ratatui::{
|
||||
style::{Modifier, Style},
|
||||
text::{Line, Span},
|
||||
};
|
||||
|
||||
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 theme = THEME.as_ref();
|
||||
let key_style = Style::default().fg(theme.accent()).add_modifier(Modifier::BOLD);
|
||||
let label_style = Style::default().fg(theme.text());
|
||||
|
||||
let mut rows: Vec<Line<'static>> = Vec::new();
|
||||
let mut current_spans: Vec<Span<'static>> = Vec::new();
|
||||
@@ -117,13 +111,13 @@ pub fn keybind_lines_wrapped(
|
||||
}
|
||||
|
||||
if !current_spans.is_empty() {
|
||||
current_spans.push(Span::styled(" ", dim_style));
|
||||
current_spans.push(Span::styled(" ", label_style));
|
||||
current_width += 2;
|
||||
}
|
||||
|
||||
current_spans.push(Span::styled(format!("[{}]", key), key_style));
|
||||
if !label.is_empty() {
|
||||
current_spans.push(Span::styled(label.to_string(), dim_style));
|
||||
current_spans.push(Span::styled(label.to_string(), label_style));
|
||||
}
|
||||
current_width += item_w;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
mod render;
|
||||
mod state;
|
||||
|
||||
pub use render::{popup_rect, render};
|
||||
pub use state::{handle_key, take_result, LoadState, WizardParams, WizardStep, WizardState};
|
||||
@@ -0,0 +1,321 @@
|
||||
use super::state::{
|
||||
clamp_loader_version_index, clamp_version_index, ensure_loader_versions_loaded,
|
||||
ensure_versions_loaded, visible_versions, LoadState, WizardState, WizardStep, WIZARD_STATE,
|
||||
};
|
||||
use crate::instance::models::ModLoader;
|
||||
use crate::tui::app::FocusedArea;
|
||||
use crate::config::theme::THEME;
|
||||
use crate::tui::widgets::popups::base::PopupFrame;
|
||||
use tui_prompts::State as PromptState;
|
||||
use ratatui::{
|
||||
layout::{Constraint, Direction, Layout, Rect},
|
||||
style::{Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{List, ListItem, ListState, Paragraph, StatefulWidget, Widget, Wrap},
|
||||
Frame,
|
||||
};
|
||||
|
||||
pub fn render(frame: &mut Frame, area: Rect, _focused: FocusedArea) {
|
||||
let snapshot = match WIZARD_STATE.lock() {
|
||||
Ok(mut state) => {
|
||||
if state.step == WizardStep::Version {
|
||||
ensure_versions_loaded(&mut state);
|
||||
clamp_version_index(&mut state);
|
||||
}
|
||||
|
||||
if state.step == WizardStep::LoaderVersion {
|
||||
if state.selected_loader() == ModLoader::Vanilla {
|
||||
state.step = WizardStep::Confirm;
|
||||
} else {
|
||||
clamp_loader_version_index(&mut state);
|
||||
let game_version = state.selected_version().map(|v| v.id.clone());
|
||||
let loader = state.selected_loader();
|
||||
if let Some(game_version) = game_version {
|
||||
ensure_loader_versions_loaded(&mut state, loader, game_version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
state.clone()
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Wizard state lock poisoned: {}", e);
|
||||
WizardState::default()
|
||||
}
|
||||
};
|
||||
|
||||
let keybinds = step_keybinds(&snapshot);
|
||||
|
||||
let search_line = snapshot.version_search.title_line();
|
||||
|
||||
let theme = THEME.as_ref();
|
||||
let popup = PopupFrame {
|
||||
title: wizard_title(&snapshot),
|
||||
border_color: theme.text_dim(),
|
||||
bg: Some(theme.surface()),
|
||||
keybinds: Some(keybinds),
|
||||
search_line,
|
||||
content: Box::new(move |popup_area, buf| {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([Constraint::Min(1)])
|
||||
.split(popup_area);
|
||||
|
||||
match snapshot.step {
|
||||
WizardStep::Name => render_name_step(&snapshot, chunks[0], buf),
|
||||
WizardStep::Version => render_version_step(&snapshot, chunks[0], buf),
|
||||
WizardStep::Loader => render_loader_step(&snapshot, chunks[0], buf),
|
||||
WizardStep::LoaderVersion => render_loader_version_step(&snapshot, chunks[0], buf),
|
||||
WizardStep::Confirm => render_confirm_step(&snapshot, chunks[0], buf),
|
||||
}
|
||||
}),
|
||||
};
|
||||
|
||||
frame.render_widget(popup, area);
|
||||
}
|
||||
|
||||
pub fn popup_rect(frame_area: Rect) -> Rect {
|
||||
use ratatui::layout::Constraint;
|
||||
|
||||
let step = match WIZARD_STATE.lock() {
|
||||
Ok(s) => s.step.clone(),
|
||||
Err(_) => WizardStep::Name,
|
||||
};
|
||||
|
||||
let w = Constraint::Percentage(50);
|
||||
|
||||
match step {
|
||||
WizardStep::Name => {
|
||||
let h = 6u16.min(frame_area.height.saturating_sub(4));
|
||||
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));
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
WizardStep::Loader => {
|
||||
let h = 9u16.min(frame_area.height.saturating_sub(4));
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
WizardStep::Confirm => {
|
||||
let h = 8u16.min(frame_area.height.saturating_sub(4));
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn wizard_title(_state: &WizardState) -> Line<'static> {
|
||||
use crate::tui::widgets::styled_title;
|
||||
styled_title("New Instance", false)
|
||||
}
|
||||
|
||||
fn step_keybinds(state: &WizardState) -> ratatui::text::Line<'static> {
|
||||
use crate::tui::widgets::popups::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::LoaderVersion => keybind_line(&[("h", " back"), ("Enter", " select")]),
|
||||
WizardStep::Confirm => keybind_line(&[("h", " back"), ("Enter", " create")]),
|
||||
}
|
||||
}
|
||||
|
||||
fn render_name_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
|
||||
let theme = THEME.as_ref();
|
||||
let value = state.name_state.value();
|
||||
let line = if value.is_empty() {
|
||||
Line::from(vec![
|
||||
Span::styled(
|
||||
"Instance name...",
|
||||
Style::default().fg(theme.text_dim()),
|
||||
),
|
||||
Span::styled(
|
||||
"\u{2588}",
|
||||
Style::default()
|
||||
.fg(theme.text_dim())
|
||||
.add_modifier(Modifier::SLOW_BLINK),
|
||||
),
|
||||
])
|
||||
} else {
|
||||
Line::from(vec![
|
||||
Span::styled(value, Style::default().fg(theme.text())),
|
||||
Span::styled(
|
||||
"\u{2588}",
|
||||
Style::default()
|
||||
.fg(theme.text_dim())
|
||||
.add_modifier(Modifier::SLOW_BLINK),
|
||||
),
|
||||
])
|
||||
};
|
||||
|
||||
Paragraph::new(line).render(area, buf);
|
||||
}
|
||||
|
||||
fn render_version_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
|
||||
let theme = THEME.as_ref();
|
||||
match &state.versions {
|
||||
LoadState::Idle | LoadState::Loading => {
|
||||
Paragraph::new("Loading versions...")
|
||||
.style(Style::default().fg(theme.text_dim()))
|
||||
.render(area, buf);
|
||||
}
|
||||
LoadState::Error(message) => {
|
||||
Paragraph::new(message.as_str())
|
||||
.wrap(Wrap { trim: true })
|
||||
.style(Style::default().fg(theme.error()))
|
||||
.render(area, buf);
|
||||
}
|
||||
LoadState::Loaded(_) => {
|
||||
let items: Vec<ListItem> = visible_versions(state)
|
||||
.into_iter()
|
||||
.map(|version| {
|
||||
let suffix = if version.stable {
|
||||
String::new()
|
||||
} else {
|
||||
" (snapshot)".to_string()
|
||||
};
|
||||
ListItem::new(Line::from(Span::styled(
|
||||
format!("{}{}", version.id, suffix),
|
||||
Style::default().fg(theme.text()),
|
||||
)))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let list = List::new(items)
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.fg(theme.accent())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.highlight_symbol("▶ ");
|
||||
|
||||
let mut list_state = ListState::default().with_selected(Some(state.version_idx));
|
||||
StatefulWidget::render(list, area, buf, &mut list_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn render_loader_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
|
||||
let theme = THEME.as_ref();
|
||||
let loaders = [
|
||||
ModLoader::Vanilla,
|
||||
ModLoader::Fabric,
|
||||
ModLoader::Forge,
|
||||
ModLoader::NeoForge,
|
||||
ModLoader::Quilt,
|
||||
];
|
||||
|
||||
let items: Vec<ListItem> = loaders
|
||||
.into_iter()
|
||||
.map(|loader| {
|
||||
ListItem::new(Line::from(Span::styled(
|
||||
loader.to_string(),
|
||||
Style::default().fg(theme.text()),
|
||||
)))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let list = List::new(items)
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.fg(theme.accent())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.highlight_symbol("▶ ");
|
||||
|
||||
let mut list_state = ListState::default().with_selected(Some(state.loader_idx));
|
||||
StatefulWidget::render(list, area, buf, &mut list_state);
|
||||
}
|
||||
|
||||
fn render_loader_version_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
|
||||
let theme = THEME.as_ref();
|
||||
if state.selected_loader() == ModLoader::Vanilla {
|
||||
Paragraph::new("Vanilla has no loader version.")
|
||||
.style(Style::default().fg(theme.text_dim()))
|
||||
.render(area, buf);
|
||||
return;
|
||||
}
|
||||
|
||||
match &state.loader_versions {
|
||||
LoadState::Idle | LoadState::Loading => {
|
||||
Paragraph::new(format!("Loading {} versions...", state.selected_loader()))
|
||||
.style(Style::default().fg(theme.text_dim()))
|
||||
.render(area, buf);
|
||||
}
|
||||
LoadState::Error(message) => {
|
||||
Paragraph::new(message.as_str())
|
||||
.wrap(Wrap { trim: true })
|
||||
.style(Style::default().fg(theme.error()))
|
||||
.render(area, buf);
|
||||
}
|
||||
LoadState::Loaded(versions) => {
|
||||
let items: Vec<ListItem> = versions
|
||||
.iter()
|
||||
.map(|version| {
|
||||
ListItem::new(Line::from(Span::styled(
|
||||
version.clone(),
|
||||
Style::default().fg(theme.text()),
|
||||
)))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let list = List::new(items)
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.fg(theme.accent())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.highlight_symbol("▶ ");
|
||||
|
||||
let mut list_state = ListState::default().with_selected(Some(state.loader_version_idx));
|
||||
StatefulWidget::render(list, area, buf, &mut list_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn render_confirm_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
|
||||
let theme = THEME.as_ref();
|
||||
let game_version = state
|
||||
.selected_version()
|
||||
.map(|version| version.id.as_str())
|
||||
.unwrap_or("<not selected>");
|
||||
let loader = state.selected_loader();
|
||||
let loader_version = if loader == ModLoader::Vanilla {
|
||||
"n/a".to_string()
|
||||
} else {
|
||||
state
|
||||
.selected_loader_version()
|
||||
.unwrap_or_else(|| "<not selected>".to_string())
|
||||
};
|
||||
|
||||
let label_style = Style::default().fg(theme.text_dim());
|
||||
|
||||
Paragraph::new(vec![
|
||||
Line::from(vec![
|
||||
Span::styled("Name: ", label_style),
|
||||
Span::raw(state.name_state.value()),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("MC: ", label_style),
|
||||
Span::raw(game_version),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("Loader: ", label_style),
|
||||
Span::raw(loader.to_string()),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("Loader version: ", label_style),
|
||||
Span::raw(loader_version),
|
||||
]),
|
||||
])
|
||||
.style(Style::default().fg(theme.text()))
|
||||
.wrap(Wrap { trim: true })
|
||||
.render(area, buf);
|
||||
}
|
||||
+31
-344
@@ -1,27 +1,17 @@
|
||||
use super::base::PopupFrame;
|
||||
use crate::instance::{
|
||||
loader::{get_installer, GameVersion},
|
||||
models::ModLoader,
|
||||
};
|
||||
use crate::tui::layout::FocusedArea;
|
||||
use crate::tui::theme::THEME;
|
||||
use crate::tui::widgets::profiles;
|
||||
use crate::tui::widgets::instances;
|
||||
use crossterm::event::{KeyCode, KeyEvent};
|
||||
use once_cell::sync::Lazy;
|
||||
use ratatui::{
|
||||
layout::{Constraint, Direction, Layout, Rect},
|
||||
style::{Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{List, ListItem, ListState, Paragraph, StatefulWidget, Widget, Wrap},
|
||||
Frame,
|
||||
};
|
||||
use std::sync::LazyLock;
|
||||
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)));
|
||||
pub(crate) static WIZARD_STATE: LazyLock<Arc<Mutex<WizardState>>> =
|
||||
LazyLock::new(|| Arc::new(Mutex::new(WizardState::default())));
|
||||
pub(crate) static WIZARD_RESULT: LazyLock<Arc<Mutex<Option<WizardParams>>>> =
|
||||
LazyLock::new(|| Arc::new(Mutex::new(None)));
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct WizardParams {
|
||||
@@ -51,7 +41,6 @@ pub enum LoadState<T> {
|
||||
Error(String),
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct WizardState {
|
||||
pub step: WizardStep,
|
||||
@@ -118,82 +107,24 @@ impl WizardState {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(frame: &mut Frame, area: Rect, _focused: FocusedArea) {
|
||||
let snapshot = match WIZARD_STATE.lock() {
|
||||
Ok(mut state) => {
|
||||
if state.step == WizardStep::Version {
|
||||
ensure_versions_loaded(&mut state);
|
||||
clamp_version_index(&mut state);
|
||||
}
|
||||
|
||||
if state.step == WizardStep::LoaderVersion {
|
||||
if state.selected_loader() == ModLoader::Vanilla {
|
||||
state.step = WizardStep::Confirm;
|
||||
} else {
|
||||
clamp_loader_version_index(&mut state);
|
||||
let game_version = state.selected_version().map(|v| v.id.clone());
|
||||
let loader = state.selected_loader();
|
||||
if let Some(game_version) = game_version {
|
||||
ensure_loader_versions_loaded(&mut state, loader, game_version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
state.clone()
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Wizard state lock poisoned: {}", e);
|
||||
WizardState::default()
|
||||
}
|
||||
};
|
||||
|
||||
let keybinds = step_keybinds(&snapshot);
|
||||
|
||||
let search_line = snapshot.version_search.title_line();
|
||||
|
||||
let popup = PopupFrame {
|
||||
title: wizard_title(&snapshot),
|
||||
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| {
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([Constraint::Min(1)])
|
||||
.split(popup_area);
|
||||
|
||||
match snapshot.step {
|
||||
WizardStep::Name => render_name_step(&snapshot, chunks[0], buf),
|
||||
WizardStep::Version => render_version_step(&snapshot, chunks[0], buf),
|
||||
WizardStep::Loader => render_loader_step(&snapshot, chunks[0], buf),
|
||||
WizardStep::LoaderVersion => render_loader_version_step(&snapshot, chunks[0], buf),
|
||||
WizardStep::Confirm => render_confirm_step(&snapshot, chunks[0], buf),
|
||||
}
|
||||
}),
|
||||
};
|
||||
|
||||
frame.render_widget(popup, area);
|
||||
}
|
||||
|
||||
pub fn handle_key(key_event: &KeyEvent, profiles_state: &mut profiles::State) {
|
||||
pub fn handle_key(key_event: &KeyEvent, instances_state: &mut instances::State) {
|
||||
let mut state = match WIZARD_STATE.lock() {
|
||||
Ok(state) => state,
|
||||
Err(e) => {
|
||||
tracing::error!("Wizard state lock poisoned: {}", e);
|
||||
profiles_state.show_popup = false;
|
||||
instances_state.show_popup = false;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
match state.step {
|
||||
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::Name => handle_name_key(&mut state, key_event, instances_state),
|
||||
WizardStep::Version => handle_version_key(&mut state, key_event, instances_state),
|
||||
WizardStep::Loader => handle_loader_key(&mut state, key_event, instances_state),
|
||||
WizardStep::LoaderVersion => {
|
||||
handle_loader_version_key(&mut state, key_event, profiles_state)
|
||||
handle_loader_version_key(&mut state, key_event, instances_state)
|
||||
}
|
||||
WizardStep::Confirm => handle_confirm_key(&mut state, key_event, profiles_state),
|
||||
WizardStep::Confirm => handle_confirm_key(&mut state, key_event, instances_state),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,46 +135,14 @@ pub fn take_result() -> Option<WizardParams> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn popup_rect(frame_area: Rect) -> Rect {
|
||||
use ratatui::layout::Constraint;
|
||||
|
||||
let step = match WIZARD_STATE.lock() {
|
||||
Ok(s) => s.step.clone(),
|
||||
Err(_) => WizardStep::Name,
|
||||
};
|
||||
|
||||
let w = Constraint::Percentage(50);
|
||||
|
||||
match step {
|
||||
WizardStep::Name => {
|
||||
let h = 6u16.min(frame_area.height.saturating_sub(4));
|
||||
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));
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
WizardStep::Loader => {
|
||||
let h = 9u16.min(frame_area.height.saturating_sub(4));
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
WizardStep::Confirm => {
|
||||
let h = 8u16.min(frame_area.height.saturating_sub(4));
|
||||
frame_area.centered(w, Constraint::Length(h))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_name_key(
|
||||
state: &mut WizardState,
|
||||
key_event: &KeyEvent,
|
||||
profiles_state: &mut profiles::State,
|
||||
instances_state: &mut instances::State,
|
||||
) {
|
||||
match key_event.code {
|
||||
KeyCode::Esc => {
|
||||
close_popup(state, profiles_state);
|
||||
close_popup(state, instances_state);
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
if state.name_state.value().trim().is_empty() {
|
||||
@@ -260,7 +159,7 @@ fn handle_name_key(
|
||||
fn handle_version_key(
|
||||
state: &mut WizardState,
|
||||
key_event: &KeyEvent,
|
||||
profiles_state: &mut profiles::State,
|
||||
instances_state: &mut instances::State,
|
||||
) {
|
||||
// Search mode: route char input to search query
|
||||
if state.version_search.active {
|
||||
@@ -294,7 +193,7 @@ fn handle_version_key(
|
||||
|
||||
match key_event.code {
|
||||
KeyCode::Esc => {
|
||||
close_popup(state, profiles_state);
|
||||
close_popup(state, instances_state);
|
||||
}
|
||||
KeyCode::Left | KeyCode::Char('h') if !state.version_search.active => {
|
||||
state.step = WizardStep::Loader;
|
||||
@@ -342,10 +241,10 @@ fn handle_version_key(
|
||||
fn handle_loader_key(
|
||||
state: &mut WizardState,
|
||||
key_event: &KeyEvent,
|
||||
profiles_state: &mut profiles::State,
|
||||
instances_state: &mut instances::State,
|
||||
) {
|
||||
match key_event.code {
|
||||
KeyCode::Esc => close_popup(state, profiles_state),
|
||||
KeyCode::Esc => close_popup(state, instances_state),
|
||||
KeyCode::Left | KeyCode::Char('h') => state.step = WizardStep::Name,
|
||||
KeyCode::Char('j') | KeyCode::Down => {
|
||||
state.loader_idx = (state.loader_idx + 1).min(4);
|
||||
@@ -368,7 +267,7 @@ fn handle_loader_key(
|
||||
fn handle_loader_version_key(
|
||||
state: &mut WizardState,
|
||||
key_event: &KeyEvent,
|
||||
profiles_state: &mut profiles::State,
|
||||
instances_state: &mut instances::State,
|
||||
) {
|
||||
if state.selected_loader() == ModLoader::Vanilla {
|
||||
state.step = WizardStep::Confirm;
|
||||
@@ -381,7 +280,7 @@ fn handle_loader_version_key(
|
||||
};
|
||||
|
||||
match key_event.code {
|
||||
KeyCode::Esc => close_popup(state, profiles_state),
|
||||
KeyCode::Esc => close_popup(state, instances_state),
|
||||
KeyCode::Left | KeyCode::Char('h') => state.step = WizardStep::Version,
|
||||
KeyCode::Char('j') | KeyCode::Down => {
|
||||
if version_count > 0 {
|
||||
@@ -405,10 +304,10 @@ fn handle_loader_version_key(
|
||||
fn handle_confirm_key(
|
||||
state: &mut WizardState,
|
||||
key_event: &KeyEvent,
|
||||
profiles_state: &mut profiles::State,
|
||||
instances_state: &mut instances::State,
|
||||
) {
|
||||
match key_event.code {
|
||||
KeyCode::Esc => close_popup(state, profiles_state),
|
||||
KeyCode::Esc => close_popup(state, instances_state),
|
||||
KeyCode::Left | KeyCode::Char('h') => {
|
||||
if state.selected_loader() == ModLoader::Vanilla {
|
||||
state.step = WizardStep::Version;
|
||||
@@ -442,230 +341,18 @@ fn handle_confirm_key(
|
||||
}
|
||||
}
|
||||
|
||||
close_popup(state, profiles_state);
|
||||
close_popup(state, instances_state);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn close_popup(state: &mut WizardState, profiles_state: &mut profiles::State) {
|
||||
fn close_popup(state: &mut WizardState, instances_state: &mut instances::State) {
|
||||
state.reset();
|
||||
profiles_state.show_popup = false;
|
||||
instances_state.show_popup = false;
|
||||
}
|
||||
|
||||
fn wizard_title(_state: &WizardState) -> Line<'static> {
|
||||
use crate::tui::widgets::styled_title;
|
||||
styled_title("New Instance", false)
|
||||
}
|
||||
|
||||
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::LoaderVersion => keybind_line(&[("h", " back"), ("Enter", " select")]),
|
||||
WizardStep::Confirm => keybind_line(&[("h", " back"), ("Enter", " create")]),
|
||||
}
|
||||
}
|
||||
|
||||
fn render_name_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
|
||||
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.popup_new_instance.field_inactive_border_fg),
|
||||
),
|
||||
Span::styled(
|
||||
"\u{2588}",
|
||||
Style::default()
|
||||
.fg(THEME.popup_new_instance.border_fg)
|
||||
.add_modifier(Modifier::SLOW_BLINK),
|
||||
),
|
||||
])
|
||||
} else {
|
||||
Line::from(vec![
|
||||
Span::styled(value, Style::default().fg(THEME.popup_new_instance.text_fg)),
|
||||
Span::styled(
|
||||
"\u{2588}",
|
||||
Style::default()
|
||||
.fg(THEME.popup_new_instance.border_fg)
|
||||
.add_modifier(Modifier::SLOW_BLINK),
|
||||
),
|
||||
])
|
||||
};
|
||||
|
||||
Paragraph::new(line).render(area, buf);
|
||||
}
|
||||
|
||||
fn render_version_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
|
||||
match &state.versions {
|
||||
LoadState::Idle | LoadState::Loading => {
|
||||
Paragraph::new("Loading versions...")
|
||||
.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.popup_new_instance.error_fg))
|
||||
.render(area, buf);
|
||||
}
|
||||
LoadState::Loaded(_) => {
|
||||
let items: Vec<ListItem> = visible_versions(state)
|
||||
.into_iter()
|
||||
.map(|version| {
|
||||
let suffix = if version.stable {
|
||||
String::new()
|
||||
} else {
|
||||
" (snapshot)".to_string()
|
||||
};
|
||||
ListItem::new(Line::from(Span::styled(
|
||||
format!("{}{}", version.id, suffix),
|
||||
Style::default().fg(THEME.popup_new_instance.text_fg),
|
||||
)))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let list = List::new(items)
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.fg(THEME.popup_new_instance.accent_fg)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.highlight_symbol("▶ ");
|
||||
|
||||
let mut list_state = ListState::default().with_selected(Some(state.version_idx));
|
||||
StatefulWidget::render(list, area, buf, &mut list_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn render_loader_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
|
||||
let loaders = [
|
||||
ModLoader::Vanilla,
|
||||
ModLoader::Fabric,
|
||||
ModLoader::Forge,
|
||||
ModLoader::NeoForge,
|
||||
ModLoader::Quilt,
|
||||
];
|
||||
|
||||
let items: Vec<ListItem> = loaders
|
||||
.into_iter()
|
||||
.map(|loader| {
|
||||
ListItem::new(Line::from(Span::styled(
|
||||
loader.to_string(),
|
||||
Style::default().fg(THEME.popup_new_instance.text_fg),
|
||||
)))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let list = List::new(items)
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.fg(THEME.popup_new_instance.accent_fg)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.highlight_symbol("▶ ");
|
||||
|
||||
let mut list_state = ListState::default().with_selected(Some(state.loader_idx));
|
||||
StatefulWidget::render(list, area, buf, &mut list_state);
|
||||
}
|
||||
|
||||
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.popup_new_instance.field_inactive_border_fg))
|
||||
.render(area, buf);
|
||||
return;
|
||||
}
|
||||
|
||||
match &state.loader_versions {
|
||||
LoadState::Idle | LoadState::Loading => {
|
||||
Paragraph::new(format!("Loading {} versions...", state.selected_loader()))
|
||||
.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.popup_new_instance.error_fg))
|
||||
.render(area, buf);
|
||||
}
|
||||
LoadState::Loaded(versions) => {
|
||||
let items: Vec<ListItem> = versions
|
||||
.iter()
|
||||
.map(|version| {
|
||||
ListItem::new(Line::from(Span::styled(
|
||||
version.clone(),
|
||||
Style::default().fg(THEME.popup_new_instance.text_fg),
|
||||
)))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let list = List::new(items)
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.fg(THEME.popup_new_instance.accent_fg)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.highlight_symbol("▶ ");
|
||||
|
||||
let mut list_state = ListState::default().with_selected(Some(state.loader_version_idx));
|
||||
StatefulWidget::render(list, area, buf, &mut list_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn render_confirm_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
|
||||
let game_version = state
|
||||
.selected_version()
|
||||
.map(|version| version.id.as_str())
|
||||
.unwrap_or("<not selected>");
|
||||
let loader = state.selected_loader();
|
||||
let loader_version = if loader == ModLoader::Vanilla {
|
||||
"n/a".to_string()
|
||||
} else {
|
||||
state
|
||||
.selected_loader_version()
|
||||
.unwrap_or_else(|| "<not selected>".to_string())
|
||||
};
|
||||
|
||||
let label_style = Style::default().fg(THEME.popup_new_instance.border_fg);
|
||||
|
||||
Paragraph::new(vec![
|
||||
Line::from(vec![
|
||||
Span::styled("Name: ", label_style),
|
||||
Span::raw(state.name_state.value()),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("MC: ", label_style),
|
||||
Span::raw(game_version),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("Loader: ", label_style),
|
||||
Span::raw(loader.to_string()),
|
||||
]),
|
||||
Line::from(vec![
|
||||
Span::styled("Loader version: ", label_style),
|
||||
Span::raw(loader_version),
|
||||
]),
|
||||
])
|
||||
.style(Style::default().fg(THEME.popup_new_instance.text_fg))
|
||||
.wrap(Wrap { trim: true })
|
||||
.render(area, buf);
|
||||
}
|
||||
|
||||
fn visible_versions(state: &WizardState) -> Vec<GameVersion> {
|
||||
pub(crate) fn visible_versions(state: &WizardState) -> Vec<GameVersion> {
|
||||
let q = state.version_search.query.to_lowercase();
|
||||
match &state.versions {
|
||||
LoadState::Loaded(versions) => versions
|
||||
@@ -678,7 +365,7 @@ fn visible_versions(state: &WizardState) -> Vec<GameVersion> {
|
||||
}
|
||||
}
|
||||
|
||||
fn clamp_version_index(state: &mut WizardState) {
|
||||
pub(crate) fn clamp_version_index(state: &mut WizardState) {
|
||||
let count = visible_versions(state).len();
|
||||
if count == 0 {
|
||||
state.version_idx = 0;
|
||||
@@ -687,7 +374,7 @@ fn clamp_version_index(state: &mut WizardState) {
|
||||
}
|
||||
}
|
||||
|
||||
fn clamp_loader_version_index(state: &mut WizardState) {
|
||||
pub(crate) fn clamp_loader_version_index(state: &mut WizardState) {
|
||||
if let LoadState::Loaded(versions) = &state.loader_versions {
|
||||
if versions.is_empty() {
|
||||
state.loader_version_idx = 0;
|
||||
@@ -699,7 +386,7 @@ fn clamp_loader_version_index(state: &mut WizardState) {
|
||||
}
|
||||
}
|
||||
|
||||
fn ensure_versions_loaded(state: &mut WizardState) {
|
||||
pub(crate) fn ensure_versions_loaded(state: &mut WizardState) {
|
||||
if !matches!(state.versions, LoadState::Idle) {
|
||||
return;
|
||||
}
|
||||
@@ -733,7 +420,7 @@ fn ensure_versions_loaded(state: &mut WizardState) {
|
||||
});
|
||||
}
|
||||
|
||||
fn ensure_loader_versions_loaded(state: &mut WizardState, loader: ModLoader, game_version: String) {
|
||||
pub(crate) fn ensure_loader_versions_loaded(state: &mut WizardState, loader: ModLoader, game_version: String) {
|
||||
if !matches!(state.loader_versions, LoadState::Idle) {
|
||||
return;
|
||||
}
|
||||
@@ -13,7 +13,7 @@ use ratatui::{
|
||||
use ratatui_image::{protocol::StatefulProtocol, Resize, StatefulImage};
|
||||
|
||||
use crate::instance::screenshots::ScreenshotEntry;
|
||||
use crate::tui::theme::THEME;
|
||||
use crate::config::theme::THEME;
|
||||
|
||||
const TARGET_CELL_WIDTH: u16 = 34;
|
||||
const MIN_CELL_WIDTH: u16 = 24;
|
||||
@@ -219,14 +219,18 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut ScreenshotsState) -> bool {
|
||||
KeyCode::Enter if key_event.modifiers.contains(KeyModifiers::SHIFT) => {
|
||||
if let Some(entry) = state.entries.get(state.selected) {
|
||||
if let Some(dir) = entry.path.parent() {
|
||||
xdg_open(dir);
|
||||
if let Err(e) = open::that(dir) {
|
||||
tracing::error!("Failed to open directory: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
if let Some(entry) = state.entries.get(state.selected) {
|
||||
xdg_open(&entry.path);
|
||||
if let Err(e) = open::that(&entry.path) {
|
||||
tracing::error!("Failed to open file: {}", e);
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
@@ -261,22 +265,12 @@ pub fn handle_key(key_event: &KeyEvent, state: &mut ScreenshotsState) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
fn xdg_open(path: &std::path::Path) {
|
||||
if let Err(e) = std::process::Command::new("xdg-open")
|
||||
.arg(path)
|
||||
.stdout(std::process::Stdio::null())
|
||||
.stderr(std::process::Stdio::null())
|
||||
.spawn()
|
||||
{
|
||||
tracing::error!("Failed to open: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(frame: &mut Frame, area: Rect, state: &mut ScreenshotsState, is_focused: bool) {
|
||||
let theme = THEME.as_ref();
|
||||
if state.loading {
|
||||
frame.render_widget(
|
||||
Paragraph::new("Loading screenshots...")
|
||||
.style(Style::default().fg(THEME.screenshots.label_fg)),
|
||||
.style(Style::default().fg(theme.text_dim())),
|
||||
area,
|
||||
);
|
||||
return;
|
||||
@@ -285,7 +279,7 @@ 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.screenshots.label_fg)),
|
||||
.style(Style::default().fg(theme.text_dim())),
|
||||
area,
|
||||
);
|
||||
return;
|
||||
@@ -352,10 +346,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.screenshots.selected_border_fg)
|
||||
.fg(theme.accent())
|
||||
.add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
Style::default().fg(THEME.screenshots.label_fg)
|
||||
Style::default().fg(theme.text_dim())
|
||||
};
|
||||
|
||||
let truncated = if name.len() > cell_width as usize {
|
||||
@@ -382,7 +376,7 @@ pub fn render(frame: &mut Frame, area: Rect, state: &mut ScreenshotsState, is_fo
|
||||
.begin_symbol(Some("\u{25b2}"))
|
||||
.style(
|
||||
Style::default()
|
||||
.fg(THEME.screenshots.border_focused_fg)
|
||||
.fg(theme.text_dim())
|
||||
.add_modifier(Modifier::BOLD),
|
||||
)
|
||||
.thumb_symbol("\u{2551}")
|
||||
|
||||
@@ -3,7 +3,7 @@ use ratatui::{
|
||||
text::{Line, Span},
|
||||
};
|
||||
|
||||
use crate::tui::theme::THEME;
|
||||
use crate::config::theme::THEME;
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct SearchState {
|
||||
@@ -77,9 +77,10 @@ impl SearchState {
|
||||
return None;
|
||||
}
|
||||
|
||||
let dim = Style::default().fg(THEME.search.border_unfocused_fg);
|
||||
let theme = THEME.as_ref();
|
||||
let dim = Style::default().fg(theme.text_dim());
|
||||
let accent = Style::default()
|
||||
.fg(THEME.search.border_focused_fg)
|
||||
.fg(theme.text_dim())
|
||||
.add_modifier(Modifier::BOLD);
|
||||
|
||||
let mut spans = vec![
|
||||
|
||||
+15
-14
@@ -7,9 +7,9 @@ use ratatui::{
|
||||
};
|
||||
use throbber_widgets_tui::{Throbber, ThrobberState};
|
||||
|
||||
use crate::tui::layout::FocusedArea;
|
||||
use crate::tui::app::FocusedArea;
|
||||
use crate::tui::progress::PROGRESS;
|
||||
use crate::tui::theme::THEME;
|
||||
use crate::config::theme::{THEME, BORDER_STYLE};
|
||||
|
||||
use super::styled_title;
|
||||
|
||||
@@ -19,16 +19,17 @@ pub fn render(
|
||||
focused: FocusedArea,
|
||||
throbber_state: &mut ThrobberState,
|
||||
) {
|
||||
let theme = THEME.as_ref();
|
||||
let border_color = if focused == FocusedArea::Overview {
|
||||
THEME.status.border_focused_fg
|
||||
theme.accent()
|
||||
} else {
|
||||
THEME.status.border_unfocused_fg
|
||||
theme.border()
|
||||
};
|
||||
|
||||
let block = Block::default()
|
||||
.title(styled_title("Overview", true))
|
||||
.borders(Borders::ALL)
|
||||
.border_type(THEME.general.border_type.to_border_type())
|
||||
.border_type(BORDER_STYLE.to_border_type())
|
||||
.border_style(Style::default().fg(border_color));
|
||||
|
||||
let state = match PROGRESS.lock() {
|
||||
@@ -37,7 +38,7 @@ pub fn render(
|
||||
frame.render_widget(
|
||||
Paragraph::new(Span::styled(
|
||||
"Ready",
|
||||
Style::default().fg(THEME.status.label_fg),
|
||||
Style::default().fg(theme.text_dim()),
|
||||
))
|
||||
.block(block),
|
||||
area,
|
||||
@@ -50,7 +51,7 @@ pub fn render(
|
||||
frame.render_widget(
|
||||
Paragraph::new(Span::styled(
|
||||
"Ready",
|
||||
Style::default().fg(THEME.status.label_fg),
|
||||
Style::default().fg(theme.text_dim()),
|
||||
))
|
||||
.block(block),
|
||||
area,
|
||||
@@ -77,19 +78,19 @@ pub fn render(
|
||||
let gauge = Gauge::default()
|
||||
.gauge_style(
|
||||
Style::default()
|
||||
.fg(THEME.status.progress_fill_fg)
|
||||
.bg(THEME.status.progress_track_fg)
|
||||
.fg(theme.success())
|
||||
.bg(theme.surface())
|
||||
.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.status.text_fg)),
|
||||
Paragraph::new(action_text).style(Style::default().fg(theme.text())),
|
||||
chunks[1],
|
||||
);
|
||||
if !sub_text.is_empty() {
|
||||
frame.render_widget(
|
||||
Paragraph::new(sub_text).style(Style::default().fg(THEME.status.label_fg)),
|
||||
Paragraph::new(sub_text).style(Style::default().fg(theme.text_dim())),
|
||||
chunks[2],
|
||||
);
|
||||
}
|
||||
@@ -99,16 +100,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.status.text_fg))
|
||||
.style(Style::default().fg(theme.text()))
|
||||
.throbber_style(
|
||||
Style::default()
|
||||
.fg(THEME.status.border_focused_fg)
|
||||
.fg(theme.text_dim())
|
||||
.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.status.label_fg)),
|
||||
Paragraph::new(sub_text).style(Style::default().fg(theme.text_dim())),
|
||||
chunks[1],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user