fed fixes

This commit is contained in:
Ultradesu
2026-07-21 00:12:45 +03:00
parent 151e2cf337
commit da5d2410ac
24 changed files with 2660 additions and 461 deletions
+19
View File
@@ -25,6 +25,8 @@ pub enum Command {
/// `:import <path>` — import an audio file or a directory into the
/// library.
Import(String),
/// `:open frid://...` — open a shared federation content link.
Open(String),
/// `:volume 40` (also `:vol`) — set the volume precisely.
Volume(u8),
/// `:seek +30` / `:seek -10` — relative seek in seconds.
@@ -82,6 +84,13 @@ pub fn parse(input: &str) -> Parsed {
_ => Parsed::Invalid("usage: :import <file or directory>".to_string()),
}
}
"open" => {
let value = input.trim_start().split_once(char::is_whitespace);
match value.map(|(_, rest)| rest.trim()) {
Some(value) if !value.is_empty() => Parsed::Command(Command::Open(value.into())),
_ => Parsed::Invalid("usage: :open frid://<content_id>".to_string()),
}
}
"volume" | "vol" => match arg.and_then(|a| a.parse::<u8>().ok()) {
Some(value) if value <= 100 => Parsed::Command(Command::Volume(value)),
_ => Parsed::Invalid("usage: :volume 0-100".to_string()),
@@ -162,7 +171,17 @@ mod tests {
parse("import ~/Music/My Album"),
Parsed::Command(Command::Import("~/Music/My Album".to_string()))
);
assert_eq!(
parse(
"open frid://b3:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef?t=A-B"
),
Parsed::Command(Command::Open(
"frid://b3:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef?t=A-B"
.to_string()
))
);
assert!(matches!(parse("import"), Parsed::Invalid(_)));
assert!(matches!(parse("open"), Parsed::Invalid(_)));
assert_eq!(parse("volume 40"), Parsed::Command(Command::Volume(40)));
assert_eq!(parse("vol 0"), Parsed::Command(Command::Volume(0)));
assert_eq!(parse("shuffle"), Parsed::Command(Command::Shuffle));