Commit 99be1b008d

99be1b008d7a6a55830359d235737a6d08c8a5ab

parent: 73476361e1

Unsigned

Siriusmart <71584876+Siriusmart@users.noreply.github.com> · 2022-12-09 19:46 UTC

mouse click event

Layout: unified · split

Cargo.lock +34 −34
@@ -235,9 +235,9 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
235 235
236[[package]] 236[[package]]
237name = "cxx" 237name = "cxx"
238version = "1.0.82" 238version = "1.0.83"
239source = "registry+https://github.com/rust-lang/crates.io-index" 239source = "registry+https://github.com/rust-lang/crates.io-index"
240checksum = "d4a41a86530d0fe7f5d9ea779916b7cadd2d4f9add748b99c2c029cbbdfaf453" 240checksum = "bdf07d07d6531bfcdbe9b8b739b104610c6508dcc4d63b410585faf338241daf"
241dependencies = [ 241dependencies = [
242 "cc", 242 "cc",
243 "cxxbridge-flags", 243 "cxxbridge-flags",
@@ -247,9 +247,9 @@ dependencies = [
247 247
248[[package]] 248[[package]]
249name = "cxx-build" 249name = "cxx-build"
250version = "1.0.82" 250version = "1.0.83"
251source = "registry+https://github.com/rust-lang/crates.io-index" 251source = "registry+https://github.com/rust-lang/crates.io-index"
252checksum = "06416d667ff3e3ad2df1cd8cd8afae5da26cf9cec4d0825040f88b5ca659a2f0" 252checksum = "d2eb5b96ecdc99f72657332953d4d9c50135af1bac34277801cc3937906ebd39"
253dependencies = [ 253dependencies = [
254 "cc", 254 "cc",
255 "codespan-reporting", 255 "codespan-reporting",
@@ -262,15 +262,15 @@ dependencies = [
262 262
263[[package]] 263[[package]]
264name = "cxxbridge-flags" 264name = "cxxbridge-flags"
265version = "1.0.82" 265version = "1.0.83"
266source = "registry+https://github.com/rust-lang/crates.io-index" 266source = "registry+https://github.com/rust-lang/crates.io-index"
267checksum = "820a9a2af1669deeef27cb271f476ffd196a2c4b6731336011e0ba63e2c7cf71" 267checksum = "ac040a39517fd1674e0f32177648334b0f4074625b5588a64519804ba0553b12"
268 268
269[[package]] 269[[package]]
270name = "cxxbridge-macro" 270name = "cxxbridge-macro"
271version = "1.0.82" 271version = "1.0.83"
272source = "registry+https://github.com/rust-lang/crates.io-index" 272source = "registry+https://github.com/rust-lang/crates.io-index"
273checksum = "a08a6e2fcc370a089ad3b4aaf54db3b1b4cee38ddabce5896b33eb693275f470" 273checksum = "1362b0ddcfc4eb0a1f57b68bd77dd99f0e826958a96abd0ae9bd092e114ffed6"
274dependencies = [ 274dependencies = [
275 "proc-macro2", 275 "proc-macro2",
276 "quote", 276 "quote",
@@ -712,9 +712,9 @@ dependencies = [
712 712
713[[package]] 713[[package]]
714name = "invidious" 714name = "invidious"
715version = "0.4.0" 715version = "0.4.1"
716source = "registry+https://github.com/rust-lang/crates.io-index" 716source = "registry+https://github.com/rust-lang/crates.io-index"
717checksum = "f6a0c87f44203986f9b402ef0409c1c776c5229d09be2a85cda5b53a23ba0757" 717checksum = "d8a4bb13ce198d68343e135c30ccfaee05fc23f3931b29ce0c83e653a275ab9c"
718dependencies = [ 718dependencies = [
719 "reqwest", 719 "reqwest",
720 "serde", 720 "serde",
@@ -723,9 +723,9 @@ dependencies = [
723 723
724[[package]] 724[[package]]
725name = "ipnet" 725name = "ipnet"
726version = "2.5.1" 726version = "2.6.0"
727source = "registry+https://github.com/rust-lang/crates.io-index" 727source = "registry+https://github.com/rust-lang/crates.io-index"
728checksum = "f88c5561171189e69df9d98bcf18fd5f9558300f7ea7b801eb8a0fd748bd8745" 728checksum = "ec947b7a4ce12e3b87e353abae7ce124d025b6c7d6c5aea5cc0bcf92e9510ded"
729 729
730[[package]] 730[[package]]
731name = "itoa" 731name = "itoa"
@@ -765,9 +765,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
765 765
766[[package]] 766[[package]]
767name = "libc" 767name = "libc"
768version = "0.2.137" 768version = "0.2.138"
769source = "registry+https://github.com/rust-lang/crates.io-index" 769source = "registry+https://github.com/rust-lang/crates.io-index"
770checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" 770checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8"
771 771
772[[package]] 772[[package]]
773name = "link-cplusplus" 773name = "link-cplusplus"
@@ -920,9 +920,9 @@ checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
920 920
921[[package]] 921[[package]]
922name = "openssl" 922name = "openssl"
923version = "0.10.43" 923version = "0.10.44"
924source = "registry+https://github.com/rust-lang/crates.io-index" 924source = "registry+https://github.com/rust-lang/crates.io-index"
925checksum = "020433887e44c27ff16365eaa2d380547a94544ad509aff6eb5b6e3e0b27b376" 925checksum = "29d971fd5722fec23977260f6e81aa67d2f22cadbdc2aa049f1022d9a3be1566"
926dependencies = [ 926dependencies = [
927 "bitflags", 927 "bitflags",
928 "cfg-if", 928 "cfg-if",
@@ -952,9 +952,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
952 952
953[[package]] 953[[package]]
954name = "openssl-sys" 954name = "openssl-sys"
955version = "0.9.78" 955version = "0.9.79"
956source = "registry+https://github.com/rust-lang/crates.io-index" 956source = "registry+https://github.com/rust-lang/crates.io-index"
957checksum = "07d5c8cb6e57b3a3612064d7b18b117912b4ce70955c2504d4b741c9e244b132" 957checksum = "5454462c0eced1e97f2ec09036abc8da362e66802f66fd20f86854d9d8cbcbc4"
958dependencies = [ 958dependencies = [
959 "autocfg", 959 "autocfg",
960 "cc", 960 "cc",
@@ -975,9 +975,9 @@ dependencies = [
975 975
976[[package]] 976[[package]]
977name = "parking_lot_core" 977name = "parking_lot_core"
978version = "0.9.4" 978version = "0.9.5"
979source = "registry+https://github.com/rust-lang/crates.io-index" 979source = "registry+https://github.com/rust-lang/crates.io-index"
980checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" 980checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba"
981dependencies = [ 981dependencies = [
982 "cfg-if", 982 "cfg-if",
983 "libc", 983 "libc",
@@ -1206,18 +1206,18 @@ dependencies = [
1206 1206
1207[[package]] 1207[[package]]
1208name = "serde" 1208name = "serde"
1209version = "1.0.148" 1209version = "1.0.149"
1210source = "registry+https://github.com/rust-lang/crates.io-index" 1210source = "registry+https://github.com/rust-lang/crates.io-index"
1211checksum = "e53f64bb4ba0191d6d0676e1b141ca55047d83b74f5607e6d8eb88126c52c2dc" 1211checksum = "256b9932320c590e707b94576e3cc1f7c9024d0ee6612dfbcf1cb106cbe8e055"
1212dependencies = [ 1212dependencies = [
1213 "serde_derive", 1213 "serde_derive",
1214] 1214]
1215 1215
1216[[package]] 1216[[package]]
1217name = "serde_derive" 1217name = "serde_derive"
1218version = "1.0.148" 1218version = "1.0.149"
1219source = "registry+https://github.com/rust-lang/crates.io-index" 1219source = "registry+https://github.com/rust-lang/crates.io-index"
1220checksum = "a55492425aa53521babf6137309e7d34c20bbfbbfcfe2c7f3a047fd1f6b92c0c" 1220checksum = "b4eae9b04cbffdfd550eb462ed33bc6a1b68c935127d008b27444d08380f94e4"
1221dependencies = [ 1221dependencies = [
1222 "proc-macro2", 1222 "proc-macro2",
1223 "quote", 1223 "quote",
@@ -1344,9 +1344,9 @@ dependencies = [
1344 1344
1345[[package]] 1345[[package]]
1346name = "syn" 1346name = "syn"
1347version = "1.0.104" 1347version = "1.0.105"
1348source = "registry+https://github.com/rust-lang/crates.io-index" 1348source = "registry+https://github.com/rust-lang/crates.io-index"
1349checksum = "4ae548ec36cf198c0ef7710d3c230987c2d6d7bd98ad6edc0274462724c585ce" 1349checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908"
1350dependencies = [ 1350dependencies = [
1351 "proc-macro2", 1351 "proc-macro2",
1352 "quote", 1352 "quote",
@@ -1423,9 +1423,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
1423 1423
1424[[package]] 1424[[package]]
1425name = "tokio" 1425name = "tokio"
1426version = "1.22.0" 1426version = "1.23.0"
1427source = "registry+https://github.com/rust-lang/crates.io-index" 1427source = "registry+https://github.com/rust-lang/crates.io-index"
1428checksum = "d76ce4a75fb488c605c54bf610f221cea8b0dafb53333c1a67e8ee199dcd2ae3" 1428checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46"
1429dependencies = [ 1429dependencies = [
1430 "autocfg", 1430 "autocfg",
1431 "bytes", 1431 "bytes",
@@ -1435,7 +1435,7 @@ dependencies = [
1435 "num_cpus", 1435 "num_cpus",
1436 "pin-project-lite", 1436 "pin-project-lite",
1437 "socket2", 1437 "socket2",
1438 "winapi", 1438 "windows-sys 0.42.0",
1439] 1439]
1440 1440
1441[[package]] 1441[[package]]
@@ -1516,9 +1516,9 @@ dependencies = [
1516 1516
1517[[package]] 1517[[package]]
1518name = "tui-additions" 1518name = "tui-additions"
1519version = "0.1.10" 1519version = "0.1.11"
1520source = "registry+https://github.com/rust-lang/crates.io-index" 1520source = "registry+https://github.com/rust-lang/crates.io-index"
1521checksum = "e7b8ddf761287fd6bc7d703bac577a2ad904a8f94ff3a66208cf435c668eae41" 1521checksum = "42473ced74bd112a4c96a03aa03bfdce0d3545a0696164379ac901efe2cd6e73"
1522dependencies = [ 1522dependencies = [
1523 "crossterm", 1523 "crossterm",
1524 "dyn-clone", 1524 "dyn-clone",
@@ -1538,9 +1538,9 @@ dependencies = [
1538 1538
1539[[package]] 1539[[package]]
1540name = "typenum" 1540name = "typenum"
1541version = "1.15.0" 1541version = "1.16.0"
1542source = "registry+https://github.com/rust-lang/crates.io-index" 1542source = "registry+https://github.com/rust-lang/crates.io-index"
1543checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" 1543checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
1544 1544
1545[[package]] 1545[[package]]
1546name = "unicode-bidi" 1546name = "unicode-bidi"
@@ -1870,7 +1870,7 @@ dependencies = [
1870 1870
1871[[package]] 1871[[package]]
1872name = "youtube-tui" 1872name = "youtube-tui"
1873version = "0.5.3" 1873version = "0.6.0"
1874dependencies = [ 1874dependencies = [
1875 "chrono", 1875 "chrono",
1876 "crossterm", 1876 "crossterm",
Cargo.toml +2 −2
@@ -1,6 +1,6 @@
1[package] 1[package]
2name = "youtube-tui" 2name = "youtube-tui"
3version = "0.5.3" 3version = "0.6.0"
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"
@@ -27,8 +27,8 @@ crossterm = {version = "0.25", default-features = false, features = ["serde"]}
27viuer = {version = "0.6", default-features = false, optional = true} 27viuer = {version = "0.6", default-features = false, optional = true}
28home = "0.5" 28home = "0.5"
29chrono = {version = "0.4", default-features = false, features = ["clock"]} 29chrono = {version = "0.4", default-features = false, features = ["clock"]}
30tui-additions = {version = "0.1", default-features = false, features = ["framework", "widgets"]}
31typemap = {version = "0.3", default-features = false} 30typemap = {version = "0.3", default-features = false}
31tui-additions = {version = "0.1", default-features = false, features = ["framework", "widgets"]}
32invidious = {version = "0.4", default-features = false, features = ["reqwest"]} 32invidious = {version = "0.4", default-features = false, features = ["reqwest"]}
33serde_yaml = {version = "0.9", default-features = false} 33serde_yaml = {version = "0.9", default-features = false}
34dyn-clone = {version = "1.0", default-features = false} 34dyn-clone = {version = "1.0", default-features = false}
README.md +4
@@ -14,6 +14,10 @@ Written in Rust, the **YouTube TUI** is a lightweight and user friendly TUI for
14 14
15It is like an *app launcher*, it launches other programs to do the heavy lifting (for example, `mpv` for playing videos). 15It is like an *app launcher*, it launches other programs to do the heavy lifting (for example, `mpv` for playing videos).
16 16
17> ### Mouse support
18>
19> Mouse click support partially implemented, now it works for selecting/deselecting, interacting with buttons and moving the cursor in the search bar.
20
17## Customisable 21## Customisable
18 22
19The YouTube TUI can be customised through config files, they are located in `~/.config/youtube-tui` and are in the YAML format. 23The YouTube TUI can be customised through config files, they are located in `~/.config/youtube-tui` and are in the YAML format.
src/items/searchbar.rs +19
@@ -116,6 +116,25 @@ impl FrameworkItem for SearchBar {
116 Ok(()) 116 Ok(())
117 } 117 }
118 118
119 fn mouse_event(&mut self, _framework: &mut tui_additions::framework::FrameworkClean, mut x: u16, y: u16) -> bool {
120 if y != 1 || x == 0 {
121 return false;
122 }
123
124 x -= 1; // there is 1 character to the left of the text field
125
126 if x == self.text_field.cursor as u16 {
127 return false;
128 }
129
130 if x > self.text_field.content.len() as u16 {
131 return self.text_field.last().is_ok();
132 }
133
134 self.text_field.cursor = x as usize;
135 self.text_field.update().is_ok()
136 }
137
119 fn selectable(&self) -> bool { 138 fn selectable(&self) -> bool {
120 true 139 true
121 } 140 }
src/run.rs +18 −1
@@ -1,4 +1,4 @@
1use crossterm::event::{self, Event}; 1use crossterm::event::{self, Event, MouseEventKind, MouseButton};
2use std::{error::Error, io::Stdout}; 2use std::{error::Error, io::Stdout};
3use tui::{backend::CrosstermBackend, Terminal}; 3use tui::{backend::CrosstermBackend, Terminal};
4use tui_additions::framework::{Framework, FrameworkDirection}; 4use tui_additions::framework::{Framework, FrameworkDirection};
@@ -23,6 +23,23 @@ pub fn run(
23 *framework.data.global.get_mut::<Message>().unwrap() = Message::None; 23 *framework.data.global.get_mut::<Message>().unwrap() = Message::None;
24 24
25 match event::read()? { 25 match event::read()? {
26 Event::Mouse(mouse) => {
27 if mouse.kind != MouseEventKind::Down(MouseButton::Left) {
28 continue;
29 }
30
31 let updated = framework.mouse_event(mouse.column, mouse.row);
32
33 if updated {
34 framework
35 .data
36 .state
37 .get_mut::<Tasks>()
38 .unwrap()
39 .priority
40 .push(Task::RenderAll);
41 }
42 },
26 Event::Key(key) => { 43 Event::Key(key) => {
27 // 1. get the corresponding action 44 // 1. get the corresponding action
28 // 2. check if action is deselect, if yes, deselect 45 // 2. check if action is deselect, if yes, deselect