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
-1
@@ -170,7 +170,10 @@ impl Action {
|
||||
Action::Quit => "Quit".into(),
|
||||
Action::NextTab => "Next tab".into(),
|
||||
Action::PrevTab => "Previous tab".into(),
|
||||
Action::GoToTab(i) => format!("Go to tab {}", i + 1),
|
||||
Action::GoToTab(i) => match crate::app::state::Tab::from_index(*i) {
|
||||
Some(tab) => format!("Go to {}", tab.title()),
|
||||
None => format!("Go to tab {}", i + 1),
|
||||
},
|
||||
Action::MoveUp => "Move up".into(),
|
||||
Action::MoveDown => "Move down".into(),
|
||||
Action::MoveLeft => "Move left".into(),
|
||||
|
||||
+8
-1
@@ -1467,15 +1467,20 @@ pub enum Tab {
|
||||
Global,
|
||||
Playlists,
|
||||
Queue,
|
||||
Podcasts,
|
||||
Federation,
|
||||
Logs,
|
||||
}
|
||||
|
||||
impl Tab {
|
||||
pub const ALL: [Tab; 5] = [
|
||||
/// Display, Tab/Shift+Tab and `GoToTab` index order (`1`..`6`). Changing
|
||||
/// it changes what `GoToTab(n)` means in users' keymap files: bump
|
||||
/// `config::keymap::KEYMAP_VERSION` and remap older files in memory.
|
||||
pub const ALL: [Tab; 6] = [
|
||||
Tab::Global,
|
||||
Tab::Playlists,
|
||||
Tab::Queue,
|
||||
Tab::Podcasts,
|
||||
Tab::Federation,
|
||||
Tab::Logs,
|
||||
];
|
||||
@@ -1485,6 +1490,7 @@ impl Tab {
|
||||
Tab::Global => "Library",
|
||||
Tab::Playlists => "Playlists",
|
||||
Tab::Queue => "Queue",
|
||||
Tab::Podcasts => "Podcasts",
|
||||
Tab::Federation => "Settings",
|
||||
Tab::Logs => "Logs",
|
||||
}
|
||||
@@ -1511,6 +1517,7 @@ impl Tab {
|
||||
Tab::Global => KeyContext::Library,
|
||||
Tab::Playlists => KeyContext::Playlists,
|
||||
Tab::Queue => KeyContext::Queue,
|
||||
Tab::Podcasts => KeyContext::Podcasts,
|
||||
Tab::Federation => KeyContext::Federation,
|
||||
Tab::Logs => KeyContext::Logs,
|
||||
}
|
||||
|
||||
+4
-4
@@ -1016,7 +1016,7 @@ fn current_track_list_context(state: &AppState) -> Option<(TrackSelectionScope,
|
||||
state.queue_tab.cursor,
|
||||
state.player.queue.len(),
|
||||
)),
|
||||
Tab::Federation | Tab::Logs => None,
|
||||
Tab::Podcasts | Tab::Federation | Tab::Logs => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1070,7 +1070,7 @@ fn current_track_list(state: &AppState) -> Option<(TrackSelectionScope, usize, V
|
||||
state.queue_tab.cursor,
|
||||
state.player.queue.clone(),
|
||||
)),
|
||||
Tab::Federation | Tab::Logs => None,
|
||||
Tab::Podcasts | Tab::Federation | Tab::Logs => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1371,7 +1371,7 @@ pub fn selected_track(state: &AppState) -> Option<TrackItem> {
|
||||
.map(|track| (*track).clone())
|
||||
}
|
||||
Tab::Queue => state.player.queue.get(state.queue_tab.cursor).cloned(),
|
||||
Tab::Federation | Tab::Logs => None,
|
||||
Tab::Podcasts | Tab::Federation | Tab::Logs => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3250,7 +3250,7 @@ fn reset_tab(state: &mut AppState, tab: Tab) {
|
||||
state.logs.follow = true;
|
||||
state.logs.selected_seq = None;
|
||||
}
|
||||
Tab::Queue => {}
|
||||
Tab::Queue | Tab::Podcasts => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -186,6 +186,97 @@ fn tab_cycling_wraps() {
|
||||
assert_eq!(state.active_tab, Tab::Global);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tabs_follow_the_documented_order() {
|
||||
use crate::config::keymap::KeyContext;
|
||||
|
||||
assert_eq!(
|
||||
Tab::ALL,
|
||||
[
|
||||
Tab::Global,
|
||||
Tab::Playlists,
|
||||
Tab::Queue,
|
||||
Tab::Podcasts,
|
||||
Tab::Federation,
|
||||
Tab::Logs,
|
||||
]
|
||||
);
|
||||
let titles: Vec<_> = Tab::ALL.iter().map(|tab| tab.title()).collect();
|
||||
assert_eq!(
|
||||
titles,
|
||||
[
|
||||
"Library",
|
||||
"Playlists",
|
||||
"Queue",
|
||||
"Podcasts",
|
||||
"Settings",
|
||||
"Logs"
|
||||
]
|
||||
);
|
||||
for (index, tab) in Tab::ALL.iter().enumerate() {
|
||||
assert_eq!(tab.index(), index);
|
||||
assert_eq!(Tab::from_index(index), Some(*tab));
|
||||
}
|
||||
assert_eq!(Tab::from_index(Tab::ALL.len()), None);
|
||||
assert_eq!(Tab::Podcasts.key_context(), KeyContext::Podcasts);
|
||||
assert_eq!(Tab::Federation.key_context(), KeyContext::Federation);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn next_and_prev_tab_visit_every_tab_in_order() {
|
||||
let mut state = AppState::default();
|
||||
for expected in Tab::ALL.iter().cycle().skip(1).take(Tab::ALL.len()) {
|
||||
update(&mut state, Action::NextTab);
|
||||
assert_eq!(state.active_tab, *expected);
|
||||
}
|
||||
assert_eq!(state.active_tab, Tab::Global);
|
||||
for expected in Tab::ALL.iter().rev() {
|
||||
update(&mut state, Action::PrevTab);
|
||||
assert_eq!(state.active_tab, *expected);
|
||||
}
|
||||
assert_eq!(state.active_tab, Tab::Global);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn go_to_tab_uses_the_new_numbering() {
|
||||
let mut state = AppState::default();
|
||||
for (index, tab) in [
|
||||
(3, Tab::Podcasts),
|
||||
(4, Tab::Federation),
|
||||
(5, Tab::Logs),
|
||||
(2, Tab::Queue),
|
||||
] {
|
||||
update(&mut state, Action::GoToTab(index));
|
||||
assert_eq!(state.active_tab, tab);
|
||||
}
|
||||
// Out-of-range indices are ignored.
|
||||
update(&mut state, Action::GoToTab(6));
|
||||
assert_eq!(state.active_tab, Tab::Queue);
|
||||
// Re-selecting the placeholder tab is a harmless reset.
|
||||
update(&mut state, Action::GoToTab(3));
|
||||
update(&mut state, Action::GoToTab(3));
|
||||
assert_eq!(state.active_tab, Tab::Podcasts);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help_names_tabs_for_go_to_tab() {
|
||||
let labels: Vec<_> = (0..Tab::ALL.len())
|
||||
.map(|index| Action::GoToTab(index).describe())
|
||||
.collect();
|
||||
assert_eq!(
|
||||
labels,
|
||||
[
|
||||
"Go to Library",
|
||||
"Go to Playlists",
|
||||
"Go to Queue",
|
||||
"Go to Podcasts",
|
||||
"Go to Settings",
|
||||
"Go to Logs",
|
||||
]
|
||||
);
|
||||
assert_eq!(Action::GoToTab(6).describe(), "Go to tab 7");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn volume_clamps() {
|
||||
let mut state = AppState::default();
|
||||
|
||||
Reference in new issue
Block a user