Commit 6221eb407a

6221eb407a83c9df6c94530290477698ebacbf4c

parent: 5e1ba1714e

Unsigned

Siriusmart <71584876+Siriusmart@users.noreply.github.com> · 2022-11-12 16:53 UTC

optional features

Layout: unified · split

Cargo.lock +25 −25
@@ -58,9 +58,9 @@ checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba"
58 58
59[[package]] 59[[package]]
60name = "bytemuck" 60name = "bytemuck"
61version = "1.12.2" 61version = "1.12.3"
62source = "registry+https://github.com/rust-lang/crates.io-index" 62source = "registry+https://github.com/rust-lang/crates.io-index"
63checksum = "5aec14f5d4e6e3f927cd0c81f72e5710d95ee9019fbeb4b3021193867491bfd8" 63checksum = "aaa3a8d9a1ca92e282c96a32d6511b695d7d994d1d102ba85d279f9b2756947f"
64 64
65[[package]] 65[[package]]
66name = "byteorder" 66name = "byteorder"
@@ -82,9 +82,9 @@ checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53"
82 82
83[[package]] 83[[package]]
84name = "cc" 84name = "cc"
85version = "1.0.74" 85version = "1.0.76"
86source = "registry+https://github.com/rust-lang/crates.io-index" 86source = "registry+https://github.com/rust-lang/crates.io-index"
87checksum = "581f5dba903aac52ea3feb5ec4810848460ee833876f1f9b0fdeab1f19091574" 87checksum = "76a284da2e6fe2092f2353e51713435363112dfd60030e22add80be333fb928f"
88 88
89[[package]] 89[[package]]
90name = "cfg-if" 90name = "cfg-if"
@@ -94,9 +94,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
94 94
95[[package]] 95[[package]]
96name = "chrono" 96name = "chrono"
97version = "0.4.22" 97version = "0.4.23"
98source = "registry+https://github.com/rust-lang/crates.io-index" 98source = "registry+https://github.com/rust-lang/crates.io-index"
99checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" 99checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f"
100dependencies = [ 100dependencies = [
101 "iana-time-zone", 101 "iana-time-zone",
102 "num-integer", 102 "num-integer",
@@ -235,9 +235,9 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
235 235
236[[package]] 236[[package]]
237name = "cxx" 237name = "cxx"
238version = "1.0.80" 238version = "1.0.81"
239source = "registry+https://github.com/rust-lang/crates.io-index" 239source = "registry+https://github.com/rust-lang/crates.io-index"
240checksum = "6b7d4e43b25d3c994662706a1d4fcfc32aaa6afd287502c111b237093bb23f3a" 240checksum = "97abf9f0eca9e52b7f81b945524e76710e6cb2366aead23b7d4fbf72e281f888"
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.80" 250version = "1.0.81"
251source = "registry+https://github.com/rust-lang/crates.io-index" 251source = "registry+https://github.com/rust-lang/crates.io-index"
252checksum = "84f8829ddc213e2c1368e51a2564c552b65a8cb6a28f31e576270ac81d5e5827" 252checksum = "7cc32cc5fea1d894b77d269ddb9f192110069a8a9c1f1d441195fba90553dea3"
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.80" 265version = "1.0.81"
266source = "registry+https://github.com/rust-lang/crates.io-index" 266source = "registry+https://github.com/rust-lang/crates.io-index"
267checksum = "e72537424b474af1460806647c41d4b6d35d09ef7fe031c5c2fa5766047cc56a" 267checksum = "8ca220e4794c934dc6b1207c3b42856ad4c302f2df1712e9f8d2eec5afaacf1f"
268 268
269[[package]] 269[[package]]
270name = "cxxbridge-macro" 270name = "cxxbridge-macro"
271version = "1.0.80" 271version = "1.0.81"
272source = "registry+https://github.com/rust-lang/crates.io-index" 272source = "registry+https://github.com/rust-lang/crates.io-index"
273checksum = "309e4fb93eed90e1e14bea0da16b209f81813ba9fc7830c20ed151dd7bc0a4d7" 273checksum = "b846f081361125bfc8dc9d3940c84e1fd83ba54bbca7b17cd29483c828be0704"
274dependencies = [ 274dependencies = [
275 "proc-macro2", 275 "proc-macro2",
276 "quote", 276 "quote",
@@ -603,9 +603,9 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
603 603
604[[package]] 604[[package]]
605name = "hyper" 605name = "hyper"
606version = "0.14.22" 606version = "0.14.23"
607source = "registry+https://github.com/rust-lang/crates.io-index" 607source = "registry+https://github.com/rust-lang/crates.io-index"
608checksum = "abfba89e19b959ca163c7752ba59d737c1ceea53a5d31a149c805446fc958064" 608checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c"
609dependencies = [ 609dependencies = [
610 "bytes", 610 "bytes",
611 "futures-channel", 611 "futures-channel",
@@ -674,9 +674,9 @@ dependencies = [
674 674
675[[package]] 675[[package]]
676name = "image" 676name = "image"
677version = "0.24.4" 677version = "0.24.5"
678source = "registry+https://github.com/rust-lang/crates.io-index" 678source = "registry+https://github.com/rust-lang/crates.io-index"
679checksum = "bd8e4fb07cf672b1642304e731ef8a6a4c7891d67bb4fd4f5ce58cd6ed86803c" 679checksum = "69b7ea949b537b0fd0af141fff8c77690f2ce96f4f41f042ccb6c69c6c965945"
680dependencies = [ 680dependencies = [
681 "bytemuck", 681 "bytemuck",
682 "byteorder", 682 "byteorder",
@@ -723,9 +723,9 @@ dependencies = [
723 723
724[[package]] 724[[package]]
725name = "ipnet" 725name = "ipnet"
726version = "2.5.0" 726version = "2.5.1"
727source = "registry+https://github.com/rust-lang/crates.io-index" 727source = "registry+https://github.com/rust-lang/crates.io-index"
728checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" 728checksum = "f88c5561171189e69df9d98bcf18fd5f9558300f7ea7b801eb8a0fd748bd8745"
729 729
730[[package]] 730[[package]]
731name = "itoa" 731name = "itoa"
@@ -735,9 +735,9 @@ checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
735 735
736[[package]] 736[[package]]
737name = "jpeg-decoder" 737name = "jpeg-decoder"
738version = "0.2.6" 738version = "0.3.0"
739source = "registry+https://github.com/rust-lang/crates.io-index" 739source = "registry+https://github.com/rust-lang/crates.io-index"
740checksum = "9478aa10f73e7528198d75109c8be5cd7d15fb530238040148d5f9a22d4c5b3b" 740checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e"
741dependencies = [ 741dependencies = [
742 "rayon", 742 "rayon",
743] 743]
@@ -1407,9 +1407,9 @@ dependencies = [
1407 1407
1408[[package]] 1408[[package]]
1409name = "tiff" 1409name = "tiff"
1410version = "0.7.4" 1410version = "0.8.0"
1411source = "registry+https://github.com/rust-lang/crates.io-index" 1411source = "registry+https://github.com/rust-lang/crates.io-index"
1412checksum = "9f71e422515e83e3ab8a03d4781d05ebf864fc61f4546e6ecffa58cbd34181a0" 1412checksum = "f17def29300a156c19ae30814710d9c63cd50288a49c6fd3a10ccfbe4cf886fd"
1413dependencies = [ 1413dependencies = [
1414 "flate2", 1414 "flate2",
1415 "jpeg-decoder", 1415 "jpeg-decoder",
@@ -1880,7 +1880,7 @@ dependencies = [
1880 1880
1881[[package]] 1881[[package]]
1882name = "youtube-tui" 1882name = "youtube-tui"
1883version = "0.5.0" 1883version = "0.5.1"
1884dependencies = [ 1884dependencies = [
1885 "chrono", 1885 "chrono",
1886 "crossterm", 1886 "crossterm",
Cargo.toml +7 −3
@@ -1,6 +1,6 @@
1[package] 1[package]
2name = "youtube-tui" 2name = "youtube-tui"
3version = "0.5.0" 3version = "0.5.1"
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"
@@ -9,18 +9,22 @@ readme = "README.md"
9homepage = "https://siriusmart.github.io/youtube-tui" 9homepage = "https://siriusmart.github.io/youtube-tui"
10repository = "https://github.com/siriusmart/youtube-tui" 10repository = "https://github.com/siriusmart/youtube-tui"
11license = "GPL-3.0" 11license = "GPL-3.0"
12license-file = "LICENSE"
13keywords = ["cli", "terminal", "youtube", "tui"] 12keywords = ["cli", "terminal", "youtube", "tui"]
14categories =["command-line-interface", "command-line-utilities"] 13categories =["command-line-interface", "command-line-utilities"]
15exclude = ["/docs"] 14exclude = ["/docs"]
16 15
17# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 16# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
18 17
18[features]
19default = ["sixel", "halfblock"]
20sixel = ["viuer/sixel"]
21halfblock = ["viuer"]
22
19[dependencies] 23[dependencies]
20serde = {version = "1.0", default-features = false, features = ["derive"]} 24serde = {version = "1.0", default-features = false, features = ["derive"]}
21tui = {version = "0.19", default-features = false, features = ["serde"]} 25tui = {version = "0.19", default-features = false, features = ["serde"]}
22crossterm = {version = "0.25", default-features = false, features = ["serde"]} 26crossterm = {version = "0.25", default-features = false, features = ["serde"]}
23viuer = {version = "0.6", default-features = false, features = ["sixel"]} 27viuer = {version = "0.6", default-features = false, optional = true}
24home = "0.5" 28home = "0.5"
25chrono = {version = "0.4", default-features = false, features = ["clock"]} 29chrono = {version = "0.4", default-features = false, features = ["clock"]}
26tui-additions = {version = "0.1", default-features = false, features = ["framework", "widgets"]} 30tui-additions = {version = "0.1", default-features = false, features = ["framework", "widgets"]}
docs/src/config/README.md +1 −1
@@ -11,4 +11,4 @@ In the following sections we will go through all config files including:
11- [`keybindings.yml`](./keybindings.md) 11- [`keybindings.yml`](./keybindings.md)
12- [`pages.yml`](./pages.md) 12- [`pages.yml`](./pages.md)
13- [`appearance.yml`](./appearance.md) 13- [`appearance.yml`](./appearance.md)
14- `search.yml` 14- [`search.yml`](./search.md)
docs/src/installation.md +22
@@ -47,3 +47,25 @@ youtube-tui
47``` 47```
48 48
49If installed correctly, a TUI should be launched. Press `q` to close the TUI. 49If installed correctly, a TUI should be launched. Press `q` to close the TUI.
50
51## Features
52
53The TUI has features that can be enabled/disabled when compiling.
54
55```sh
56cargo install youtube-tui # install with all default features
57cargo install youtube-tui --no-default-features # install without any features enabled
58cargo install youtube-tui --no-default-features -F 'halfblock' # install with only HalfBlocks support (but not Sixels)
59cargo install youtube-tui --no-default-features -F 'halfblock' -F 'sixel' # can install with multiple features by doing this
60cargo install youtube-tui --all-features # install with all features (even if not included in default)
61```
62
63### `halfblock` (default)
64
65Display images through HalfBlocks, work best in terminals with TrueColour support (so would not recommend for Windows users).
66
67### `sixel` (default)
68
69Display images with Sixels, allows the display of images at full definition. Not present on windows.
70
71Enabling this will also enable `halfblock`.
src/config/main.rs +2 −2
@@ -56,7 +56,7 @@ impl ConfigTrait for MainConfig {
56} 56}
57 57
58/// how images are handled/displayed 58/// how images are handled/displayed
59#[derive(Clone, Copy, Serialize, Deserialize, PartialEq)] 59#[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
60pub enum Images { 60pub enum Images {
61 r#None, 61 r#None,
62 HalfBlocks, 62 HalfBlocks,
@@ -73,7 +73,7 @@ impl Images {
73 } 73 }
74} 74}
75 75
76#[derive(Clone, Copy, Serialize, Deserialize, PartialEq)] 76#[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
77pub enum Provider { 77pub enum Provider {
78 YouTube, 78 YouTube,
79 Invidious, 79 Invidious,
src/global/functions/date_text.rs +3 −1
@@ -2,6 +2,8 @@ use chrono::{Datelike, NaiveDateTime};
2 2
3/// Convert timestamp into `DD/MM/YYYY` 3/// Convert timestamp into `DD/MM/YYYY`
4pub fn date_text(timestamp: u64) -> String { 4pub fn date_text(timestamp: u64) -> String {
5 let date = NaiveDateTime::from_timestamp(timestamp as i64, 0).date(); 5 let date = NaiveDateTime::from_timestamp_opt(timestamp as i64, 0)
6 .unwrap()
7 .date();
6 format!("{}/{}/{}", date.day(), date.month(), date.year()) 8 format!("{}/{}/{}", date.day(), date.month(), date.year())
7} 9}
src/global/functions/download_all_images.rs +6 −1
@@ -42,10 +42,15 @@ impl From<&Item> for Option<DownloadRequest> {
42 42
43/// Function to download all thumbnails (or just any files) to `~/.cache/thumbnails` with no file exitension (cuz its not needed) 43/// Function to download all thumbnails (or just any files) to `~/.cache/thumbnails` with no file exitension (cuz its not needed)
44pub fn download_all_images(downloads: Vec<Option<DownloadRequest>>) { 44pub fn download_all_images(downloads: Vec<Option<DownloadRequest>>) {
45 // do not download the images if non of the features are enabled
46 if cfg!(not(any(feature = "sixel", feature = "halfblock"))) {
47 return;
48 }
49
45 thread::spawn(move || { 50 thread::spawn(move || {
46 let rt: Runtime = tokio::runtime::Runtime::new().unwrap(); 51 let rt: Runtime = tokio::runtime::Runtime::new().unwrap();
47 52
48 let _ = rt.block_on(download_all_images_async( 53 rt.block_on(download_all_images_async(
49 downloads.into_iter().flatten().collect(), 54 downloads.into_iter().flatten().collect(),
50 )); 55 ));
51 }); 56 });
src/global/structs/page.rs +5 −5
@@ -6,7 +6,7 @@ use typemap::Key;
6 6
7// Page can be converted into PageConfig, which can then be converted into State 7// Page can be converted into PageConfig, which can then be converted into State
8/// Covers all possible pages and variants 8/// Covers all possible pages and variants
9#[derive(Clone, PartialEq)] 9#[derive(Clone, PartialEq, Eq)]
10pub enum Page { 10pub enum Page {
11 MainMenu(MainMenuPage), 11 MainMenu(MainMenuPage),
12 Search(Search), 12 Search(Search),
@@ -49,7 +49,7 @@ impl Key for Page {
49} 49}
50 50
51/// page variants for the main menu 51/// page variants for the main menu
52#[derive(Clone, Copy, PartialEq)] 52#[derive(Clone, Copy, PartialEq, Eq)]
53pub enum MainMenuPage { 53pub enum MainMenuPage {
54 Trending, 54 Trending,
55 Popular, 55 Popular,
@@ -63,13 +63,13 @@ impl Default for MainMenuPage {
63} 63}
64 64
65/// variants of the coannel display page 65/// variants of the coannel display page
66#[derive(Clone, PartialEq)] 66#[derive(Clone, PartialEq, Eq)]
67pub struct ChannelDisplayPage { 67pub struct ChannelDisplayPage {
68 pub id: String, 68 pub id: String,
69 pub r#type: ChannelDisplayPageType, 69 pub r#type: ChannelDisplayPageType,
70} 70}
71 71
72#[derive(Clone, Copy, PartialEq)] 72#[derive(Clone, Copy, PartialEq, Eq)]
73pub enum ChannelDisplayPageType { 73pub enum ChannelDisplayPageType {
74 Main, 74 Main,
75 Videos, 75 Videos,
@@ -77,7 +77,7 @@ pub enum ChannelDisplayPageType {
77} 77}
78 78
79/// Different items to be displayed on a single item page 79/// Different items to be displayed on a single item page
80#[derive(Clone, PartialEq)] 80#[derive(Clone, PartialEq, Eq)]
81pub enum SingleItemPage { 81pub enum SingleItemPage {
82 Video(String), 82 Video(String),
83 Playlist(String), 83 Playlist(String),
src/global/structs/tasks.rs +1 −1
@@ -19,7 +19,7 @@ pub enum Task {
19} 19}
20 20
21/// multiple tasks joined together, with duplicates removed 21/// multiple tasks joined together, with duplicates removed
22#[derive(Clone, PartialEq)] 22#[derive(Clone, PartialEq, Eq)]
23pub struct TaskQueue { 23pub struct TaskQueue {
24 pub render: RenderTask, 24 pub render: RenderTask,
25 pub reload: bool, 25 pub reload: bool,
src/items/iteminfo.rs +35 −26
@@ -4,6 +4,7 @@ use tui::{
4 widgets::{Paragraph, Wrap}, 4 widgets::{Paragraph, Wrap},
5}; 5};
6use tui_additions::framework::FrameworkItem; 6use tui_additions::framework::FrameworkItem;
7#[cfg(any(feature = "sixel", feature = "halfblock"))]
7use viuer::{print_from_file, Config}; 8use viuer::{print_from_file, Config};
8 9
9use crate::{ 10use crate::{
@@ -40,37 +41,45 @@ impl FrameworkItem for ItemInfo {
40 let appearance = framework.data.global.get::<AppearanceConfig>().unwrap(); 41 let appearance = framework.data.global.get::<AppearanceConfig>().unwrap();
41 42
42 // The scroll (space above) text info will be the height of the image, but if the image fail to display, the scroll will be 0 43 // The scroll (space above) text info will be the height of the image, but if the image fail to display, the scroll will be 0
43 let scroll = if main_config.images.display() 44 let scroll = if cfg!(any(feature = "halfblock", feature = "sixel"))
45 && main_config.images.display()
44 && !framework.data.state.get::<Status>().unwrap().popup_opened 46 && !framework.data.state.get::<Status>().unwrap().popup_opened
45 { 47 {
46 let thumbnail_path = home::home_dir() 48 let mut scroll = 0;
47 .unwrap() 49
48 .join(".cache/youtube-tui/thumbnails/") 50 #[cfg(any(feature = "sixel", feature = "halfblock"))]
49 .join(item.thumbnail_id()); 51 {
50 if thumbnail_path.exists() { 52 let thumbnail_path = home::home_dir()
51 let config = Config { 53 .unwrap()
52 // channel thumbnails are squares, limiting their maximum width can prevent the 54 .join(".cache/youtube-tui/thumbnails/")
53 // entire page being taken up by the image 55 .join(item.thumbnail_id());
54 width: Some(if let Item::MiniChannel(_) = item { 56 if thumbnail_path.exists() {
55 area.width / 2 57 #[cfg(any(feature = "sixel", feature = "halfblock"))]
56 } else if let Item::FullChannel(_) = item { 58 let config = Config {
57 area.width / 4 59 // channel thumbnails are squares, limiting their maximum width can prevent the
60 // entire page being taken up by the image
61 width: Some(if let Item::MiniChannel(_) = item {
62 area.width / 2
63 } else if let Item::FullChannel(_) = item {
64 area.width / 4
65 } else {
66 area.width
67 } as u32),
68 x: area.x,
69 y: area.y as i16,
70 #[cfg(feature = "sixel")]
71 use_sixel: main_config.images.use_sixels(),
72 ..Default::default()
73 };
74
75 if let Ok((_, height)) = print_from_file(thumbnail_path, &config) {
76 scroll = height as u16;
58 } else { 77 } else {
59 area.width 78 scroll = 0;
60 } as u32), 79 }
61 x: area.x,
62 y: area.y as i16,
63 use_sixel: main_config.images.use_sixels(),
64 ..Default::default()
65 };
66 if let Ok((_, height)) = print_from_file(thumbnail_path, &config) {
67 height as u16
68 } else {
69 0
70 } 80 }
71 } else {
72 0
73 } 81 }
82 scroll
74 } else { 83 } else {
75 0 84 0
76 }; 85 };
src/items/pagebutton.rs +3 −2
@@ -1,7 +1,7 @@
1use crate::{ 1use crate::{
2 config::AppearanceConfig, 2 config::AppearanceConfig,
3 global::structs::{ 3 global::structs::{
4 ChannelDisplayPage, ChannelDisplayPageType, MainMenuPage, Page, Task, Tasks, Message, 4 ChannelDisplayPage, ChannelDisplayPageType, MainMenuPage, Message, Page, Task, Tasks,
5 }, 5 },
6}; 6};
7use tui::{ 7use tui::{
@@ -97,7 +97,8 @@ impl FrameworkItem for PageButton {
97 let current_page = framework.data.state.get::<Page>().unwrap().clone(); 97 let current_page = framework.data.state.get::<Page>().unwrap().clone();
98 98
99 if self.page(&current_page) == current_page { 99 if self.page(&current_page) == current_page {
100 *framework.data.global.get_mut::<Message>().unwrap() = Message::Message(String::from("You are already on this page")); 100 *framework.data.global.get_mut::<Message>().unwrap() =
101 Message::Message(String::from("You are already on this page"));
101 return false; 102 return false;
102 } 103 }
103 104
src/items/singleitem.rs +5 −7
@@ -370,14 +370,12 @@ impl SingleItem {
370 if iteminfo.selected { 370 if iteminfo.selected {
371 self.grid 371 self.grid
372 .set_border_style(Style::default().fg(appearance.colors.outline_selected)); 372 .set_border_style(Style::default().fg(appearance.colors.outline_selected));
373 } else if iteminfo.hover {
374 self.grid
375 .set_border_style(Style::default().fg(appearance.colors.outline_hover));
373 } else { 376 } else {
374 if iteminfo.hover { 377 self.grid
375 self.grid 378 .set_border_style(Style::default().fg(appearance.colors.outline));
376 .set_border_style(Style::default().fg(appearance.colors.outline_hover));
377 } else {
378 self.grid
379 .set_border_style(Style::default().fg(appearance.colors.outline));
380 }
381 } 379 }
382 380
383 self.r#type 381 self.r#type