forked from Furumi/furumi-tui
Reorder tabs and migrate legacy keymap tab indices
Tabs are now 1 Library, 2 Playlists, 3 Queue, 4 Podcasts, 5 Settings, 6 Logs. The Podcasts tab is a placeholder that states podcasts are not available in this build yet; it gets its own "podcasts" key context. Keymap files gain an optional top-level `version`. The default keymap declares `version = 2` and binds "6" to the Logs tab. Files without a version (or with version 1) have their GoToTab indices remapped in memory (3 -> 4, 4 -> 5, and 5 -> 3 for the prototype podcast build) with a startup notice; the user's file is never rewritten. The help window names the target tab instead of "Go to tab N". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
292f17fee1
commit
e78f1627da
8 files changed
+487
-11
No files matched your search
@@ -4,6 +4,7 @@ mod federation;
|
||||
pub(crate) mod global;
|
||||
mod logs;
|
||||
mod playlists;
|
||||
mod podcasts;
|
||||
mod popup;
|
||||
#[cfg(test)]
|
||||
mod status_tests;
|
||||
@@ -50,6 +51,62 @@ mod tests {
|
||||
assert_eq!(label, "●");
|
||||
assert_eq!(style, client_style);
|
||||
}
|
||||
|
||||
fn render(state: &AppState, width: u16, height: u16) -> String {
|
||||
let keymap = Keymap::defaults();
|
||||
let mut terminal =
|
||||
ratatui::Terminal::new(ratatui::backend::TestBackend::new(width, height)).unwrap();
|
||||
terminal.draw(|frame| draw(frame, state, &keymap)).unwrap();
|
||||
let buffer = terminal.backend().buffer();
|
||||
(0..height)
|
||||
.map(|y| {
|
||||
(0..width)
|
||||
.map(|x| buffer[(x, y)].symbol())
|
||||
.collect::<String>()
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tab_bar_numbers_tabs_in_the_new_order() {
|
||||
let screen = render(&AppState::default(), 120, 10);
|
||||
let bar = screen.lines().next().unwrap();
|
||||
let positions: Vec<usize> = [
|
||||
"1 Library",
|
||||
"2 Playlists",
|
||||
"3 Queue",
|
||||
"4 Podcasts",
|
||||
"5 Settings",
|
||||
"6 Logs",
|
||||
]
|
||||
.iter()
|
||||
.map(|title| {
|
||||
bar.find(title)
|
||||
.unwrap_or_else(|| panic!("{title} in {bar:?}"))
|
||||
})
|
||||
.collect();
|
||||
assert!(positions.is_sorted(), "{bar:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn podcasts_tab_shows_placeholder() {
|
||||
let mut state = AppState::default();
|
||||
state.active_tab = Tab::Podcasts;
|
||||
let screen = render(&state, 100, 12);
|
||||
assert!(screen.contains(podcasts::UNAVAILABLE), "{screen}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help_lists_tab_names_for_digit_shortcuts() {
|
||||
let mut state = AppState::default();
|
||||
state.help_visible = true;
|
||||
let screen = render(&state, 160, 80);
|
||||
for title in ["Go to Podcasts", "Go to Settings", "Go to Logs"] {
|
||||
assert!(screen.contains(title), "{title} missing:\n{screen}");
|
||||
}
|
||||
assert!(!screen.contains("Go to tab"), "{screen}");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw(frame: &mut Frame, state: &AppState, keymap: &Keymap) {
|
||||
@@ -73,6 +130,7 @@ pub fn draw(frame: &mut Frame, state: &AppState, keymap: &Keymap) {
|
||||
Tab::Global => global::draw(frame, main_area, state),
|
||||
Tab::Playlists => playlists::draw(frame, main_area, state),
|
||||
Tab::Queue => draw_queue(frame, main_area, state),
|
||||
Tab::Podcasts => podcasts::draw(frame, main_area, state),
|
||||
Tab::Federation => federation::draw(frame, main_area, state),
|
||||
Tab::Logs => logs::draw(frame, main_area, state),
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
use ratatui::Frame;
|
||||
use ratatui::layout::{Alignment, Rect};
|
||||
use ratatui::text::Line;
|
||||
use ratatui::widgets::{Block, Paragraph, Wrap};
|
||||
|
||||
use super::theme;
|
||||
use crate::app::state::AppState;
|
||||
|
||||
/// Placeholder notice shown until podcast support lands: the tab already
|
||||
/// holds its final position so the numeric shortcuts stay stable.
|
||||
pub(crate) const UNAVAILABLE: &str = "Podcasts are not available in this build yet.";
|
||||
|
||||
pub fn draw(frame: &mut Frame, area: Rect, state: &AppState) {
|
||||
let block = Block::bordered()
|
||||
.title(" Podcasts ")
|
||||
.title_style(theme::header_for(state))
|
||||
.border_style(theme::border_for(state));
|
||||
let inner = block.inner(area);
|
||||
frame.render_widget(block, area);
|
||||
if inner.height == 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
let lines = vec![
|
||||
Line::styled(UNAVAILABLE, theme::header_for(state)),
|
||||
Line::default(),
|
||||
Line::styled(
|
||||
"Subscriptions, episodes and listening progress will appear here.",
|
||||
theme::dim(),
|
||||
),
|
||||
];
|
||||
let height = (lines.len() as u16).min(inner.height);
|
||||
let body = Rect {
|
||||
y: inner.y + inner.height.saturating_sub(height) / 2,
|
||||
height,
|
||||
..inner
|
||||
};
|
||||
frame.render_widget(
|
||||
Paragraph::new(lines)
|
||||
.alignment(Alignment::Center)
|
||||
.wrap(Wrap { trim: true }),
|
||||
body,
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user