diff --git a/Cargo.lock b/Cargo.lock index 9ad08f6..2554dd5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1471,6 +1471,7 @@ dependencies = [ "rodio", "scraper", "tokio", + "unicode-segmentation", "unicode-width 0.2.0", "url", ] @@ -2778,6 +2779,12 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" + [[package]] name = "unicode-width" version = "0.1.14" diff --git a/Cargo.toml b/Cargo.toml index feaf6b3..83727cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,3 +51,4 @@ lazy_static = "1.5.0" libc = "0.2.167" url = "2.5.4" unicode-width = "0.2.0" +unicode-segmentation = "1.12.0" diff --git a/src/player/ui/components.rs b/src/player/ui/components.rs index ecfb77a..ad00965 100644 --- a/src/player/ui/components.rs +++ b/src/player/ui/components.rs @@ -4,6 +4,7 @@ use std::{ops::Deref, sync::Arc, time::Duration}; use crossterm::style::Stylize; +use unicode_segmentation::UnicodeSegmentation; use crate::{player::Player, tracks::Info}; @@ -100,10 +101,10 @@ pub fn action(player: &Player, current: Option<&Arc>, width: usize) -> Str }) .format(); - // TODO: Deal with dangerous string slicing. - #[allow(clippy::string_slice)] if len > width { - format!("{}...", &main[..=width]) + let chopped: String = main.graphemes(true).take(width + 1).collect(); + + format!("{}...", chopped) } else { format!("{}{}", main, " ".repeat(width - len)) }