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
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user