diff options
| author | salmonik <raisersoft@proton.me> | 2026-05-08 01:20:43 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-05-08 01:20:43 +0200 |
| commit | 5c3110c7843773e617c224e16f150b25884d3fb6 (patch) | |
| tree | 883b436437ee8c81794a261b242f750e286d8c82 /src | |
| parent | Fix shuffle first song not being shuffled (diff) | |
| download | rsplayer-5c3110c7843773e617c224e16f150b25884d3fb6.tar.gz rsplayer-5c3110c7843773e617c224e16f150b25884d3fb6.zip | |
Pad queue display numbers with leading zeros
display_string now takes a total parameter to compute the
zero-padding width. Queue positions are formatted as 01, 02, ..., 10
instead of 1, 2, ..., 10, keeping columns aligned.
Diffstat (limited to '')
| -rw-r--r-- | src/daemon.rs | 4 | ||||
| -rw-r--r-- | src/queue.rs | 7 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/daemon.rs b/src/daemon.rs index 00bf35f..e88669a 100644 --- a/src/daemon.rs +++ b/src/daemon.rs | |||
| @@ -254,7 +254,7 @@ fn process_command( | |||
| 254 | if audio.is_playing() { | 254 | if audio.is_playing() { |
| 255 | if let Some(track_path) = audio.current_track() { | 255 | if let Some(track_path) = audio.current_track() { |
| 256 | let track = Track::from_path(track_path); | 256 | let track = Track::from_path(track_path); |
| 257 | let track_str = track.display_string(0); | 257 | let track_str = track.display_string(0, 1); |
| 258 | format!("Playing\nTrack: {}\n", track_str) | 258 | format!("Playing\nTrack: {}\n", track_str) |
| 259 | } else { | 259 | } else { |
| 260 | "Playing\n".to_string() | 260 | "Playing\n".to_string() |
| @@ -511,7 +511,7 @@ fn process_command( | |||
| 511 | let is_playing = audio.is_playing(); | 511 | let is_playing = audio.is_playing(); |
| 512 | for (display_idx, &track_idx) in indices.iter().enumerate() { | 512 | for (display_idx, &track_idx) in indices.iter().enumerate() { |
| 513 | if let Some(track) = q.track_at(track_idx) { | 513 | if let Some(track) = q.track_at(track_idx) { |
| 514 | let track_str = track.display_string(display_idx); | 514 | let track_str = track.display_string(display_idx, q.len()); |
| 515 | if track_idx == playing_track_idx && is_playing { | 515 | if track_idx == playing_track_idx && is_playing { |
| 516 | output.push_str(&format!("> {} (playing)\n", track_str)); | 516 | output.push_str(&format!("> {} (playing)\n", track_str)); |
| 517 | } else { | 517 | } else { |
diff --git a/src/queue.rs b/src/queue.rs index dca8e3d..9e8e1af 100644 --- a/src/queue.rs +++ b/src/queue.rs | |||
| @@ -96,7 +96,7 @@ impl Track { | |||
| 96 | } | 96 | } |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | pub fn display_string(&self, index: usize) -> String { | 99 | pub fn display_string(&self, index: usize, total: usize) -> String { |
| 100 | let album_artist = self | 100 | let album_artist = self |
| 101 | .artist | 101 | .artist |
| 102 | .clone() | 102 | .clone() |
| @@ -109,11 +109,12 @@ impl Track { | |||
| 109 | .unwrap_or("Unknown") | 109 | .unwrap_or("Unknown") |
| 110 | .to_string() | 110 | .to_string() |
| 111 | }); | 111 | }); |
| 112 | let width = total.to_string().len(); | ||
| 112 | 113 | ||
| 113 | if album_artist.is_empty() { | 114 | if album_artist.is_empty() { |
| 114 | format!("{}. {}", index + 1, title) | 115 | format!("{:0width$}. {}", index + 1, title) |
| 115 | } else { | 116 | } else { |
| 116 | format!("{}. {} - {}", index + 1, album_artist, title) | 117 | format!("{:0width$}. {} - {}", index + 1, album_artist, title) |
| 117 | } | 118 | } |
| 118 | } | 119 | } |
| 119 | } | 120 | } |
