fix: switch default profile to terminal and fixed some comments
This commit is contained in:
1 parent
971375bf1f
commit
52787b57c7
71 files changed
+671
-188
No files matched your search
@@ -1,3 +1,6 @@
|
||||
// rendering for the new instance wizard. each step gets its own render fn
|
||||
// and the popup resizes itself based on which step is active.
|
||||
|
||||
use super::state::{
|
||||
clamp_loader_version_index, clamp_version_index, ensure_loader_versions_loaded,
|
||||
ensure_versions_loaded, visible_versions, LoadState, WizardState, WizardStep, WIZARD_STATE,
|
||||
@@ -16,6 +19,9 @@ use ratatui::{
|
||||
};
|
||||
|
||||
pub fn render(frame: &mut Frame, area: Rect, _focused: FocusedArea) {
|
||||
// grab the lock, kick off any lazy-loading, then clone and release.
|
||||
// data fetching happens here (in render) because the wizard is purely
|
||||
// reactive: version lists only load when you navigate to that step.
|
||||
let snapshot = match WIZARD_STATE.lock() {
|
||||
Ok(mut state) => {
|
||||
if state.step == WizardStep::Version {
|
||||
@@ -23,6 +29,7 @@ pub fn render(frame: &mut Frame, area: Rect, _focused: FocusedArea) {
|
||||
clamp_version_index(&mut state);
|
||||
}
|
||||
|
||||
// vanilla has no loader version, so skip straight to confirm
|
||||
if state.step == WizardStep::LoaderVersion {
|
||||
if state.selected_loader() == ModLoader::Vanilla {
|
||||
state.step = WizardStep::Confirm;
|
||||
@@ -130,6 +137,7 @@ fn step_keybinds(state: &WizardState) -> ratatui::text::Line<'static> {
|
||||
fn render_name_step(state: &WizardState, area: Rect, buf: &mut ratatui::buffer::Buffer) {
|
||||
let theme = THEME.as_ref();
|
||||
let value = state.name_state.value();
|
||||
// \u{2588} is the full block char used as a fake blinking cursor
|
||||
let line = if value.is_empty() {
|
||||
Line::from(vec![
|
||||
Span::styled(
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
// state machine and input handling for the new instance wizard.
|
||||
// flow: Name -> Loader -> Version -> LoaderVersion -> Confirm
|
||||
// version lists are fetched lazily from the network when you reach that step.
|
||||
|
||||
use crate::instance::{
|
||||
loader::{get_installer, GameVersion},
|
||||
loader::{GameVersion, get_installer},
|
||||
models::ModLoader,
|
||||
};
|
||||
use crate::tui::widgets::instances;
|
||||
@@ -10,6 +14,7 @@ use tui_prompts::{FocusState, State as PromptState, TextState};
|
||||
|
||||
pub(crate) static WIZARD_STATE: LazyLock<Arc<Mutex<WizardState>>> =
|
||||
LazyLock::new(|| Arc::new(Mutex::new(WizardState::default())));
|
||||
// populated on confirm, consumed by the main event loop to actually create the instance
|
||||
pub(crate) static WIZARD_RESULT: LazyLock<Arc<Mutex<Option<WizardParams>>>> =
|
||||
LazyLock::new(|| Arc::new(Mutex::new(None)));
|
||||
|
||||
@@ -31,8 +36,7 @@ pub enum WizardStep {
|
||||
Confirm,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Default)]
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub enum LoadState<T> {
|
||||
#[default]
|
||||
Idle,
|
||||
@@ -386,6 +390,8 @@ pub(crate) fn clamp_loader_version_index(state: &mut WizardState) {
|
||||
}
|
||||
}
|
||||
|
||||
// only fires on the Idle -> Loading transition to avoid spamming requests.
|
||||
// the spawned task writes results back into WIZARD_STATE when done.
|
||||
pub(crate) fn ensure_versions_loaded(state: &mut WizardState) {
|
||||
if !matches!(state.versions, LoadState::Idle) {
|
||||
return;
|
||||
@@ -420,7 +426,11 @@ pub(crate) fn ensure_versions_loaded(state: &mut WizardState) {
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) 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;
|
||||
}
|
||||
@@ -452,6 +462,8 @@ pub(crate) fn ensure_loader_versions_loaded(state: &mut WizardState, loader: Mod
|
||||
});
|
||||
}
|
||||
|
||||
// quick and dirty semver compare. doesn't handle pre-release tags or anything
|
||||
// fancy, just splits on dots and compares numerically. good enough for mc versions.
|
||||
fn compare_semver(a: &str, b: &str) -> std::cmp::Ordering {
|
||||
let parse_parts = |s: &str| -> Vec<u64> {
|
||||
s.split('.')
|
||||
@@ -470,6 +482,5 @@ fn compare_semver(a: &str, b: &str) -> std::cmp::Ordering {
|
||||
}
|
||||
|
||||
fn sort_versions_semver(versions: &mut [GameVersion]) {
|
||||
// Sort newest first (descending), so compare b vs a
|
||||
versions.sort_by(|a, b| compare_semver(&b.id, &a.id));
|
||||
}
|
||||
Reference in new issue
Block a user