Reject a keymap version nested in a binding; fix macOS keymap path in docs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
df171208eb
commit
df7ad3c8b7
4 files changed
+50
-8
No files matched your search
+3
-1
@@ -267,7 +267,9 @@ format `version`. Files from an older format are adapted in memory when they
|
||||
are loaded and the user is told once per start; Furumi never rewrites a
|
||||
user's configuration. The current format, version 2, orders tabs as Library,
|
||||
Playlists, Queue, Podcasts, Settings, Logs; unversioned files use the earlier
|
||||
order and have their tab indices remapped.
|
||||
order and have their tab indices remapped. A `version` key that TOML attached
|
||||
to a binding (written after a `[[keymaps]]` header) is rejected, so a versioned
|
||||
file is never silently mistaken for a legacy one.
|
||||
|
||||
## Scripted visualizations
|
||||
|
||||
|
||||
@@ -164,13 +164,17 @@ Shift+Tab cycle through them:
|
||||
| `6` | Logs |
|
||||
|
||||
The Podcasts tab is a placeholder in this build; podcast support is not
|
||||
available yet. Press `?` for the full list of bindings and commands.
|
||||
available yet. On narrow terminals the tab bar shortens titles and then shows
|
||||
only the numbers, keeping the active tab's full name. Press `?` for the full list of bindings and commands.
|
||||
|
||||
Bindings can be overridden in `keymap.toml` in the platform config directory
|
||||
(`~/.config/furumi/keymap.toml` on Linux and macOS); the bundled
|
||||
(`~/.config/furumi/keymap.toml` on Linux,
|
||||
`~/Library/Application Support/furumi/keymap.toml` on macOS); the bundled
|
||||
`src/config/default_keymap.toml` documents the format. Start the file with
|
||||
`version = 2`, the current format: its `GoToTab` indices are used exactly as
|
||||
written (`0` Library … `5` Logs). Files without `version` were written for the
|
||||
written (`0` Library … `5` Logs). `version` must come before the first
|
||||
`[[keymaps]]` entry; written after one, TOML would attach it to that entry, so
|
||||
Furumi rejects such a file with an error instead of guessing. Files without `version` were written for the
|
||||
older tab order (Settings and Logs on `4`/`5`, Podcasts on `6` in the
|
||||
prototype podcast build); Furumi adapts their tab shortcuts in memory so they
|
||||
keep opening the same tabs, shows a short notice at startup, and never
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
# Default keybindings for furumi.
|
||||
#
|
||||
# To customize, copy entries into <config dir>/furumi/keymap.toml
|
||||
# (~/.config/furumi/keymap.toml on Linux/macOS). A user binding replaces the
|
||||
# default binding with the same key sequence and context.
|
||||
# To customize, copy entries into keymap.toml in the platform config dir
|
||||
# (~/.config/furumi/keymap.toml on Linux,
|
||||
# ~/Library/Application Support/furumi/keymap.toml on macOS). A user binding
|
||||
# replaces the default binding with the same key sequence and context.
|
||||
#
|
||||
# version: keymap format version; put `version = 2` at the top of your file,
|
||||
# before the first [[keymaps]] entry. Version 2 numbers tabs in this order:
|
||||
# before the first [[keymaps]] entry (after one, TOML attaches it to that
|
||||
# entry and the file is rejected). Version 2 numbers tabs in this order:
|
||||
# GoToTab = 0 Library, 1 Playlists, 2 Queue, 3 Podcasts, 4 Settings, 5 Logs.
|
||||
# A file without `version` is treated as the older layout and its GoToTab
|
||||
# indices are adapted in memory (3 -> 4 Settings, 4 -> 5 Logs, and 5 -> 3
|
||||
|
||||
@@ -62,6 +62,11 @@ struct RawBinding {
|
||||
command: Action,
|
||||
#[serde(default)]
|
||||
context: KeyContext,
|
||||
/// Never valid here: a `version = N` line written after a `[[keymaps]]`
|
||||
/// header lands inside that entry. Caught so the file is not silently
|
||||
/// treated as legacy (and its tab indices remapped) despite the version.
|
||||
#[serde(default)]
|
||||
version: Option<toml::Value>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize)]
|
||||
@@ -369,6 +374,11 @@ fn parse_file(text: &str) -> Result<(Option<u32>, Vec<Binding>)> {
|
||||
.keymaps
|
||||
.into_iter()
|
||||
.map(|raw| {
|
||||
if raw.version.is_some() {
|
||||
bail!(
|
||||
"`version` must be a top-level key placed before the first [[keymaps]] entry"
|
||||
);
|
||||
}
|
||||
let keys = parse_sequence(&raw.key_sequence)
|
||||
.with_context(|| format!("bad key_sequence {:?}", raw.key_sequence))?;
|
||||
Ok(Binding {
|
||||
@@ -795,6 +805,30 @@ mod tests {
|
||||
assert!(user.notice.unwrap().contains("newer"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_inside_a_keymaps_entry_is_rejected() {
|
||||
// Appended at the end, TOML puts `version` into the last entry; the
|
||||
// file must not silently fall back to the legacy remap.
|
||||
let err = parse_user_keymap(
|
||||
"[[keymaps]]\nkey_sequence = \"4\"\ncommand = { GoToTab = 3 }\nversion = 2\n",
|
||||
)
|
||||
.err()
|
||||
.expect("misplaced version must be rejected");
|
||||
assert!(
|
||||
format!("{err:#}").contains("before the first [[keymaps]]"),
|
||||
"{err:#}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_keys_in_keymaps_entries_are_still_ignored() {
|
||||
let user = parse_user_keymap(
|
||||
"version = 2\n[[keymaps]]\nkey_sequence = \"4\"\ncommand = { GoToTab = 3 }\nnote = \"mine\"\n",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(go_to_tab_indices(&user.bindings), [3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keymap_version_zero_is_rejected() {
|
||||
assert!(parse_user_keymap("version = 0").is_err());
|
||||
|
||||
Reference in new issue
Block a user