diff --git a/src/tui/tests/snapshots/rmcl__tui__tests__snapshots__empty_app_renders_the_complete_frame.snap b/src/tui/tests/snapshots/rmcl__tui__tests__snapshots__empty_app_renders_the_complete_frame.snap index 59562a0..cc90885 100644 --- a/src/tui/tests/snapshots/rmcl__tui__tests__snapshots__empty_app_renders_the_complete_frame.snap +++ b/src/tui/tests/snapshots/rmcl__tui__tests__snapshots__empty_app_renders_the_complete_frame.snap @@ -25,8 +25,8 @@ expression: ui.screen() "│ ││ │" "│ ││ │" "│ ││ │" -"│ ││[l] launch [⏎] content [Shift+⏎] open dir [Esc] kill [a] add [m] modpacks│" -"│ │╰────────────────────────────────[u] update [d] delete [r] rename [/] search╯" +"│ ││ │" +"│ │╰[l] launch [⏎] content [Shift+⏎] open dir [Esc] kill [a] add [m] modpacks╯" "│ │╭Accounts─────────╮╭Settings───────────────────────────╮╭Overview──────────────╮" "│ ││No accounts. ││▸ instance default ││Ready │" "│ ││ ││ ││ │" diff --git a/src/tui/tests/snapshots/rmcl__tui__tests__snapshots__provider_conflict_renders_the_complete_frame.snap b/src/tui/tests/snapshots/rmcl__tui__tests__snapshots__provider_conflict_renders_the_complete_frame.snap index 34594de..02a964c 100644 --- a/src/tui/tests/snapshots/rmcl__tui__tests__snapshots__provider_conflict_renders_the_complete_frame.snap +++ b/src/tui/tests/snapshots/rmcl__tui__tests__snapshots__provider_conflict_renders_the_complete_frame.snap @@ -25,8 +25,8 @@ expression: ui.screen() "│ ││ │" "│ ││ │" "│ ││ │" -"│ ││[l] launch [⏎] content [Shift+⏎] open dir [Esc] kill [a] add [m] modpacks│" -"│ │╰────────────────────────────────[u] update [d] delete [r] rename [/] search╯" +"│ ││ │" +"│ │╰[l] launch [⏎] content [Shift+⏎] open dir [Esc] kill [a] add [m] modpacks╯" "│ │╭Accounts─────────╮╭Settings───────────────────────────╮╭Overview──────────────╮" "│ ││No accounts. ││▸ instance default ││Ready │" "│ ││ ││ ││ │" diff --git a/src/tui/tests/widgets/popups/mod.rs b/src/tui/tests/widgets/popups/mod.rs index acea60e..cb759c4 100644 --- a/src/tui/tests/widgets/popups/mod.rs +++ b/src/tui/tests/widgets/popups/mod.rs @@ -1,14 +1,14 @@ use super::{ confirm::{ConfirmTarget, confirm_popup_area}, - keybind_lines_wrapped, word_wrap_size, + keybind_line_fitted, word_wrap_size, }; #[test] -fn keybind_wrapping_uses_terminal_width_for_unicode_keys() { - let lines = keybind_lines_wrapped(&[("⏎", " select"), ("a", " add")], 19); +fn fitted_keybinds_use_terminal_width_and_omit_overflow() { + let line = keybind_line_fitted(&[("⏎", " select"), ("a", " add")], 10); - assert_eq!(lines.len(), 1); - assert_eq!(lines[0].width(), 19); + assert_eq!(line.width(), 10); + assert_eq!(line.to_string(), "[⏎] select"); } #[test] diff --git a/src/tui/widgets/account.rs b/src/tui/widgets/account.rs index 1f47599..f55a248 100644 --- a/src/tui/widgets/account.rs +++ b/src/tui/widgets/account.rs @@ -220,21 +220,20 @@ pub fn render(frame: &mut Frame, area: Rect, focused: FocusedArea, state: &mut A .border_type(BORDER_STYLE.to_border_type()) .border_style(Style::default().fg(color)); - let keybind_lines = if focused == FocusedArea::Account { - super::popups::keybind_lines_wrapped( + let keybind_line = if focused == FocusedArea::Account { + Some(super::popups::keybind_line_fitted( &[("⏎", " select"), ("a", " add"), ("d", " del")], area.width.saturating_sub(2), - ) + )) } else { - Vec::new() + None }; - if let Some(line) = keybind_lines.last() { - block = block.title_bottom(line.clone()); + if let Some(line) = keybind_line { + block = block.title_bottom(line); } - let mut inner = block.inner(area); + let inner = block.inner(area); frame.render_widget(block, area); - inner = super::popups::render_keybind_overflow(frame, inner, &keybind_lines); if state.store.accounts.is_empty() { frame.render_widget( diff --git a/src/tui/widgets/content/tabs.rs b/src/tui/widgets/content/tabs.rs index d133c88..dca5ad7 100644 --- a/src/tui/widgets/content/tabs.rs +++ b/src/tui/widgets/content/tabs.rs @@ -345,7 +345,7 @@ pub fn render( ("Shift+⏎", " open dir"), ("h/l", " tabs"), ("/", " search"), - ("Tab", " discover"), + ("Tab", " discovery"), ], (ContentMode::Installed, ContentTab::Worlds) if open_world_datapacks.is_some() => &[ ("j/k", " navigate"), @@ -364,7 +364,7 @@ pub fn render( ("Shift+⏎", " open dir"), ("h/l", " tabs"), ("/", " search"), - ("Tab", " discover"), + ("Tab", " discovery"), ], (ContentMode::Installed, ContentTab::Worlds) => &[ ("j/k", " navigate"), @@ -373,7 +373,7 @@ pub fn render( ("Shift+⏎", " open dir"), ("h/l", " tabs"), ("/", " search"), - ("Tab", " discover"), + ("Tab", " discovery"), ], (ContentMode::Installed, ContentTab::DataPacks) => &[], (ContentMode::Installed, ContentTab::Screenshots) => &[ @@ -383,7 +383,7 @@ pub fn render( ("Shift+⏎", " open dir"), ("h/l", " tabs"), ("/", " search"), - ("Tab", " discover"), + ("Tab", " discovery"), ], (ContentMode::Installed, ContentTab::Logs) => { if logs_state.viewer_focused { @@ -393,7 +393,7 @@ pub fn render( ("d", " delete"), ("Esc", " back"), ("/", " search"), - ("Tab", " discover"), + ("Tab", " discovery"), ] } else { &[ @@ -402,7 +402,7 @@ pub fn render( ("d", " delete"), ("h/l", " tabs"), ("/", " search"), - ("Tab", " discover"), + ("Tab", " discovery"), ] } } @@ -428,16 +428,14 @@ pub fn render( if is_focused && mode == ContentMode::Installed && !has_updates { keybinds.retain(|(key, _)| *key != "u"); } - let keybind_lines = - crate::tui::widgets::popups::keybind_lines_wrapped(&keybinds, area.width.saturating_sub(2)); - if let Some(line) = keybind_lines.last() { - block = block.title_bottom(line.clone()); - } + // The main panel footer stays on its border; lower-priority hints are omitted when narrow. + block = block.title_bottom(crate::tui::widgets::popups::keybind_line_fitted( + &keybinds, + area.width.saturating_sub(2), + )); - let mut content_area = block.inner(area); + let content_area = block.inner(area); frame.render_widget(block, area); - content_area = - crate::tui::widgets::popups::render_keybind_overflow(frame, content_area, &keybind_lines); let downloadable_state = match tab { ContentTab::Mods => Some((mods_state, mods_discovery_state)), diff --git a/src/tui/widgets/popups/mod.rs b/src/tui/widgets/popups/mod.rs index ac7feaa..b3c8836 100644 --- a/src/tui/widgets/popups/mod.rs +++ b/src/tui/widgets/popups/mod.rs @@ -11,12 +11,7 @@ pub mod new_instance; pub use load_state::LoadState; -use ratatui::{ - Frame, - layout::{Alignment, Constraint, Layout, Rect}, - text::{Line, Span}, - widgets::Paragraph, -}; +use ratatui::{layout::Rect, text::Span}; pub(crate) fn compare_game_versions(a: &str, b: &str) -> std::cmp::Ordering { let parse_parts = |version: &str| { @@ -106,74 +101,19 @@ pub fn keybind_line(binds: &[(&str, &str)]) -> ratatui::text::Line<'static> { Line::from(spans) } -// same as keybind_line but wraps to multiple rows when the panel is too narrow -// to fit everything on one line -pub fn keybind_lines_wrapped( - binds: &[(&str, &str)], - max_width: u16, -) -> Vec> { - use crate::config::theme::THEME; - use ratatui::{ - style::{Modifier, Style}, - text::{Line, Span}, - }; - 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> = Vec::new(); - let mut current_spans: Vec> = Vec::new(); - let mut current_width: usize = 0; - - for (i, (key, label)) in binds.iter().enumerate() { - let sep_w = if i > 0 && !current_spans.is_empty() { - 2 - } else { - 0 - }; - let item_w = Span::raw(format!("[{key}]{label}")).width(); - let needed = sep_w + item_w; - - if !current_spans.is_empty() && current_width + needed > max_width as usize { - rows.push(Line::from(current_spans).right_aligned()); - current_spans = Vec::new(); - current_width = 0; +pub fn keybind_line_fitted(binds: &[(&str, &str)], max_width: u16) -> ratatui::text::Line<'static> { + let mut width = 0; + let mut count = 0; + for (key, label) in binds { + let item_width = Span::raw(format!("[{key}]{label}")).width() + usize::from(count > 0) * 2; + if width + item_width > max_width as usize { + break; } - - if !current_spans.is_empty() { - 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(), label_style)); - } - current_width += item_w; + width += item_width; + count += 1; } - if !current_spans.is_empty() { - rows.push(Line::from(current_spans).right_aligned()); - } - - rows -} - -pub fn render_keybind_overflow(frame: &mut Frame, area: Rect, lines: &[Line<'static>]) -> Rect { - let overflow = lines.len().saturating_sub(1); - if overflow == 0 { - return area; - } - - let [content, footer] = - Layout::vertical([Constraint::Min(0), Constraint::Length(overflow as u16)]).areas(area); - frame.render_widget( - Paragraph::new(lines[..overflow].to_vec()).alignment(Alignment::Right), - footer, - ); - content + keybind_line(&binds[..count]).right_aligned() } #[cfg(test)] diff --git a/src/tui/widgets/settings.rs b/src/tui/widgets/settings.rs index c62e4d6..5d3052c 100644 --- a/src/tui/widgets/settings.rs +++ b/src/tui/widgets/settings.rs @@ -210,7 +210,7 @@ pub fn render( .border_type(BORDER_STYLE.to_border_type()) .border_style(Style::default().fg(color)); - let keybind_lines = if focused == FocusedArea::Settings { + let keybind_line = if focused == FocusedArea::Settings { let keybinds: &[(&str, &str)] = match state.pane { SettingsPane::Profile => &[ ("⏎", " select"), @@ -226,17 +226,19 @@ pub fn render( ("h/l", " tab"), ], }; - super::popups::keybind_lines_wrapped(keybinds, area.width.saturating_sub(2)) + Some(super::popups::keybind_line_fitted( + keybinds, + area.width.saturating_sub(2), + )) } else { - Vec::new() + None }; - if let Some(line) = keybind_lines.last() { - block = block.title_bottom(line.clone()); + if let Some(line) = keybind_line { + block = block.title_bottom(line); } - let mut inner = block.inner(area); + let inner = block.inner(area); frame.render_widget(block, area); - inner = super::popups::render_keybind_overflow(frame, inner, &keybind_lines); if inner.width >= 42 { let chunks = Layout::default()