fix: bug where text after ! in custom names wouldn't show up

This commit is contained in:
talwat 2025-02-18 21:48:30 +02:00
parent 840b1663e7
commit 1e3c66679c
4 changed files with 14 additions and 8 deletions

View File

@ -36,6 +36,8 @@
clippy::integer_division,
clippy::cast_sign_loss,
clippy::cast_lossless,
clippy::arbitrary_source_item_ordering,
clippy::unused_trait_names
)]
use clap::{Parser, Subcommand};

View File

@ -187,7 +187,7 @@ impl Player {
let volume = PersistentVolume::load().await?;
// Load the track list.
let list = List::load(&args.tracks).await?;
let list = List::load(args.tracks.as_ref()).await?;
// We should only shut up alsa forcefully on Linux if we really have to.
#[cfg(target_os = "linux")]
@ -233,7 +233,9 @@ impl Player {
///
/// This will also set `current` to the newly loaded song.
pub async fn next(&self) -> eyre::Result<tracks::Decoded> {
let track = if let Some(track) = self.tracks.write().await.pop_front() {
// TODO: Consider replacing this with `unwrap_or_else` when async closures are stablized.
let track = self.tracks.write().await.pop_front();
let track = if let Some(track) = track {
track
} else {
// If the queue is completely empty, then fallback to simply getting a new track.

View File

@ -78,7 +78,10 @@ impl Info {
if skip == formatted.len() {
formatted
} else {
#[allow(clippy::string_slice, /* We've already checked before that the bound is at an ASCII digit. */)]
#[expect(
clippy::string_slice,
reason = "We've already checked before that the bound is at an ASCII digit."
)]
String::from(&formatted[skip..])
}
}

View File

@ -41,11 +41,10 @@ impl List {
let random = rand::thread_rng().gen_range(1..self.lines.len());
let line = self.lines[random].clone();
let split: Vec<&str> = line.split('!').collect();
if split.len() == 1 {
(line, None)
if let Some((first, second)) = line.split_once('!') {
(first.to_owned(), Some(second.to_owned()))
} else {
(split[0].to_owned(), Some(split[1].to_owned()))
(line, None)
}
}
@ -87,7 +86,7 @@ impl List {
}
/// Reads a [List] from the filesystem using the CLI argument provided.
pub async fn load(tracks: &Option<String>) -> eyre::Result<Self> {
pub async fn load(tracks: Option<&String>) -> eyre::Result<Self> {
if let Some(arg) = tracks {
// Check if the track is in ~/.local/share/lowfi, in which case we'll load that.
let name = dirs::data_dir()