Commit 1d6be1e815

1d6be1e81548ac4c14c7b238a1c90aee28e421e9

parent: d4894e125c

Unsigned

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

Channels page

Added channels page, only watch history need to be added before release

Layout: unified · split

Cargo.lock +11 −11
@@ -58,9 +58,9 @@ checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba"
5858
5959[[package]]
6060name = "bytemuck"
61version = "1.12.1"
61version = "1.12.2"
6262source = "registry+https://github.com/rust-lang/crates.io-index"
63checksum = "2f5715e491b5a1598fc2bef5a606847b5dc1d48ea625bd3c02c00de8285591da"
63checksum = "5aec14f5d4e6e3f927cd0c81f72e5710d95ee9019fbeb4b3021193867491bfd8"
6464
6565[[package]]
6666name = "byteorder"
@@ -628,9 +628,9 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
628628
629629[[package]]
630630name = "hyper"
631version = "0.14.20"
631version = "0.14.22"
632632source = "registry+https://github.com/rust-lang/crates.io-index"
633checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac"
633checksum = "abfba89e19b959ca163c7752ba59d737c1ceea53a5d31a149c805446fc958064"
634634dependencies = [
635635 "bytes",
636636 "futures-channel",
@@ -890,9 +890,9 @@ dependencies = [
890890
891891[[package]]
892892name = "native-tls"
893version = "0.2.10"
893version = "0.2.11"
894894source = "registry+https://github.com/rust-lang/crates.io-index"
895checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9"
895checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e"
896896dependencies = [
897897 "lazy_static",
898898 "libc",
@@ -938,9 +938,9 @@ dependencies = [
938938
939939[[package]]
940940name = "num_cpus"
941version = "1.13.1"
941version = "1.14.0"
942942source = "registry+https://github.com/rust-lang/crates.io-index"
943checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1"
943checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5"
944944dependencies = [
945945 "hermit-abi",
946946 "libc",
@@ -1066,14 +1066,14 @@ checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
10661066
10671067[[package]]
10681068name = "png"
1069version = "0.17.6"
1069version = "0.17.7"
10701070source = "registry+https://github.com/rust-lang/crates.io-index"
1071checksum = "8f0e7f4c94ec26ff209cee506314212639d6c91b80afb82984819fafce9df01c"
1071checksum = "5d708eaf860a19b19ce538740d2b4bdeeb8337fa53f7738455e706623ad5c638"
10721072dependencies = [
10731073 "bitflags",
10741074 "crc32fast",
10751075 "flate2",
1076 "miniz_oxide 0.5.4",
1076 "miniz_oxide 0.6.2",
10771077]
10781078
10791079[[package]]
README.md −1
@@ -16,7 +16,6 @@ An aesthetically pleasing YouTube TUI written in Rust.
1616>
1717> ### Todo before release:
1818> - Watch history
19> - Channel page
2019>
2120> The previous release on `crates.io` is unaffected, and it should be used instead.
2221
example config files/appearance.yml deleted −37
@@ -1,37 +0,0 @@
1borders: Rounded
2colors:
3 text: Reset
4 text_special: Reset
5 text_secondary: Reset
6 text_error: LightRed
7 outline: Reset
8 outline_selected: LightBlue
9 outline_hover: LightRed
10 outline_secondary: LightYellow
11 message_outline: !Rgb
12 - 255
13 - 127
14 - 0
15 message_error_outline: LightRed
16 message_success_outline: LightGreen
17 item_info:
18 tag: Gray
19 title: LightBlue
20 description: Gray
21 author: LightGreen
22 viewcount: LightYellow
23 length: LightCyan
24 published: LightMagenta
25 video_count: !Rgb
26 - 131
27 - 141
28 - 255
29 sub_count: LightYellow
30 likes: !Rgb
31 - 200
32 - 255
33 - 129
34 genre: !Rgb
35 - 255
36 - 121
37 - 215
example config files/commands.yml deleted −18
@@ -1,18 +0,0 @@
1video:
2- Play video: ${video-player} ${embed-url}
3- Play audio: ${terminal-emulator} ${video-player} ${embed-url} --no-video
4- Play audio (loop): ${terminal-emulator} ${video-player} ${embed-url} --no-video --loop-file=inf
5- Open in browser: ${browser} ${url}
6- Download video (webm): ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${embed-url}
7- Download audio (opus): ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${embed-url} -x
8- 'Mode: ${provider}': '%switch-provider%'
9playlist:
10- Switch view: '%switch-view%'
11- Play all videos: ${video-player} ${all-videos}
12- Play all audio: ${terminal-emulator} ${video-player} ${all-videos} --no-video
13- Shuffle play all audio: ${terminal-emulator} ${video-player} ${all-videos} --no-video --shuffle
14- Shuffle play all audio (loop): ${terminal-emulator} ${video-player} ${all-videos} --no-video --shuffle --loop-playlist=inf
15- Open in browser: ${browser} ${url}
16- Download all video (webm): ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${all-videos}
17- Download all audio (opus): ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${all-videos} -x
18- 'Mode: ${provider}': '%switch-provider%'
example config files/keybindings.yml deleted −26
@@ -1,26 +0,0 @@
1!Char 'r':
2 2: Reload
3Right:
4 0: MoveRight
5Down:
6 0: MoveDown
7!Char 'h':
8 0: MoveLeft
9Enter:
10 0: Select
11!Char 'l':
12 0: MoveRight
13Backspace:
14 0: Back
15!Char 'j':
16 0: MoveDown
17!Char 'k':
18 0: MoveUp
19Left:
20 0: MoveLeft
21Esc:
22 0: Deselect
23Up:
24 0: MoveUp
25!Char 'q':
26 0: Exit
example config files/main.yml deleted −14
@@ -1,14 +0,0 @@
1invidious_instance: https://vid.puffyan.us
2piped_instance: https://piped.garudalinux.org
3allow_unicode: false
4message_bar_default: All good :)
5images: HalfBlocks
6refresh_after_modifying_search_filters: true
7image_index: 4
8provider: YouTube
9env:
10 terminal-emulator: konsole -e
11 youtube-downloader: yt-dlp
12 browser: firefox
13 download-path: '''~/Downloads/%(title)s-%(id)s.%(ext)s'''
14 video-player: mpv
example config files/pages.yml deleted −33
@@ -1,33 +0,0 @@
1main_menu:
2 layout:
3 - !NonCenteredRow
4 - SearchBar
5 - SearchFilters
6 - !CenteredRow
7 - Trending
8 - Popular
9 - !NonCenteredRow
10 - ItemList
11 - !NonCenteredRow
12 - MessageBar
13 message: Loading main menu...
14search:
15 layout:
16 - !NonCenteredRow
17 - SearchBar
18 - SearchFilters
19 - !NonCenteredRow
20 - ItemList
21 - !NonCenteredRow
22 - MessageBar
23 message: Loading search results...
24singleitem:
25 layout:
26 - !NonCenteredRow
27 - SearchBar
28 - SearchFilters
29 - !NonCenteredRow
30 - SingleItemInfo
31 - !NonCenteredRow
32 - MessageBar
33 message: Loading item details...
example config files/search.yml deleted −6
@@ -1,6 +0,0 @@
1query: ''
2filters:
3 sort: Relevance
4 date: None
5 duration: None
6 type: All
src/config/keybindings.rs +33 −56
@@ -22,61 +22,38 @@ impl Key for KeyBindingsConfig {
2222
2323impl Default for KeyBindingsConfig {
2424 fn default() -> Self {
25 let mut map = HashMap::new();
26
27 let mut left = HashMap::new();
28 left.insert(0, KeyAction::MoveLeft);
29 map.insert(KeyCode::Left, left);
30
31 let mut right = HashMap::new();
32 right.insert(0, KeyAction::MoveRight);
33 map.insert(KeyCode::Right, right);
34
35 let mut up = HashMap::new();
36 up.insert(0, KeyAction::MoveUp);
37 map.insert(KeyCode::Up, up);
38
39 let mut down = HashMap::new();
40 down.insert(0, KeyAction::MoveDown);
41 map.insert(KeyCode::Down, down);
42
43 let mut enter = HashMap::new();
44 enter.insert(0, KeyAction::Select);
45 map.insert(KeyCode::Enter, enter);
46
47 let mut escape = HashMap::new();
48 escape.insert(0, KeyAction::Deselect);
49 map.insert(KeyCode::Esc, escape);
50
51 let mut q = HashMap::new();
52 q.insert(0, KeyAction::Exit);
53 map.insert(KeyCode::Char('q'), q);
54
55 let mut backspace = HashMap::new();
56 backspace.insert(0, KeyAction::Back);
57 map.insert(KeyCode::Backspace, backspace);
58
59 let mut r = HashMap::new();
60 r.insert(2, KeyAction::Reload);
61 map.insert(KeyCode::Char('r'), r);
62
63 // vim keybindings
64 let mut h = HashMap::new();
65 h.insert(0, KeyAction::MoveLeft);
66 map.insert(KeyCode::Char('h'), h);
67
68 let mut j = HashMap::new();
69 j.insert(0, KeyAction::MoveDown);
70 map.insert(KeyCode::Char('j'), j);
71
72 let mut k = HashMap::new();
73 k.insert(0, KeyAction::MoveUp);
74 map.insert(KeyCode::Char('k'), k);
75
76 let mut l = HashMap::new();
77 l.insert(0, KeyAction::MoveRight);
78 map.insert(KeyCode::Char('l'), l);
79
80 Self(map)
25 Self(HashMap::from([
26 // movement keys // Alt left should be back
27 (
28 KeyCode::Left,
29 HashMap::from([(0, KeyAction::MoveLeft), (4, KeyAction::Back)]),
30 ),
31 (KeyCode::Right, HashMap::from([(0, KeyAction::MoveRight)])),
32 (KeyCode::Up, HashMap::from([(0, KeyAction::MoveUp)])),
33 (KeyCode::Down, HashMap::from([(0, KeyAction::MoveDown)])),
34 // vim keybindings
35 (
36 KeyCode::Char('h'),
37 HashMap::from([(0, KeyAction::MoveLeft)]),
38 ),
39 (
40 KeyCode::Char('j'),
41 HashMap::from([(0, KeyAction::MoveDown)]),
42 ),
43 (KeyCode::Char('k'), HashMap::from([(0, KeyAction::MoveUp)])),
44 (
45 KeyCode::Char('l'),
46 HashMap::from([(0, KeyAction::MoveRight)]),
47 ),
48 // functional keys
49 (KeyCode::Enter, HashMap::from([(0, KeyAction::Select)])),
50 (KeyCode::Esc, HashMap::from([(0, KeyAction::Deselect)])),
51 (KeyCode::Char('q'), HashMap::from([(0, KeyAction::Exit)])),
52 (KeyCode::Char('r'), HashMap::from([(0, KeyAction::Reload)])),
53 // history
54 (KeyCode::Backspace, HashMap::from([(0, KeyAction::Back)])),
55 (KeyCode::End, HashMap::from([(0, KeyAction::ClearHistory)])),
56 (KeyCode::Home, HashMap::from([(0, KeyAction::FirstHistory)])),
57 ]))
8158 }
8259}
src/config/pages.rs +43 −4
@@ -1,6 +1,8 @@
11use crate::{
22 global::traits::ConfigTrait,
3 items::{ItemList, MessageBar, PageButton, SearchBar, SearchFilter, SingleItem},
3 items::{
4 ChannelDisplay, ItemList, MessageBar, PageButton, SearchBar, SearchFilter, SingleItem,
5 },
46};
57use serde::{Deserialize, Serialize};
68use std::slice;
@@ -35,6 +37,8 @@ pub struct PagesConfig {
3537 pub search: PageConfig,
3638 #[serde(default = "singleitem_default")]
3739 pub singleitem: PageConfig,
40 #[serde(default = "channeldisplay_default")]
41 pub channeldisplay: PageConfig,
3842}
3943
4044impl Key for PagesConfig {
@@ -51,6 +55,7 @@ impl Default for PagesConfig {
5155 main_menu: main_menu_default(),
5256 search: search_default(),
5357 singleitem: singleitem_default(),
58 channeldisplay: channeldisplay_default(),
5459 }
5560 }
5661}
@@ -158,6 +163,10 @@ pub enum PageItems {
158163 Popular,
159164 SearchFilters,
160165 SingleItemInfo,
166 ChannelDisplay,
167 ChannelMain,
168 ChannelVideos,
169 ChannelPlaylists,
161170}
162171
163172impl PageItems {
@@ -171,15 +180,23 @@ impl PageItems {
171180 Self::ItemList => Box::new(ItemList::default()),
172181 Self::SearchFilters => Box::new(SearchFilter::default()),
173182 Self::SingleItemInfo => Box::new(SingleItem::default()),
183 Self::ChannelDisplay => Box::new(ChannelDisplay::default()),
184 Self::ChannelMain => Box::new(PageButton::ChannelMain),
185 Self::ChannelVideos => Box::new(PageButton::ChannelVideos),
186 Self::ChannelPlaylists => Box::new(PageButton::ChannelPlaylists),
174187 }
175188 }
176189
177190 pub fn width(&self) -> Constraint {
178191 match self {
179 Self::Popular | Self::Trending => Constraint::Length(15),
192 Self::Popular
193 | Self::Trending
194 | Self::ChannelMain
195 | Self::ChannelVideos
196 | Self::ChannelPlaylists => Constraint::Length(15),
180197 Self::SearchBar => Constraint::Min(16),
181198 Self::MessageBar => Constraint::Min(3),
182 Self::ItemList | Self::SingleItemInfo => Constraint::Min(9),
199 Self::ItemList | Self::SingleItemInfo | Self::ChannelDisplay => Constraint::Min(9),
183200 Self::SearchFilters => Constraint::Length(5),
184201 }
185202 }
@@ -187,11 +204,14 @@ impl PageItems {
187204 pub fn height(&self) -> Constraint {
188205 match self {
189206 Self::Popular
207 | Self::ChannelMain
208 | Self::ChannelVideos
209 | Self::ChannelPlaylists
190210 | Self::Trending
191211 | Self::MessageBar
192212 | Self::SearchBar
193213 | Self::SearchFilters => Constraint::Length(3),
194 Self::ItemList | Self::SingleItemInfo => Constraint::Min(6),
214 Self::ItemList | Self::SingleItemInfo | Self::ChannelDisplay => Constraint::Min(6),
195215 }
196216 }
197217}
@@ -253,3 +273,22 @@ fn singleitem_default() -> PageConfig {
253273 message: String::from("Loading item details..."),
254274 }
255275}
276
277fn channeldisplay_default() -> PageConfig {
278 PageConfig {
279 layout: vec![
280 PageRow::from_vec(vec![PageItems::SearchBar, PageItems::SearchFilters], false),
281 PageRow::from_vec(
282 vec![
283 PageItems::ChannelMain,
284 PageItems::ChannelVideos,
285 PageItems::ChannelPlaylists,
286 ],
287 true,
288 ),
289 PageRow::from_vec(vec![PageItems::ChannelDisplay], false),
290 PageRow::from_vec(vec![PageItems::MessageBar], false),
291 ],
292 message: String::from("Loading channel details..."),
293 }
294}
src/global/functions/download_all_images.rs +5 −1
@@ -31,6 +31,10 @@ impl From<&Item> for Option<DownloadRequest> {
3131 url: fullplaylist.thumbnail_url.clone(),
3232 id: fullplaylist.id.clone(),
3333 },
34 Item::FullChannel(fullchannel) => DownloadRequest {
35 url: fullchannel.thumbnail_url.clone(),
36 id: fullchannel.id.clone(),
37 },
3438 Item::Unknown(_) => return None,
3539 })
3640 }
@@ -62,7 +66,7 @@ async fn download_all_images_async(downloads: Vec<DownloadRequest>) {
6266 if !path.exists() {
6367 actions.push(download_single(
6468 download.url,
65 path.to_owned().into_os_string().into_string().unwrap(),
69 path.clone().into_os_string().into_string().unwrap(),
6670 ));
6771 }
6872
src/global/structs/item.rs +59 −2
@@ -1,7 +1,9 @@
11use crate::global::functions::{date_text, secs_display_string, viewcount_text};
22use invidious::structs::{
3 channel::Channel,
34 hidden::{
4 Playlist, PlaylistItem, PopularItem, SearchItem, SearchItemTransition, TrendingVideo,
5 ChannelVideo, Playlist, PlaylistItem, PopularItem, SearchItem, SearchItemTransition,
6 TrendingVideo,
57 },
68 universal::Playlist as FullPlaylist,
79 video::Video,
@@ -18,6 +20,7 @@ pub enum Item {
1820 MiniChannel(MiniChannelItem),
1921 FullVideo(FullVideoItem),
2022 FullPlaylist(FullPlaylistItem),
23 FullChannel(FullChannelItem),
2124 Unknown(SearchItemTransition),
2225}
2326
@@ -85,6 +88,19 @@ pub struct FullPlaylistItem {
8588 pub videos: Vec<Item>,
8689}
8790
91#[derive(Clone)]
92pub struct FullChannelItem {
93 pub name: String,
94 pub id: String,
95 pub thumbnail_url: String,
96 pub sub_count: u32,
97 pub sub_count_text: String,
98 pub total_views: String,
99 pub created: String,
100 pub autogenerated: bool,
101 pub description: String,
102}
103
88104impl Display for Item {
89105 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
90106 f.write_str(match self {
@@ -93,6 +109,7 @@ impl Display for Item {
93109 Self::MiniChannel(channel) => &channel.name,
94110 Self::FullVideo(video) => &video.title,
95111 Self::FullPlaylist(playlist) => &playlist.title,
112 Self::FullChannel(channel) => &channel.name,
96113 Self::Unknown(_) => "Unknown item",
97114 })
98115 }
@@ -144,6 +161,7 @@ impl Item {
144161 Self::MiniChannel(channel) => &channel.id,
145162 Self::FullVideo(video) => &video.id,
146163 Self::FullPlaylist(playlist) => &playlist.id,
164 Self::FullChannel(channel) => &channel.id,
147165 Self::Unknown(_) => "invalid",
148166 }
149167 }
@@ -297,7 +315,7 @@ impl Item {
297315 Self::MiniVideo(MiniVideoItem {
298316 title: original.title,
299317 id: original.id,
300 thumbnail_url: original.thumbnails[image_index].url.to_owned(),
318 thumbnail_url: original.thumbnails[image_index].url.clone(),
301319 length: secs_display_string(original.length),
302320 views: None,
303321 channel: original.author,
@@ -306,4 +324,43 @@ impl Item {
306324 description: None,
307325 })
308326 }
327
328 pub fn from_full_channel(original: Channel, image_index: usize) -> Self {
329 Self::FullChannel(FullChannelItem {
330 name: original.name,
331 id: original.id,
332 thumbnail_url: original.thumbnails[image_index].url.clone(),
333 sub_count: original.sub_count,
334 sub_count_text: viewcount_text(original.sub_count as u64),
335 total_views: viewcount_text(original.total_views),
336 created: date_text(original.joined),
337 autogenerated: original.auto_generated,
338 description: original.description,
339 })
340 }
341
342 pub fn from_channel_video(original: ChannelVideo, image_index: usize) -> Self {
343 Self::MiniVideo(MiniVideoItem {
344 title: original.title,
345 id: original.id,
346 thumbnail_url: original.thumbnails[image_index].url.clone(),
347 length: secs_display_string(original.length),
348 views: Some(viewcount_text(original.view_count)),
349 channel: original.author,
350 channel_id: original.author_id,
351 published: Some(date_text(original.published)),
352 description: Some(original.description),
353 })
354 }
355
356 pub fn from_channel_playlist(original: Playlist) -> Self {
357 Self::MiniPlaylist(MiniPlaylistItem {
358 title: original.title,
359 id: original.id,
360 channel: original.author,
361 channel_id: original.author_id,
362 video_count: original.video_count,
363 thumbnail_url: original.thumbnail,
364 })
365 }
309366}
src/global/structs/keyaction.rs +13
@@ -4,13 +4,26 @@ use serde::{Deserialize, Serialize};
44// Each key + modifier is bind to a key in a HashMap<KeyCode, HashMap<u8, KeyAction>>
55#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug)]
66pub enum KeyAction {
7 /// Moves cursor to the left direction, or to the first item
78 MoveLeft,
9 /// Moves cursor to the right direction, or to the last item
810 MoveRight,
11 /// Moves cursor up
912 MoveUp,
13 /// Moves cursor dowm
1014 MoveDown,
15 /// select the current item
1116 Select,
17 /// deselect the current item, reverts the cursor back to its hover state
1218 Deselect,
19 /// exits/quits the entire app
1320 Exit,
21 /// revert last history
1422 Back,
23 /// removes all history
24 ClearHistory,
25 /// reverts back to first history (home page if it is not cleared)
26 FirstHistory,
27 /// reload the current page
1528 Reload,
1629}
src/global/structs/page.rs +30 −3
@@ -6,11 +6,12 @@ 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, Eq)]
9#[derive(Clone, PartialEq)]
1010pub enum Page {
1111 MainMenu(MainMenuPage),
1212 Search(Search),
1313 SingleItem(SingleItemPage),
14 ChannelDisplay(ChannelDisplayPage),
1415}
1516
1617impl Debug for Page {
@@ -21,11 +22,22 @@ impl Debug for Page {
2122 Self::MainMenu(_) => "MainMenu",
2223 Self::Search(_) => "Search",
2324 Self::SingleItem(_) => "SingleItem",
25 Self::ChannelDisplay(_) => "ChannelDisplay",
2426 }
2527 ))
2628 }
2729}
2830
31impl Page {
32 pub fn channeldisplay(&self) -> &ChannelDisplayPage {
33 if let Self::ChannelDisplay(channeldisplaypage) = self {
34 channeldisplaypage
35 } else {
36 panic!("not a channel display");
37 }
38 }
39}
40
2941impl Default for Page {
3042 fn default() -> Self {
3143 Self::MainMenu(MainMenuPage::default())
@@ -37,7 +49,7 @@ impl Key for Page {
3749}
3850
3951/// page variants for the main menu
40#[derive(Clone, PartialEq, Eq)]
52#[derive(Clone, Copy, PartialEq)]
4153pub enum MainMenuPage {
4254 Trending,
4355 Popular,
@@ -49,8 +61,21 @@ impl Default for MainMenuPage {
4961 }
5062}
5163
64#[derive(Clone, PartialEq)]
65pub struct ChannelDisplayPage {
66 pub id: String,
67 pub r#type: ChannelDisplayPageType,
68}
69
70#[derive(Clone, Copy, PartialEq)]
71pub enum ChannelDisplayPageType {
72 Main,
73 Videos,
74 Playlists,
75}
76
5277/// Different items to be displayed on a single item page
53#[derive(Clone, PartialEq, Eq)]
78#[derive(Clone, PartialEq)]
5479pub enum SingleItemPage {
5580 Video(String),
5681 Playlist(String),
@@ -63,6 +88,7 @@ impl Page {
6388 Self::MainMenu(_) => pages_config.main_menu.clone(),
6489 Self::Search(_) => pages_config.search.clone(),
6590 Self::SingleItem(_) => pages_config.singleitem.clone(),
91 Self::ChannelDisplay(_) => pages_config.channeldisplay.clone(),
6692 }
6793 }
6894
@@ -73,6 +99,7 @@ impl Page {
7399 Self::MainMenu(_) => pages_config.main_menu.message.clone(),
74100 Self::Search(_) => pages_config.search.message.clone(),
75101 Self::SingleItem(_) => pages_config.singleitem.message.clone(),
102 Self::ChannelDisplay(_) => pages_config.channeldisplay.message.clone(),
76103 }
77104 }
78105}
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, Eq)]
22#[derive(Clone, PartialEq)]
2323pub struct TaskQueue {
2424 pub render: RenderTask,
2525 pub reload: bool,
src/items/channeldisplay.rs added +377
@@ -0,0 +1,377 @@
1use super::ItemInfo;
2use crate::{
3 config::{AppearanceConfig, KeyBindingsConfig, MainConfig},
4 global::{
5 functions::download_all_images,
6 structs::{
7 ChannelDisplayPageType, InvidiousClient, Item, KeyAction, Page, SingleItemPage, Task,
8 Tasks, Message,
9 },
10 },
11};
12use tui::{
13 layout::Constraint,
14 style::Style,
15 widgets::{Block, Borders},
16};
17use tui_additions::{
18 framework::FrameworkItem,
19 widgets::{Grid, TextList},
20};
21
22/// the 4 pages that a channel has (including the default "blank" page when loading)
23#[derive(Clone)]
24pub enum ChannelDisplay {
25 None,
26 Main {
27 channel: Item,
28 },
29 Videos {
30 videos: Vec<Item>,
31 textlist: TextList,
32 iteminfo: ItemInfo,
33 grid: Grid,
34 },
35 Playlists {
36 playlists: Vec<Item>,
37 textlist: TextList,
38 iteminfo: ItemInfo,
39 grid: Grid,
40 },
41}
42
43impl Default for ChannelDisplay {
44 fn default() -> Self {
45 Self::None
46 }
47}
48
49impl ChannelDisplay {
50 fn update_appearance(
51 &mut self,
52 info: &tui_additions::framework::ItemInfo,
53 appearance: &AppearanceConfig,
54 ) {
55 // is runs on every render
56 match self {
57 ChannelDisplay::Videos { textlist, grid, .. } => {
58 if info.selected {
59 textlist
60 .set_selected_style(Style::default().fg(appearance.colors.text_special));
61 textlist.set_cursor_style(Style::default().fg(appearance.colors.outline_hover));
62 grid.set_border_style(Style::default().fg(appearance.colors.outline_selected));
63 } else {
64 if info.hover {
65 grid.set_border_style(Style::default().fg(appearance.colors.outline_hover));
66 } else {
67 grid.set_border_style(Style::default().fg(appearance.colors.outline));
68 }
69 textlist
70 .set_selected_style(Style::default().fg(appearance.colors.text_secondary));
71 textlist
72 .set_cursor_style(Style::default().fg(appearance.colors.outline_secondary));
73 }
74 }
75 ChannelDisplay::Playlists { textlist, grid, .. } => {
76 if info.selected {
77 textlist
78 .set_selected_style(Style::default().fg(appearance.colors.text_special));
79 textlist.set_cursor_style(Style::default().fg(appearance.colors.outline_hover));
80 grid.set_border_style(Style::default().fg(appearance.colors.outline_selected));
81 } else {
82 if info.hover {
83 grid.set_border_style(Style::default().fg(appearance.colors.outline_hover));
84 } else {
85 grid.set_border_style(Style::default().fg(appearance.colors.outline));
86 }
87 textlist
88 .set_selected_style(Style::default().fg(appearance.colors.text_secondary));
89 textlist
90 .set_cursor_style(Style::default().fg(appearance.colors.outline_secondary));
91 }
92 }
93 _ => {}
94 }
95 }
96
97 pub fn selectable(&self) -> bool {
98 !(matches!(self, Self::Main { .. }) || matches!(self, Self::None))
99 }
100}
101
102impl FrameworkItem for ChannelDisplay {
103 fn render(
104 &mut self,
105 frame: &mut tui::Frame<tui::backend::CrosstermBackend<std::io::Stdout>>,
106 framework: &mut tui_additions::framework::FrameworkClean,
107 area: tui::layout::Rect,
108 popup_render: bool,
109 info: tui_additions::framework::ItemInfo,
110 ) {
111 if popup_render {
112 return;
113 }
114
115 let appearance = framework.data.global.get::<AppearanceConfig>().unwrap();
116 self.update_appearance(&info, appearance);
117 let border_style = Style::default().fg(if info.hover {
118 appearance.colors.outline_hover
119 } else if info.selected {
120 appearance.colors.outline_selected
121 } else {
122 appearance.colors.outline
123 });
124
125 // matches itself to render differently depending on the enum variation
126 match self {
127 Self::None => {
128 // the block is created when rendered because its quite simple and should not be a
129 // performance issue
130 let block = Block::default()
131 .border_type(appearance.borders)
132 .borders(Borders::ALL)
133 .border_style(border_style);
134 frame.render_widget(block, area);
135 }
136 Self::Main { channel } => {
137 let block = Block::default()
138 .border_type(appearance.borders)
139 .borders(Borders::ALL)
140 .border_style(border_style);
141 let inner = block.inner(area);
142
143 frame.render_widget(block, area);
144 ItemInfo {
145 item: Some(channel.clone()),
146 }
147 .render(frame, framework, inner, popup_render, info);
148 }
149 Self::Videos {
150 textlist,
151 iteminfo,
152 grid,
153 ..
154 }
155 | Self::Playlists {
156 textlist,
157 iteminfo,
158 grid,
159 ..
160 } => {
161 let inner = &grid.chunks(area).unwrap()[0];
162
163 frame.render_widget(grid.clone(), area);
164 textlist.set_height(inner[0].height);
165 frame.render_widget(textlist.clone(), inner[0]);
166 iteminfo.render(frame, framework, inner[1], popup_render, info);
167 }
168 }
169 }
170
171 fn select(&mut self, _framework: &mut tui_additions::framework::FrameworkClean) -> bool {
172 self.selectable()
173 }
174
175 fn key_event(
176 &mut self,
177 framework: &mut tui_additions::framework::FrameworkClean,
178 key: crossterm::event::KeyEvent,
179 _info: tui_additions::framework::ItemInfo,
180 ) -> Result<(), Box<dyn std::error::Error>> {
181 let action = if let Some(keyactions) = framework
182 .data
183 .global
184 .get::<KeyBindingsConfig>()
185 .unwrap()
186 .0
187 .get(&key.code)
188 {
189 if let Some(action) = keyactions.get(&key.modifiers.bits()) {
190 *action
191 } else {
192 return Ok(());
193 }
194 } else {
195 return Ok(());
196 };
197
198 match self {
199 Self::Videos {
200 videos,
201 textlist,
202 iteminfo,
203 ..
204 } => {
205 let updated = match action {
206 KeyAction::MoveUp => textlist.up().is_ok(),
207 KeyAction::MoveDown => textlist.down().is_ok(),
208 KeyAction::MoveLeft => textlist.first().is_ok(),
209 KeyAction::MoveRight => textlist.last().is_ok(),
210 KeyAction::Select => {
211 // on select loads that in singleitem
212 if !videos.is_empty() {
213 framework
214 .data
215 .state
216 .get_mut::<Tasks>()
217 .unwrap()
218 .priority
219 .push(Task::LoadPage(Page::SingleItem(SingleItemPage::Video(
220 videos[textlist.selected].minivideo().id.clone(),
221 ))));
222 } else {
223 *framework.data.global.get_mut::<Message>().unwrap() = Message::Error(String::from("There is nothing to select"));
224 }
225 true
226 },
227 _ => false,
228 };
229
230 // only update iteminfo (it requires cloning) if changed and not empty
231 if updated && !videos.is_empty() {
232 framework
233 .data
234 .state
235 .get_mut::<Tasks>()
236 .unwrap()
237 .priority
238 .push(Task::RenderAll);
239 iteminfo.item = Some(videos[textlist.selected].clone());
240 }
241 }
242 Self::Playlists {
243 playlists,
244 textlist,
245 iteminfo,
246 ..
247 } => {
248 let updated = match action {
249 KeyAction::MoveUp => textlist.up().is_ok(),
250 KeyAction::MoveDown => textlist.down().is_ok(),
251 KeyAction::MoveLeft => textlist.first().is_ok(),
252 KeyAction::MoveRight => textlist.last().is_ok(),
253 KeyAction::Select => {
254 if !playlists.is_empty() {
255 framework
256 .data
257 .state
258 .get_mut::<Tasks>()
259 .unwrap()
260 .priority
261 .push(Task::LoadPage(Page::SingleItem(SingleItemPage::Playlist(
262 playlists[textlist.selected].miniplaylist().id.clone(),
263 ))));
264 } else {
265 *framework.data.global.get_mut::<Message>().unwrap() = Message::Error(String::from("There is nothing to select"));
266 }
267 true
268 },
269 _ => false,
270 };
271
272 if updated && !playlists.is_empty() {
273 framework
274 .data
275 .state
276 .get_mut::<Tasks>()
277 .unwrap()
278 .priority
279 .push(Task::RenderAll);
280 iteminfo.item = Some(playlists[textlist.selected].clone());
281 }
282 }
283 _ => {}
284 }
285
286 Ok(())
287 }
288
289 fn load_item(
290 &mut self,
291 framework: &mut tui_additions::framework::FrameworkClean,
292 _info: tui_additions::framework::ItemInfo,
293 ) -> Result<(), Box<dyn std::error::Error>> {
294 let mainconfig = framework.data.global.get::<MainConfig>().unwrap();
295 let appearance = framework.data.global.get::<AppearanceConfig>().unwrap();
296 let page = framework.data.state.get::<Page>().unwrap().channeldisplay();
297
298 match page.r#type {
299 ChannelDisplayPageType::Main => {
300 let channel = Item::from_full_channel(
301 framework
302 .data
303 .global
304 .get::<InvidiousClient>()
305 .unwrap()
306 .0
307 .channel(&page.id, None)?,
308 mainconfig.image_index,
309 );
310 download_all_images(vec![(&channel).into()]);
311 *self = Self::Main { channel }
312 }
313 ChannelDisplayPageType::Videos => {
314 let videos = framework
315 .data
316 .global
317 .get::<InvidiousClient>()
318 .unwrap()
319 .0
320 .channel_videos(&page.id, None)?
321 .videos
322 .into_iter()
323 .map(|video| Item::from_channel_video(video, mainconfig.image_index))
324 .collect::<Vec<_>>();
325 download_all_images(videos.iter().map(|item| item.into()).collect());
326 *self = Self::Videos {
327 textlist: TextList::default()
328 .ascii_only(!mainconfig.allow_unicode)
329 .border_type(appearance.borders)
330 .style(Style::default().fg(appearance.colors.text))
331 .items(&videos)?,
332 iteminfo: ItemInfo {
333 item: videos.first().cloned(),
334 },
335 grid: Grid::new(
336 vec![Constraint::Percentage(60), Constraint::Percentage(40)],
337 vec![Constraint::Percentage(100)],
338 )?
339 .border_type(appearance.borders),
340 videos,
341 };
342 }
343 ChannelDisplayPageType::Playlists => {
344 let playlists = framework
345 .data
346 .global
347 .get::<InvidiousClient>()
348 .unwrap()
349 .0
350 .channel_playlists(&page.id, None)?
351 .playlists
352 .into_iter()
353 .map(Item::from_channel_playlist)
354 .collect::<Vec<_>>();
355 download_all_images(playlists.iter().map(|item| item.into()).collect());
356 *self = Self::Playlists {
357 textlist: TextList::default()
358 .ascii_only(!mainconfig.allow_unicode)
359 .border_type(appearance.borders)
360 .style(Style::default().fg(appearance.colors.text))
361 .items(&playlists)?,
362 iteminfo: ItemInfo {
363 item: playlists.first().cloned(),
364 },
365 grid: Grid::new(
366 vec![Constraint::Percentage(60), Constraint::Percentage(40)],
367 vec![Constraint::Percentage(100)],
368 )?
369 .border_type(appearance.borders),
370 playlists,
371 };
372 }
373 }
374
375 Ok(())
376 }
377}
src/items/iteminfo.rs +47 −9
@@ -53,6 +53,8 @@ impl FrameworkItem for ItemInfo {
5353 // entire page being taken up by the image
5454 width: Some(if let Item::MiniChannel(_) = item {
5555 area.width / 2
56 } else if let Item::FullChannel(_) = item {
57 area.width / 4
5658 } else {
5759 area.width
5860 } as u32),
@@ -84,13 +86,13 @@ impl FrameworkItem for ItemInfo {
8486 Style::default().fg(appearance.colors.item_info.tag),
8587 ),
8688 (
87 minivideo.title.to_owned(),
89 minivideo.title.clone(),
8890 Style::default().fg(appearance.colors.item_info.title),
8991 ),
9092 ],
9193 minivideo.description.as_ref().map(|description| {
9294 (
93 description.to_owned(),
95 description.clone(),
9496 Style::default().fg(appearance.colors.item_info.description),
9597 )
9698 }),
@@ -125,7 +127,7 @@ impl FrameworkItem for ItemInfo {
125127 Style::default().fg(appearance.colors.item_info.tag),
126128 ),
127129 (
128 miniplaylist.title.to_owned(),
130 miniplaylist.title.clone(),
129131 Style::default().fg(appearance.colors.item_info.title),
130132 ),
131133 (
@@ -154,7 +156,7 @@ impl FrameworkItem for ItemInfo {
154156 Style::default().fg(appearance.colors.item_info.tag),
155157 ),
156158 (
157 minichannel.name.to_owned(),
159 minichannel.name.clone(),
158160 Style::default().fg(appearance.colors.item_info.title),
159161 ),
160162 (
@@ -179,7 +181,7 @@ impl FrameworkItem for ItemInfo {
179181 ),
180182 ],
181183 Some((
182 minichannel.description.to_owned(),
184 minichannel.description.clone(),
183185 Style::default().fg(appearance.colors.item_info.description),
184186 )),
185187 ),
@@ -190,7 +192,7 @@ impl FrameworkItem for ItemInfo {
190192 Style::default().fg(appearance.colors.item_info.tag),
191193 ),
192194 (
193 fullvideo.title.to_owned(),
195 fullvideo.title.clone(),
194196 Style::default().fg(appearance.colors.item_info.title),
195197 ),
196198 (
@@ -218,7 +220,7 @@ impl FrameworkItem for ItemInfo {
218220 ),
219221 ],
220222 Some((
221 fullvideo.description.to_owned(),
223 fullvideo.description.clone(),
222224 Style::default().fg(appearance.colors.item_info.description),
223225 )),
224226 ),
@@ -229,7 +231,7 @@ impl FrameworkItem for ItemInfo {
229231 Style::default().fg(appearance.colors.item_info.tag),
230232 ),
231233 (
232 fullplaylist.title.to_owned(),
234 fullplaylist.title.clone(),
233235 Style::default().fg(appearance.colors.item_info.title),
234236 ),
235237 (
@@ -250,7 +252,43 @@ impl FrameworkItem for ItemInfo {
250252 ),
251253 ],
252254 Some((
253 fullplaylist.description.to_owned(),
255 fullplaylist.description.clone(),
256 Style::default().fg(appearance.colors.item_info.description),
257 )),
258 ),
259 Item::FullChannel(fullchannel) => (
260 vec![
261 (
262 if fullchannel.autogenerated {
263 String::from("[Auto generated]")
264 } else {
265 String::from("[Channel]")
266 },
267 Style::default().fg(appearance.colors.item_info.tag),
268 ),
269 (
270 fullchannel.name.clone(),
271 Style::default().fg(appearance.colors.item_info.title),
272 ),
273 (
274 format!("{} total views", fullchannel.total_views),
275 Style::default().fg(appearance.colors.item_info.viewcount),
276 ),
277 (
278 format!(
279 "{} subscriber{}",
280 fullchannel.sub_count_text,
281 if fullchannel.sub_count <= 1 { "" } else { "s" }
282 ),
283 Style::default().fg(appearance.colors.item_info.sub_count),
284 ),
285 (
286 format!("Created at {}", fullchannel.created),
287 Style::default().fg(appearance.colors.item_info.published),
288 ),
289 ],
290 Some((
291 fullchannel.description.clone(),
254292 Style::default().fg(appearance.colors.item_info.description),
255293 )),
256294 ),
src/items/itemlist.rs +10 −4
@@ -12,8 +12,9 @@ use crate::{
1212 global::{
1313 functions::download_all_images,
1414 structs::{
15 FullPlaylistItem, FullVideoItem, InvidiousClient, Item, KeyAction, MainMenuPage,
16 MiniPlaylistItem, MiniVideoItem, Page, SingleItemPage, Task, Tasks,
15 ChannelDisplayPage, ChannelDisplayPageType, FullPlaylistItem, FullVideoItem,
16 InvidiousClient, Item, KeyAction, MainMenuPage, MiniChannelItem, MiniPlaylistItem,
17 MiniVideoItem, Page, SingleItemPage, Task, Tasks,
1718 },
1819 },
1920};
@@ -99,7 +100,7 @@ impl FrameworkItem for ItemList {
99100
100101 // creates the grid
101102 let grid = self.grid.clone();
102 let chunks = grid.chunks(area).unwrap()[0].to_owned();
103 let chunks = grid.chunks(area).unwrap()[0].clone();
103104
104105 // creates the text list in cell (0, 1)
105106 self.textlist.set_height(chunks[0].height);
@@ -227,7 +228,12 @@ impl FrameworkItem for ItemList {
227228 | Item::FullPlaylist(FullPlaylistItem { id, .. }) => {
228229 Page::SingleItem(SingleItemPage::Playlist(id.clone()))
229230 }
230 Item::MiniChannel(_) => unimplemented!(),
231 Item::MiniChannel(MiniChannelItem { id, .. }) => {
232 Page::ChannelDisplay(ChannelDisplayPage {
233 id: id.clone(),
234 r#type: ChannelDisplayPageType::Main,
235 })
236 }
231237 _ => panic!("wtf did you just selected"),
232238 };
233239 framework
src/items/mod.rs +2
@@ -13,3 +13,5 @@ mod searchfilters;
1313pub use searchfilters::*;
1414mod singleitem;
1515pub use singleitem::*;
16mod channeldisplay;
17pub use channeldisplay::*;
src/items/pagebutton.rs +28 −4
@@ -1,6 +1,8 @@
11use crate::{
22 config::AppearanceConfig,
3 global::structs::{MainMenuPage, Page, Task, Tasks},
3 global::structs::{
4 ChannelDisplayPage, ChannelDisplayPageType, MainMenuPage, Page, Task, Tasks,
5 },
46};
57use tui::{
68 layout::Alignment,
@@ -14,13 +16,28 @@ use tui_additions::framework::FrameworkItem;
1416pub enum PageButton {
1517 Trending,
1618 Popular,
19 ChannelMain,
20 ChannelVideos,
21 ChannelPlaylists,
1722}
1823
1924impl PageButton {
20 pub fn page(&self) -> Page {
25 pub fn page(&self, current_page: &Page) -> Page {
2126 match self {
2227 Self::Trending => Page::MainMenu(MainMenuPage::Trending),
2328 Self::Popular => Page::MainMenu(MainMenuPage::Popular),
29 Self::ChannelMain => Page::ChannelDisplay(ChannelDisplayPage {
30 id: current_page.channeldisplay().id.clone(),
31 r#type: ChannelDisplayPageType::Main,
32 }),
33 Self::ChannelVideos => Page::ChannelDisplay(ChannelDisplayPage {
34 id: current_page.channeldisplay().id.clone(),
35 r#type: ChannelDisplayPageType::Videos,
36 }),
37 Self::ChannelPlaylists => Page::ChannelDisplay(ChannelDisplayPage {
38 id: current_page.channeldisplay().id.clone(),
39 r#type: ChannelDisplayPageType::Playlists,
40 }),
2441 }
2542 }
2643}
@@ -30,6 +47,9 @@ impl ToString for PageButton {
3047 match self {
3148 Self::Popular => String::from("Popular"),
3249 Self::Trending => String::from("Trending"),
50 Self::ChannelMain => String::from("Main"),
51 Self::ChannelVideos => String::from("Videos"),
52 Self::ChannelPlaylists => String::from("Playlists"),
3353 }
3454 }
3555}
@@ -49,7 +69,8 @@ impl FrameworkItem for PageButton {
4969 }
5070
5171 let appearance = framework.data.global.get::<AppearanceConfig>().unwrap();
52 let same_page = &self.page() == framework.data.state.get::<Page>().unwrap();
72 let same_page = &self.page(framework.data.state.get::<Page>().unwrap())
73 == framework.data.state.get::<Page>().unwrap();
5374
5475 let block = Block::default()
5576 .border_type(appearance.borders)
@@ -70,8 +91,11 @@ impl FrameworkItem for PageButton {
7091
7192 // when selected creates a load page task, but returns false to show that it is not being selected
7293 fn select(&mut self, framework: &mut tui_additions::framework::FrameworkClean) -> bool {
94 let current_page = framework.data.state.get::<Page>().unwrap().clone();
7395 let tasks = framework.data.state.get_mut::<Tasks>().unwrap();
74 tasks.priority.push(Task::LoadPage(self.page()));
96 tasks
97 .priority
98 .push(Task::LoadPage(self.page(&current_page)));
7599
76100 false
77101 }
src/items/singleitem.rs +1 −1
@@ -404,7 +404,7 @@ impl FrameworkItem for SingleItem {
404404 let appearance = framework.data.global.get::<AppearanceConfig>().unwrap();
405405 self.update_appearance(appearance, &info);
406406
407 let chunks = self.grid.chunks(area).unwrap()[0].to_owned();
407 let chunks = self.grid.chunks(area).unwrap()[0].clone();
408408
409409 frame.render_widget(self.grid.clone(), area);
410410
src/run.rs +28
@@ -100,6 +100,34 @@ pub fn run(
100100 .push(Task::ClearPage);
101101 }
102102 }
103 KeyAction::FirstHistory => {
104 if framework.revert_history(0).is_err() {
105 *framework.data.global.get_mut::<Message>().unwrap() =
106 Message::Error(String::from(
107 "This is already the beginning of history",
108 ))
109 } else {
110 framework
111 .data
112 .state
113 .get_mut::<Tasks>()
114 .unwrap()
115 .priority
116 .push(Task::ClearPage);
117 }
118 }
119 KeyAction::ClearHistory => {
120 if framework.history.is_empty() {
121 *framework.data.global.get_mut::<Message>().unwrap() =
122 Message::Error(String::from(
123 "This is already the beginning of history",
124 ))
125 } else {
126 framework.clear_history();
127 *framework.data.global.get_mut::<Message>().unwrap() =
128 Message::Success(String::from("History cleared!"))
129 }
130 }
103131 KeyAction::Select => {
104132 let _ = framework.select();
105133 }