Commit 6139b99714

6139b99714a0163d01767d926079ea8c97945ade

parent: 2fc2d5a43f

Unsigned

Siriusmart <sirius@siri.ws> · 2026-03-17 18:17 UTC

mouse seeking in playbar

Layout: unified · split

Cargo.lock +3 −3
@@ -2910,9 +2910,9 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
29102910
29112911[[package]]
29122912name = "tui-additions"
2913version = "0.4.2"
2913version = "0.4.3"
29142914source = "registry+https://github.com/rust-lang/crates.io-index"
2915checksum = "19d7f5cf6ff05ab129ebc8a639539f6b814aee7b48bc3f2fe97f5845a15c3a52"
2915checksum = "cb7da617eccd7f01eb192094c864ecae2f006f2c5ad811c6d1407d91da8c0f20"
29162916dependencies = [
29172917 "crossterm 0.29.0",
29182918 "dyn-clone",
@@ -3506,7 +3506,7 @@ dependencies = [
35063506
35073507[[package]]
35083508name = "youtube-tui"
3509version = "0.9.3"
3509version = "0.9.4"
35103510dependencies = [
35113511 "chrono",
35123512 "clipboard",
Cargo.toml +3 −3
@@ -1,6 +1,6 @@
11[package]
22name = "youtube-tui"
3version = "0.9.3"
3version = "0.9.4"
44authors = ["Siriusmart <siriusmart@tuta.io>"]
55edition = "2021"
66description = "An aesthetically pleasing YouTube TUI written in Rust"
@@ -31,7 +31,7 @@ viuer = {version = "0.9", default-features = false, optional = true, features =
3131home = "0.5"
3232chrono = {version = "0.4", default-features = false, features = ["clock"]}
3333typemap = {version = "0.3", default-features = false}
34tui-additions = {version = "0.4", default-features = false, features = ["framework", "widgets"]}
34tui-additions = {version = "0.4.3", default-features = false, features = ["framework", "widgets"]}
3535invidious = { version = "0.7", default-features = false, optional = true }
3636serde_yaml_ng = {version = "0.10", default-features = false}
3737dyn-clone = {version = "1.0", default-features = false}
@@ -48,7 +48,7 @@ tokio = { version = "1", features = [ "rt" ]}
4848http_req = "0.14.1"
4949
5050# libmpv = { path = "libmpv-rs", optional = true, version = "2" }
51# tui-additions = {path = "../Rust/tui-additions", default-features = false, features = ["framework", "widgets"]}
51# tui-additions = {path = "../tui-additions", default-features = false, features = ["framework", "widgets"]}
5252# invidious = {path = "../Rust/invidious-rs"}
5353
5454[package.metadata.docs.rs]
docs/src/changelogs.md +6 −2
@@ -1,12 +1,16 @@
11# Changelogs
22
3### v0.9.3 (Latest)
3### v0.9.4 (latest)
4#### Added
5- Mouse seeking in embedded player ([as suggested by seanaye](https://github.com/Siriusmart/youtube-tui/issues/144))
6
7### v0.9.3
48
59#### Fixed
610- Album playlists doesn't load
711- Re-implemented invidious support alongside rustypipe.
812
9### v0.9.2 (Latest)
13### v0.9.2
1014
1115#### Fixed
1216- [#111](https://github.com/Siriusmart/youtube-tui/issues/111) don't know how did that line got there.
src/items/messagebar.rs +71 −2
@@ -9,8 +9,23 @@ use ratatui::{
99use tui_additions::framework::*;
1010
1111/// a message bar item, contains no fields because the message is taken from `data.global.Message`
12#[derive(Clone, Copy, Default)]
13pub struct MessageBar;
12#[derive(Clone, Copy)]
13pub enum MessageBar {
14 Stateless,
15 /// start and end position of the seeker for mouse scrubbing
16 Music {
17 seeker_front: u16,
18 seeker_rear: u16,
19 },
20 /// bar too short for seeker to display
21 MusicSeekerLess,
22}
23
24impl Default for MessageBar {
25 fn default() -> Self {
26 Self::Stateless
27 }
28}
1429
1530impl FrameworkItem for MessageBar {
1631 fn render(
@@ -30,6 +45,7 @@ impl FrameworkItem for MessageBar {
3045 let mpv = framework.data.global.get::<MpvWrapper>().unwrap();
3146 if Self::is_mpv_render(framework) {
3247 let mut label = mpv.property("media-title".to_string()).unwrap();
48
3349 if let Some((name, ext)) = label.rsplit_once('.') {
3450 if ext.len() < 5
3551 && !name.len() > 13
@@ -42,6 +58,7 @@ impl FrameworkItem for MessageBar {
4258 label = name[0..name.len() - 13].to_string();
4359 }
4460 }
61
4562 let duration = mpv
4663 .property("duration".to_string())
4764 .unwrap_or_default()
@@ -76,6 +93,15 @@ impl FrameworkItem for MessageBar {
7693 let seeker_pad = if seeker_len > 10 { seeker_len / 10 } else { 0 };
7794 seeker_len -= seeker_pad * 2;
7895 let seeker_pos = (seeker_len - 1) * playerhead as usize / duration as usize;
96
97 let seeker_front = left_chunk.len() + 1 + seeker_pad; // index of first
98 // character in seeker
99 let seeker_rear = seeker_front + seeker_len - 1; // index of last character
100 // in seeker
101 *self = MessageBar::Music {
102 seeker_front: seeker_front as u16,
103 seeker_rear: seeker_rear as u16,
104 };
79105 format!(
80106 "{left_chunk} {}├{}-{}┤{} {right_chunk}",
81107 " ".repeat(seeker_pad),
@@ -84,13 +110,16 @@ impl FrameworkItem for MessageBar {
84110 " ".repeat(seeker_pad)
85111 )
86112 } else if length > total_len + 3 {
113 *self = MessageBar::MusicSeekerLess;
87114 format!(
88115 "{left_chunk}{}{right_chunk}",
89116 " ".repeat(length - total_len)
90117 )
91118 } else if length > 19 {
119 *self = MessageBar::MusicSeekerLess;
92120 left_chunk
93121 } else {
122 *self = MessageBar::MusicSeekerLess;
94123 String::from("Not enough width")
95124 });
96125 }
@@ -156,6 +185,46 @@ impl FrameworkItem for MessageBar {
156185 fn selectable(&self) -> bool {
157186 false
158187 }
188
189 #[cfg(feature = "mpv")]
190 fn mouse_passthrough(
191 &mut self,
192 framework: &mut FrameworkClean,
193 _selected: bool,
194 x: u16,
195 _y: u16,
196 _absolute_x: u16,
197 _absolute_y: u16,
198 ) -> bool {
199 match self {
200 Self::Music {
201 seeker_front,
202 seeker_rear,
203 } => {
204 use std::sync::mpsc;
205
206 let seek_percentage =
207 (x as i32 - *seeker_front as i32) * 100 / (*seeker_rear - *seeker_front) as i32;
208 let mpv = framework.data.global.get::<MpvWrapper>().unwrap();
209 let (tx, rx) = mpsc::channel();
210 mpv.sender
211 .send(MpvAction::Command {
212 name: "seek".to_string(),
213 args: vec![
214 seek_percentage.clamp(0, 100).to_string(),
215 "absolute-percent".to_string(),
216 ],
217 responder: tx,
218 })
219 .unwrap();
220 if let MpvResponse::Error(e) = rx.recv().unwrap() {
221 *framework.data.global.get_mut::<Message>().unwrap() = Message::Error(e);
222 }
223 true
224 }
225 _ => false,
226 }
227 }
159228}
160229
161230#[cfg(feature = "mpv")]