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"
2910 2910
2911[[package]] 2911[[package]]
2912name = "tui-additions" 2912name = "tui-additions"
2913version = "0.4.2" 2913version = "0.4.3"
2914source = "registry+https://github.com/rust-lang/crates.io-index" 2914source = "registry+https://github.com/rust-lang/crates.io-index"
2915checksum = "19d7f5cf6ff05ab129ebc8a639539f6b814aee7b48bc3f2fe97f5845a15c3a52" 2915checksum = "cb7da617eccd7f01eb192094c864ecae2f006f2c5ad811c6d1407d91da8c0f20"
2916dependencies = [ 2916dependencies = [
2917 "crossterm 0.29.0", 2917 "crossterm 0.29.0",
2918 "dyn-clone", 2918 "dyn-clone",
@@ -3506,7 +3506,7 @@ dependencies = [
3506 3506
3507[[package]] 3507[[package]]
3508name = "youtube-tui" 3508name = "youtube-tui"
3509version = "0.9.3" 3509version = "0.9.4"
3510dependencies = [ 3510dependencies = [
3511 "chrono", 3511 "chrono",
3512 "clipboard", 3512 "clipboard",
Cargo.toml +3 −3
@@ -1,6 +1,6 @@
1[package] 1[package]
2name = "youtube-tui" 2name = "youtube-tui"
3version = "0.9.3" 3version = "0.9.4"
4authors = ["Siriusmart <siriusmart@tuta.io>"] 4authors = ["Siriusmart <siriusmart@tuta.io>"]
5edition = "2021" 5edition = "2021"
6description = "An aesthetically pleasing YouTube TUI written in Rust" 6description = "An aesthetically pleasing YouTube TUI written in Rust"
@@ -31,7 +31,7 @@ viuer = {version = "0.9", default-features = false, optional = true, features =
31home = "0.5" 31home = "0.5"
32chrono = {version = "0.4", default-features = false, features = ["clock"]} 32chrono = {version = "0.4", default-features = false, features = ["clock"]}
33typemap = {version = "0.3", default-features = false} 33typemap = {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"]}
35invidious = { version = "0.7", default-features = false, optional = true } 35invidious = { version = "0.7", default-features = false, optional = true }
36serde_yaml_ng = {version = "0.10", default-features = false} 36serde_yaml_ng = {version = "0.10", default-features = false}
37dyn-clone = {version = "1.0", default-features = false} 37dyn-clone = {version = "1.0", default-features = false}
@@ -48,7 +48,7 @@ tokio = { version = "1", features = [ "rt" ]}
48http_req = "0.14.1" 48http_req = "0.14.1"
49 49
50# libmpv = { path = "libmpv-rs", optional = true, version = "2" } 50# 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"]}
52# invidious = {path = "../Rust/invidious-rs"} 52# invidious = {path = "../Rust/invidious-rs"}
53 53
54[package.metadata.docs.rs] 54[package.metadata.docs.rs]
docs/src/changelogs.md +6 −2
@@ -1,12 +1,16 @@
1# Changelogs 1# Changelogs
2 2
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
4 8
5#### Fixed 9#### Fixed
6- Album playlists doesn't load 10- Album playlists doesn't load
7- Re-implemented invidious support alongside rustypipe. 11- Re-implemented invidious support alongside rustypipe.
8 12
9### v0.9.2 (Latest) 13### v0.9.2
10 14
11#### Fixed 15#### Fixed
12- [#111](https://github.com/Siriusmart/youtube-tui/issues/111) don't know how did that line got there. 16- [#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::{
9use tui_additions::framework::*; 9use tui_additions::framework::*;
10 10
11/// a message bar item, contains no fields because the message is taken from `data.global.Message` 11/// a message bar item, contains no fields because the message is taken from `data.global.Message`
12#[derive(Clone, Copy, Default)] 12#[derive(Clone, Copy)]
13pub struct MessageBar; 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}
14 29
15impl FrameworkItem for MessageBar { 30impl FrameworkItem for MessageBar {
16 fn render( 31 fn render(
@@ -30,6 +45,7 @@ impl FrameworkItem for MessageBar {
30 let mpv = framework.data.global.get::<MpvWrapper>().unwrap(); 45 let mpv = framework.data.global.get::<MpvWrapper>().unwrap();
31 if Self::is_mpv_render(framework) { 46 if Self::is_mpv_render(framework) {
32 let mut label = mpv.property("media-title".to_string()).unwrap(); 47 let mut label = mpv.property("media-title".to_string()).unwrap();
48
33 if let Some((name, ext)) = label.rsplit_once('.') { 49 if let Some((name, ext)) = label.rsplit_once('.') {
34 if ext.len() < 5 50 if ext.len() < 5
35 && !name.len() > 13 51 && !name.len() > 13
@@ -42,6 +58,7 @@ impl FrameworkItem for MessageBar {
42 label = name[0..name.len() - 13].to_string(); 58 label = name[0..name.len() - 13].to_string();
43 } 59 }
44 } 60 }
61
45 let duration = mpv 62 let duration = mpv
46 .property("duration".to_string()) 63 .property("duration".to_string())
47 .unwrap_or_default() 64 .unwrap_or_default()
@@ -76,6 +93,15 @@ impl FrameworkItem for MessageBar {
76 let seeker_pad = if seeker_len > 10 { seeker_len / 10 } else { 0 }; 93 let seeker_pad = if seeker_len > 10 { seeker_len / 10 } else { 0 };
77 seeker_len -= seeker_pad * 2; 94 seeker_len -= seeker_pad * 2;
78 let seeker_pos = (seeker_len - 1) * playerhead as usize / duration as usize; 95 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 };
79 format!( 105 format!(
80 "{left_chunk} {}├{}-{}┤{} {right_chunk}", 106 "{left_chunk} {}├{}-{}┤{} {right_chunk}",
81 " ".repeat(seeker_pad), 107 " ".repeat(seeker_pad),
@@ -84,13 +110,16 @@ impl FrameworkItem for MessageBar {
84 " ".repeat(seeker_pad) 110 " ".repeat(seeker_pad)
85 ) 111 )
86 } else if length > total_len + 3 { 112 } else if length > total_len + 3 {
113 *self = MessageBar::MusicSeekerLess;
87 format!( 114 format!(
88 "{left_chunk}{}{right_chunk}", 115 "{left_chunk}{}{right_chunk}",
89 " ".repeat(length - total_len) 116 " ".repeat(length - total_len)
90 ) 117 )
91 } else if length > 19 { 118 } else if length > 19 {
119 *self = MessageBar::MusicSeekerLess;
92 left_chunk 120 left_chunk
93 } else { 121 } else {
122 *self = MessageBar::MusicSeekerLess;
94 String::from("Not enough width") 123 String::from("Not enough width")
95 }); 124 });
96 } 125 }
@@ -156,6 +185,46 @@ impl FrameworkItem for MessageBar {
156 fn selectable(&self) -> bool { 185 fn selectable(&self) -> bool {
157 false 186 false
158 } 187 }
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 }
159} 228}
160 229
161#[cfg(feature = "mpv")] 230#[cfg(feature = "mpv")]