From 8f7e1174388c42c76e2638ce9582085af4259ba1 Mon Sep 17 00:00:00 2001 From: objz Date: Fri, 4 Sep 2026 21:28:04 +0200 Subject: [PATCH] fix: polish launcher settings rows --- src/tui/app.rs | 7 +- src/tui/input.rs | 12 ++- src/tui/mod.rs | 4 +- src/tui/tests/harness.rs | 1 + src/tui/widgets/popups/global_settings.rs | 92 ++++++++++++++++++----- 5 files changed, 93 insertions(+), 23 deletions(-) diff --git a/src/tui/app.rs b/src/tui/app.rs index 20c31b4..4a91950 100644 --- a/src/tui/app.rs +++ b/src/tui/app.rs @@ -48,6 +48,7 @@ pub struct App { pub(super) pending_instance_settings_updates: HashSet, pub(super) global_settings: Option, pub(super) picker: ratatui_image::picker::Picker, + pub(super) detected_image_protocol: ratatui_image::picker::ProtocolType, pub(super) instance_manager: InstanceManager, pub(super) log_overlay_scroll: usize, pub(super) log_overlay_max_scroll: usize, @@ -121,7 +122,10 @@ impl App { supported } - pub fn new(picker: ratatui_image::picker::Picker) -> Self { + pub fn new( + picker: ratatui_image::picker::Picker, + detected_image_protocol: ratatui_image::picker::ProtocolType, + ) -> Self { let instances_dir = crate::config::SETTINGS.read().paths.resolve_instances_dir(); let meta_dir = crate::config::SETTINGS.read().paths.resolve_meta_dir(); @@ -188,6 +192,7 @@ impl App { s }, picker, + detected_image_protocol, instance_manager: manager, log_overlay_scroll: 0, log_overlay_max_scroll: 0, diff --git a/src/tui/input.rs b/src/tui/input.rs index 11fc7a5..8ff6635 100644 --- a/src/tui/input.rs +++ b/src/tui/input.rs @@ -685,7 +685,11 @@ impl App { } widgets::settings::SettingsAction::OpenGlobal => { self.pre_overlay_focused = FocusedArea::Settings; - self.global_settings = Some(widgets::popups::global_settings::State::new()); + self.global_settings = Some( + widgets::popups::global_settings::State::with_detected_image_protocol( + self.detected_image_protocol, + ), + ); self.focused = FocusedArea::GlobalSettings; return Ok(()); } @@ -937,7 +941,11 @@ impl App { } KeyCode::Char('G') => { self.pre_overlay_focused = self.focused; - self.global_settings = Some(widgets::popups::global_settings::State::new()); + self.global_settings = Some( + widgets::popups::global_settings::State::with_detected_image_protocol( + self.detected_image_protocol, + ), + ); self.focused = FocusedArea::GlobalSettings; } KeyCode::Char('O') => { diff --git a/src/tui/mod.rs b/src/tui/mod.rs index 1628583..b37d678 100644 --- a/src/tui/mod.rs +++ b/src/tui/mod.rs @@ -69,14 +69,14 @@ pub async fn show() -> color_eyre::Result<()> { }; picker.set_protocol_type(requested_protocol); - let mut app = app::App::new(picker); + let mut app = app::App::new(picker, detected_protocol); match run_layout_migration_screen(&mut terminal, &mut app).await? { MigrationScreenOutcome::NotNeeded => {} MigrationScreenOutcome::Migrated => { // the modal uses pre-migration state as its background. rebuild the // app after confirmation so no instance or profile data stays stale let picker = app.into_picker(); - app = app::App::new(picker); + app = app::App::new(picker, detected_protocol); } MigrationScreenOutcome::Quit => return Ok(()), } diff --git a/src/tui/tests/harness.rs b/src/tui/tests/harness.rs index 99fcd69..9f6311c 100644 --- a/src/tui/tests/harness.rs +++ b/src/tui/tests/harness.rs @@ -91,6 +91,7 @@ impl UiHarness { pending_instance_settings_updates: Default::default(), global_settings: None, picker, + detected_image_protocol: ratatui_image::picker::ProtocolType::Halfblocks, instance_manager, log_overlay_scroll: 0, log_overlay_max_scroll: 0, diff --git a/src/tui/widgets/popups/global_settings.rs b/src/tui/widgets/popups/global_settings.rs index 59117f4..d7fee47 100644 --- a/src/tui/widgets/popups/global_settings.rs +++ b/src/tui/widgets/popups/global_settings.rs @@ -55,6 +55,7 @@ pub struct State { settings_picker: SettingsPicker, choice_index: usize, display_resolutions: Vec, + detected_image_protocol: &'static str, } pub enum Action { @@ -69,6 +70,12 @@ pub enum Action { impl State { pub fn new() -> Self { + Self::with_detected_image_protocol(ratatui_image::picker::ProtocolType::Halfblocks) + } + + pub fn with_detected_image_protocol( + detected_image_protocol: ratatui_image::picker::ProtocolType, + ) -> Self { let theme = crate::config::theme::current_theme_config(); let themes = available_themes(); let theme_index = themes @@ -103,6 +110,12 @@ impl State { settings_picker: SettingsPicker::default(), choice_index: 0, display_resolutions: display_resolutions(), + detected_image_protocol: match detected_image_protocol { + ratatui_image::picker::ProtocolType::Halfblocks => "halfblocks", + ratatui_image::picker::ProtocolType::Sixel => "sixel", + ratatui_image::picker::ProtocolType::Kitty => "kitty", + ratatui_image::picker::ProtocolType::Iterm2 => "iterm2", + }, } } @@ -704,7 +717,7 @@ fn available_themes() -> Vec { pub fn popup_rect(area: Rect, state: &State) -> Rect { let form_width = (area.width * 86 / 100).saturating_sub(2); - let form_height = 37 + let form_height = 38 + tagged_row_count(&state.config.defaults.jvm_args, form_width).saturating_sub(1) as u16 + tagged_row_count( &environment_labels(&state.config.defaults.environment), @@ -729,7 +742,7 @@ pub fn popup_rect(area: Rect, state: &State) -> Rect { }; area.centered( ratatui::layout::Constraint::Percentage(width), - ratatui::layout::Constraint::Length(height.min(area.height.saturating_sub(2))), + ratatui::layout::Constraint::Length(height.min(area.height)), ) } @@ -891,6 +904,7 @@ fn render_settings_list(frame: &mut Frame, area: Rect, state: &State) { for index in *fields { let label = field_label(*index); let lines = match index { + 1 => border_field_lines(state), 8 => tagged_value_lines( global_field_line(state, *index, label).spans, state.selected == *index, @@ -981,9 +995,18 @@ fn maintenance_line(state: &State) -> Line<'static> { if selected { "▌ " } else { " " }, Style::default().fg(theme.accent()), ), - status_badge("Clear caches", theme.warning()), Span::styled( - " Rebuild provider and Java metadata", + "Clear caches", + Style::default() + .fg(if selected { + theme.accent() + } else { + theme.warning() + }) + .add_modifier(Modifier::BOLD), + ), + Span::styled( + " Rebuild provider and Java metadata", Style::default().fg(if selected { theme.text() } else { @@ -993,6 +1016,41 @@ fn maintenance_line(state: &State) -> Line<'static> { ]) } +fn border_field_lines(state: &State) -> Vec> { + let theme = THEME.as_ref(); + let selected = state.selected == 1; + let value_style = Style::default() + .fg(if selected { + theme.accent() + } else { + theme.text() + }) + .add_modifier(if selected { + Modifier::BOLD + } else { + Modifier::empty() + }); + let (top, bottom) = border_preview(&state.theme.border_style); + vec![ + Line::from(vec![ + Span::styled( + if selected { "▌ " } else { " " }, + Style::default().fg(theme.accent()), + ), + Span::styled( + format!("{:<18}", field_label(1)), + Style::default().fg(theme.text_dim()), + ), + Span::styled(top, value_style), + ]), + Line::from(vec![ + Span::raw(" ".repeat(20)), + Span::styled(bottom, value_style), + Span::styled(format!(" {}", state.display_value(1)), value_style), + ]), + ] +} + fn section_line(title: &str) -> Line<'static> { Line::from(Span::styled( format!(" {title}"), @@ -1048,14 +1106,8 @@ fn global_field_line(state: &State, index: usize, label: &str) -> Line<'static> Span::styled( if editing || matches!(index, 3 | 4 | 8 | 9 | 10) { String::new() - } else if index == 1 { - format!( - "{} {}", - border_preview(&state.theme.border_style), - state.display_value(index) - ) } else if index == 2 && state.config.ui.image_protocol == ImageProtocol::Auto { - "terminal detected".to_owned() + state.detected_image_protocol.to_owned() } else { state.display_value(index) }, @@ -1079,6 +1131,7 @@ fn global_field_line(state: &State, index: usize, label: &str) -> Line<'static> spans.extend([Span::raw(" "), auto_label()]); } if index == 10 && !editing { + spans.push(Span::raw(" ")); spans.push(match state.config.content.preferred_provider { ContentProvider::Modrinth => status_badge("Modrinth", theme.success()), ContentProvider::CurseForge => status_badge("CurseForge", theme.warning()), @@ -1097,12 +1150,12 @@ fn global_field_line(state: &State, index: usize, label: &str) -> Line<'static> })) } -fn border_preview(style: &BorderStyle) -> &'static str { +fn border_preview(style: &BorderStyle) -> (&'static str, &'static str) { match style { - BorderStyle::Plain => "┌──┐", - BorderStyle::Rounded => "╭──╮", - BorderStyle::Double => "╔══╗", - BorderStyle::Thick => "┏━━┓", + BorderStyle::Plain => ("┌──┐", "└──┘"), + BorderStyle::Rounded => ("╭──╮", "╰──╯"), + BorderStyle::Double => ("╔══╗", "╚══╝"), + BorderStyle::Thick => ("┏━━┓", "┗━━┛"), } } @@ -1301,7 +1354,7 @@ mod tests { let mut state = State::new(); assert!(matches!( border_preview(&state.theme.border_style), - "┌──┐" | "╭──╮" | "╔══╗" | "┏━━┓" + ("┌──┐", "└──┘") | ("╭──╮", "╰──╯") | ("╔══╗", "╚══╝") | ("┏━━┓", "┗━━┛") )); state.selected = 0; @@ -1313,7 +1366,8 @@ mod tests { #[test] fn expanded_form_keeps_all_sections_visible_without_scrolling() { - let mut state = State::new(); + let mut state = + State::with_detected_image_protocol(ratatui_image::picker::ProtocolType::Kitty); state.selected = 23; state.config.defaults.jvm_args = vec!["-Xfoo".to_owned()]; state @@ -1335,6 +1389,8 @@ mod tests { let screen = terminal.backend().to_string(); assert!(screen.contains("Appearance")); assert!(screen.contains("Maintenance")); + assert!(screen.contains("kitty")); + assert!(screen.contains("Auto")); assert!(screen.contains("Clear caches")); assert!(screen.contains("Rebuild provider and Java metadata")); assert!(