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"
5858
5959[[package]]
6060name = "bytemuck"
61version = "1.12.2"
61version = "1.12.3"
6262source = "registry+https://github.com/rust-lang/crates.io-index"
63checksum = "5aec14f5d4e6e3f927cd0c81f72e5710d95ee9019fbeb4b3021193867491bfd8"
63checksum = "aaa3a8d9a1ca92e282c96a32d6511b695d7d994d1d102ba85d279f9b2756947f"
6464
6565[[package]]
6666name = "byteorder"
@@ -82,9 +82,9 @@ checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53"
8282
8383[[package]]
8484name = "cc"
85version = "1.0.74"
85version = "1.0.76"
8686source = "registry+https://github.com/rust-lang/crates.io-index"
87checksum = "581f5dba903aac52ea3feb5ec4810848460ee833876f1f9b0fdeab1f19091574"
87checksum = "76a284da2e6fe2092f2353e51713435363112dfd60030e22add80be333fb928f"
8888
8989[[package]]
9090name = "cfg-if"
@@ -94,9 +94,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
9494
9595[[package]]
9696name = "chrono"
97version = "0.4.22"
97version = "0.4.23"
9898source = "registry+https://github.com/rust-lang/crates.io-index"
99checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1"
99checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f"
100100dependencies = [
101101 "iana-time-zone",
102102 "num-integer",
@@ -235,9 +235,9 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
235235
236236[[package]]
237237name = "cxx"
238version = "1.0.80"
238version = "1.0.81"
239239source = "registry+https://github.com/rust-lang/crates.io-index"
240checksum = "6b7d4e43b25d3c994662706a1d4fcfc32aaa6afd287502c111b237093bb23f3a"
240checksum = "97abf9f0eca9e52b7f81b945524e76710e6cb2366aead23b7d4fbf72e281f888"
241241dependencies = [
242242 "cc",
243243 "cxxbridge-flags",
@@ -247,9 +247,9 @@ dependencies = [
247247
248248[[package]]
249249name = "cxx-build"
250version = "1.0.80"
250version = "1.0.81"
251251source = "registry+https://github.com/rust-lang/crates.io-index"
252checksum = "84f8829ddc213e2c1368e51a2564c552b65a8cb6a28f31e576270ac81d5e5827"
252checksum = "7cc32cc5fea1d894b77d269ddb9f192110069a8a9c1f1d441195fba90553dea3"
253253dependencies = [
254254 "cc",
255255 "codespan-reporting",
@@ -262,15 +262,15 @@ dependencies = [
262262
263263[[package]]
264264name = "cxxbridge-flags"
265version = "1.0.80"
265version = "1.0.81"
266266source = "registry+https://github.com/rust-lang/crates.io-index"
267checksum = "e72537424b474af1460806647c41d4b6d35d09ef7fe031c5c2fa5766047cc56a"
267checksum = "8ca220e4794c934dc6b1207c3b42856ad4c302f2df1712e9f8d2eec5afaacf1f"
268268
269269[[package]]
270270name = "cxxbridge-macro"
271version = "1.0.80"
271version = "1.0.81"
272272source = "registry+https://github.com/rust-lang/crates.io-index"
273checksum = "309e4fb93eed90e1e14bea0da16b209f81813ba9fc7830c20ed151dd7bc0a4d7"
273checksum = "b846f081361125bfc8dc9d3940c84e1fd83ba54bbca7b17cd29483c828be0704"
274274dependencies = [
275275 "proc-macro2",
276276 "quote",
@@ -603,9 +603,9 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
603603
604604[[package]]
605605name = "hyper"
606version = "0.14.22"
606version = "0.14.23"
607607source = "registry+https://github.com/rust-lang/crates.io-index"
608checksum = "abfba89e19b959ca163c7752ba59d737c1ceea53a5d31a149c805446fc958064"
608checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c"
609609dependencies = [
610610 "bytes",
611611 "futures-channel",
@@ -674,9 +674,9 @@ dependencies = [
674674
675675[[package]]
676676name = "image"
677version = "0.24.4"
677version = "0.24.5"
678678source = "registry+https://github.com/rust-lang/crates.io-index"
679checksum = "bd8e4fb07cf672b1642304e731ef8a6a4c7891d67bb4fd4f5ce58cd6ed86803c"
679checksum = "69b7ea949b537b0fd0af141fff8c77690f2ce96f4f41f042ccb6c69c6c965945"
680680dependencies = [
681681 "bytemuck",
682682 "byteorder",
@@ -723,9 +723,9 @@ dependencies = [
723723
724724[[package]]
725725name = "ipnet"
726version = "2.5.0"
726version = "2.5.1"
727727source = "registry+https://github.com/rust-lang/crates.io-index"
728checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b"
728checksum = "f88c5561171189e69df9d98bcf18fd5f9558300f7ea7b801eb8a0fd748bd8745"
729729
730730[[package]]
731731name = "itoa"
@@ -735,9 +735,9 @@ checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
735735
736736[[package]]
737737name = "jpeg-decoder"
738version = "0.2.6"
738version = "0.3.0"
739739source = "registry+https://github.com/rust-lang/crates.io-index"
740checksum = "9478aa10f73e7528198d75109c8be5cd7d15fb530238040148d5f9a22d4c5b3b"
740checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e"
741741dependencies = [
742742 "rayon",
743743]
@@ -1407,9 +1407,9 @@ dependencies = [
14071407
14081408[[package]]
14091409name = "tiff"
1410version = "0.7.4"
1410version = "0.8.0"
14111411source = "registry+https://github.com/rust-lang/crates.io-index"
1412checksum = "9f71e422515e83e3ab8a03d4781d05ebf864fc61f4546e6ecffa58cbd34181a0"
1412checksum = "f17def29300a156c19ae30814710d9c63cd50288a49c6fd3a10ccfbe4cf886fd"
14131413dependencies = [
14141414 "flate2",
14151415 "jpeg-decoder",
@@ -1880,7 +1880,7 @@ dependencies = [
18801880
18811881[[package]]
18821882name = "youtube-tui"
1883version = "0.5.0"
1883version = "0.5.1"
18841884dependencies = [
18851885 "chrono",
18861886 "crossterm",
Cargo.toml +7 −3
@@ -1,6 +1,6 @@
11[package]
22name = "youtube-tui"
3version = "0.5.0"
3version = "0.5.1"
44authors = ["Siriusmart <siriusmart@tuta.io>"]
55edition = "2021"
66description = "An aesthetically pleasing YouTube TUI written in Rust"
@@ -9,18 +9,22 @@ readme = "README.md"
99homepage = "https://siriusmart.github.io/youtube-tui"
1010repository = "https://github.com/siriusmart/youtube-tui"
1111license = "GPL-3.0"
12license-file = "LICENSE"
1312keywords = ["cli", "terminal", "youtube", "tui"]
1413categories =["command-line-interface", "command-line-utilities"]
1514exclude = ["/docs"]
1615
1716# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1817
18[features]
19default = ["sixel", "halfblock"]
20sixel = ["viuer/sixel"]
21halfblock = ["viuer"]
22
1923[dependencies]
2024serde = {version = "1.0", default-features = false, features = ["derive"]}
2125tui = {version = "0.19", default-features = false, features = ["serde"]}
2226crossterm = {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}
2428home = "0.5"
2529chrono = {version = "0.4", default-features = false, features = ["clock"]}
2630tui-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:
1111- [`keybindings.yml`](./keybindings.md)
1212- [`pages.yml`](./pages.md)
1313- [`appearance.yml`](./appearance.md)
14- `search.yml`
14- [`search.yml`](./search.md)
docs/src/installation.md +22
@@ -47,3 +47,25 @@ youtube-tui
4747```
4848
4949If 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 {
5656}
5757
5858/// how images are handled/displayed
59#[derive(Clone, Copy, Serialize, Deserialize, PartialEq)]
59#[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
6060pub enum Images {
6161 r#None,
6262 HalfBlocks,
@@ -73,7 +73,7 @@ impl Images {
7373 }
7474}
7575
76#[derive(Clone, Copy, Serialize, Deserialize, PartialEq)]
76#[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
7777pub enum Provider {
7878 YouTube,
7979 Invidious,
src/global/functions/date_text.rs +3 −1
@@ -2,6 +2,8 @@ use chrono::{Datelike, NaiveDateTime};
22
33/// Convert timestamp into `DD/MM/YYYY`
44pub 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();
68 format!("{}/{}/{}", date.day(), date.month(), date.year())
79}
src/global/functions/download_all_images.rs +6 −1
@@ -42,10 +42,15 @@ impl From<&Item> for Option<DownloadRequest> {
4242
4343/// Function to download all thumbnails (or just any files) to `~/.cache/thumbnails` with no file exitension (cuz its not needed)
4444pub 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
4550 thread::spawn(move || {
4651 let rt: Runtime = tokio::runtime::Runtime::new().unwrap();
4752
48 let _ = rt.block_on(download_all_images_async(
53 rt.block_on(download_all_images_async(
4954 downloads.into_iter().flatten().collect(),
5055 ));
5156 });
src/global/structs/page.rs +5 −5
@@ -6,7 +6,7 @@ use typemap::Key;
66
77// Page can be converted into PageConfig, which can then be converted into State
88/// Covers all possible pages and variants
9#[derive(Clone, PartialEq)]
9#[derive(Clone, PartialEq, Eq)]
1010pub enum Page {
1111 MainMenu(MainMenuPage),
1212 Search(Search),
@@ -49,7 +49,7 @@ impl Key for Page {
4949}
5050
5151/// page variants for the main menu
52#[derive(Clone, Copy, PartialEq)]
52#[derive(Clone, Copy, PartialEq, Eq)]
5353pub enum MainMenuPage {
5454 Trending,
5555 Popular,
@@ -63,13 +63,13 @@ impl Default for MainMenuPage {
6363}
6464
6565/// variants of the coannel display page
66#[derive(Clone, PartialEq)]
66#[derive(Clone, PartialEq, Eq)]
6767pub struct ChannelDisplayPage {
6868 pub id: String,
6969 pub r#type: ChannelDisplayPageType,
7070}
7171
72#[derive(Clone, Copy, PartialEq)]
72#[derive(Clone, Copy, PartialEq, Eq)]
7373pub enum ChannelDisplayPageType {
7474 Main,
7575 Videos,
@@ -77,7 +77,7 @@ pub enum ChannelDisplayPageType {
7777}
7878
7979/// Different items to be displayed on a single item page
80#[derive(Clone, PartialEq)]
80#[derive(Clone, PartialEq, Eq)]
8181pub enum SingleItemPage {
8282 Video(String),
8383 Playlist(String),
src/global/structs/tasks.rs +1 −1
@@ -19,7 +19,7 @@ pub enum Task {
1919}
2020
2121/// multiple tasks joined together, with duplicates removed
22#[derive(Clone, PartialEq)]
22#[derive(Clone, PartialEq, Eq)]
2323pub struct TaskQueue {
2424 pub render: RenderTask,
2525 pub reload: bool,
src/items/iteminfo.rs +35 −26
@@ -4,6 +4,7 @@ use tui::{
44 widgets::{Paragraph, Wrap},
55};
66use tui_additions::framework::FrameworkItem;
7#[cfg(any(feature = "sixel", feature = "halfblock"))]
78use viuer::{print_from_file, Config};
89
910use crate::{
@@ -40,37 +41,45 @@ impl FrameworkItem for ItemInfo {
4041 let appearance = framework.data.global.get::<AppearanceConfig>().unwrap();
4142
4243 // 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()
4446 && !framework.data.state.get::<Status>().unwrap().popup_opened
4547 {
46 let thumbnail_path = home::home_dir()
47 .unwrap()
48 .join(".cache/youtube-tui/thumbnails/")
49 .join(item.thumbnail_id());
50 if thumbnail_path.exists() {
51 let config = Config {
52 // channel thumbnails are squares, limiting their maximum width can prevent the
53 // entire page being taken up by the image
54 width: Some(if let Item::MiniChannel(_) = item {
55 area.width / 2
56 } else if let Item::FullChannel(_) = item {
57 area.width / 4
48 let mut scroll = 0;
49
50 #[cfg(any(feature = "sixel", feature = "halfblock"))]
51 {
52 let thumbnail_path = home::home_dir()
53 .unwrap()
54 .join(".cache/youtube-tui/thumbnails/")
55 .join(item.thumbnail_id());
56 if thumbnail_path.exists() {
57 #[cfg(any(feature = "sixel", feature = "halfblock"))]
58 let config = Config {
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;
5877 } else {
59 area.width
60 } as u32),
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
78 scroll = 0;
79 }
7080 }
71 } else {
72 0
7381 }
82 scroll
7483 } else {
7584 0
7685 };
src/items/pagebutton.rs +3 −2
@@ -1,7 +1,7 @@
11use crate::{
22 config::AppearanceConfig,
33 global::structs::{
4 ChannelDisplayPage, ChannelDisplayPageType, MainMenuPage, Page, Task, Tasks, Message,
4 ChannelDisplayPage, ChannelDisplayPageType, MainMenuPage, Message, Page, Task, Tasks,
55 },
66};
77use tui::{
@@ -97,7 +97,8 @@ impl FrameworkItem for PageButton {
9797 let current_page = framework.data.state.get::<Page>().unwrap().clone();
9898
9999 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"));
101102 return false;
102103 }
103104
src/items/singleitem.rs +5 −7
@@ -370,14 +370,12 @@ impl SingleItem {
370370 if iteminfo.selected {
371371 self.grid
372372 .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));
373376 } else {
374 if iteminfo.hover {
375 self.grid
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 }
377 self.grid
378 .set_border_style(Style::default().fg(appearance.colors.outline));
381379 }
382380
383381 self.r#type