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"
58 58
59[[package]] 59[[package]]
60name = "bytemuck" 60name = "bytemuck"
61version = "1.12.1" 61version = "1.12.2"
62source = "registry+https://github.com/rust-lang/crates.io-index" 62source = "registry+https://github.com/rust-lang/crates.io-index"
63checksum = "2f5715e491b5a1598fc2bef5a606847b5dc1d48ea625bd3c02c00de8285591da" 63checksum = "5aec14f5d4e6e3f927cd0c81f72e5710d95ee9019fbeb4b3021193867491bfd8"
64 64
65[[package]] 65[[package]]
66name = "byteorder" 66name = "byteorder"
@@ -628,9 +628,9 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
628 628
629[[package]] 629[[package]]
630name = "hyper" 630name = "hyper"
631version = "0.14.20" 631version = "0.14.22"
632source = "registry+https://github.com/rust-lang/crates.io-index" 632source = "registry+https://github.com/rust-lang/crates.io-index"
633checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac" 633checksum = "abfba89e19b959ca163c7752ba59d737c1ceea53a5d31a149c805446fc958064"
634dependencies = [ 634dependencies = [
635 "bytes", 635 "bytes",
636 "futures-channel", 636 "futures-channel",
@@ -890,9 +890,9 @@ dependencies = [
890 890
891[[package]] 891[[package]]
892name = "native-tls" 892name = "native-tls"
893version = "0.2.10" 893version = "0.2.11"
894source = "registry+https://github.com/rust-lang/crates.io-index" 894source = "registry+https://github.com/rust-lang/crates.io-index"
895checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" 895checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e"
896dependencies = [ 896dependencies = [
897 "lazy_static", 897 "lazy_static",
898 "libc", 898 "libc",
@@ -938,9 +938,9 @@ dependencies = [
938 938
939[[package]] 939[[package]]
940name = "num_cpus" 940name = "num_cpus"
941version = "1.13.1" 941version = "1.14.0"
942source = "registry+https://github.com/rust-lang/crates.io-index" 942source = "registry+https://github.com/rust-lang/crates.io-index"
943checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" 943checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5"
944dependencies = [ 944dependencies = [
945 "hermit-abi", 945 "hermit-abi",
946 "libc", 946 "libc",
@@ -1066,14 +1066,14 @@ checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
1066 1066
1067[[package]] 1067[[package]]
1068name = "png" 1068name = "png"
1069version = "0.17.6" 1069version = "0.17.7"
1070source = "registry+https://github.com/rust-lang/crates.io-index" 1070source = "registry+https://github.com/rust-lang/crates.io-index"
1071checksum = "8f0e7f4c94ec26ff209cee506314212639d6c91b80afb82984819fafce9df01c" 1071checksum = "5d708eaf860a19b19ce538740d2b4bdeeb8337fa53f7738455e706623ad5c638"
1072dependencies = [ 1072dependencies = [
1073 "bitflags", 1073 "bitflags",
1074 "crc32fast", 1074 "crc32fast",
1075 "flate2", 1075 "flate2",
1076 "miniz_oxide 0.5.4", 1076 "miniz_oxide 0.6.2",
1077] 1077]
1078 1078
1079[[package]] 1079[[package]]
README.md −1
@@ -16,7 +16,6 @@ An aesthetically pleasing YouTube TUI written in Rust.
16> 16>
17> ### Todo before release: 17> ### Todo before release:
18> - Watch history 18> - Watch history
19> - Channel page
20> 19>
21> The previous release on `crates.io` is unaffected, and it should be used instead. 20> The previous release on `crates.io` is unaffected, and it should be used instead.
22 21
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 {
22 22
23impl Default for KeyBindingsConfig { 23impl Default for KeyBindingsConfig {
24 fn default() -> Self { 24 fn default() -> Self {
25 let mut map = HashMap::new(); 25 Self(HashMap::from([
26 26 // movement keys // Alt left should be back
27 let mut left = HashMap::new(); 27 (
28 left.insert(0, KeyAction::MoveLeft); 28 KeyCode::Left,
29 map.insert(KeyCode::Left, left); 29 HashMap::from([(0, KeyAction::MoveLeft), (4, KeyAction::Back)]),
30 30 ),
31 let mut right = HashMap::new(); 31 (KeyCode::Right, HashMap::from([(0, KeyAction::MoveRight)])),
32 right.insert(0, KeyAction::MoveRight); 32 (KeyCode::Up, HashMap::from([(0, KeyAction::MoveUp)])),
33 map.insert(KeyCode::Right, right); 33 (KeyCode::Down, HashMap::from([(0, KeyAction::MoveDown)])),
34 34 // vim keybindings
35 let mut up = HashMap::new(); 35 (
36 up.insert(0, KeyAction::MoveUp); 36 KeyCode::Char('h'),
37 map.insert(KeyCode::Up, up); 37 HashMap::from([(0, KeyAction::MoveLeft)]),
38 38 ),
39 let mut down = HashMap::new(); 39 (
40 down.insert(0, KeyAction::MoveDown); 40 KeyCode::Char('j'),
41 map.insert(KeyCode::Down, down); 41 HashMap::from([(0, KeyAction::MoveDown)]),
42 42 ),
43 let mut enter = HashMap::new(); 43 (KeyCode::Char('k'), HashMap::from([(0, KeyAction::MoveUp)])),
44 enter.insert(0, KeyAction::Select); 44 (
45 map.insert(KeyCode::Enter, enter); 45 KeyCode::Char('l'),
46 46 HashMap::from([(0, KeyAction::MoveRight)]),
47 let mut escape = HashMap::new(); 47 ),
48 escape.insert(0, KeyAction::Deselect); 48 // functional keys
49 map.insert(KeyCode::Esc, escape); 49 (KeyCode::Enter, HashMap::from([(0, KeyAction::Select)])),
50 50 (KeyCode::Esc, HashMap::from([(0, KeyAction::Deselect)])),
51 let mut q = HashMap::new(); 51 (KeyCode::Char('q'), HashMap::from([(0, KeyAction::Exit)])),
52 q.insert(0, KeyAction::Exit); 52 (KeyCode::Char('r'), HashMap::from([(0, KeyAction::Reload)])),
53 map.insert(KeyCode::Char('q'), q); 53 // history
54 54 (KeyCode::Backspace, HashMap::from([(0, KeyAction::Back)])),
55 let mut backspace = HashMap::new(); 55 (KeyCode::End, HashMap::from([(0, KeyAction::ClearHistory)])),
56 backspace.insert(0, KeyAction::Back); 56 (KeyCode::Home, HashMap::from([(0, KeyAction::FirstHistory)])),
57 map.insert(KeyCode::Backspace, backspace); 57 ]))
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)
81 } 58 }
82} 59}
src/config/pages.rs +43 −4
@@ -1,6 +1,8 @@
1use crate::{ 1use crate::{
2 global::traits::ConfigTrait, 2 global::traits::ConfigTrait,
3 items::{ItemList, MessageBar, PageButton, SearchBar, SearchFilter, SingleItem}, 3 items::{
4 ChannelDisplay, ItemList, MessageBar, PageButton, SearchBar, SearchFilter, SingleItem,
5 },
4}; 6};
5use serde::{Deserialize, Serialize}; 7use serde::{Deserialize, Serialize};
6use std::slice; 8use std::slice;
@@ -35,6 +37,8 @@ pub struct PagesConfig {
35 pub search: PageConfig, 37 pub search: PageConfig,
36 #[serde(default = "singleitem_default")] 38 #[serde(default = "singleitem_default")]
37 pub singleitem: PageConfig, 39 pub singleitem: PageConfig,
40 #[serde(default = "channeldisplay_default")]
41 pub channeldisplay: PageConfig,
38} 42}
39 43
40impl Key for PagesConfig { 44impl Key for PagesConfig {
@@ -51,6 +55,7 @@ impl Default for PagesConfig {
51 main_menu: main_menu_default(), 55 main_menu: main_menu_default(),
52 search: search_default(), 56 search: search_default(),
53 singleitem: singleitem_default(), 57 singleitem: singleitem_default(),
58 channeldisplay: channeldisplay_default(),
54 } 59 }
55 } 60 }
56} 61}
@@ -158,6 +163,10 @@ pub enum PageItems {
158 Popular, 163 Popular,
159 SearchFilters, 164 SearchFilters,
160 SingleItemInfo, 165 SingleItemInfo,
166 ChannelDisplay,
167 ChannelMain,
168 ChannelVideos,
169 ChannelPlaylists,
161} 170}
162 171
163impl PageItems { 172impl PageItems {
@@ -171,15 +180,23 @@ impl PageItems {
171 Self::ItemList => Box::new(ItemList::default()), 180 Self::ItemList => Box::new(ItemList::default()),
172 Self::SearchFilters => Box::new(SearchFilter::default()), 181 Self::SearchFilters => Box::new(SearchFilter::default()),
173 Self::SingleItemInfo => Box::new(SingleItem::default()), 182 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),
174 } 187 }
175 } 188 }
176 189
177 pub fn width(&self) -> Constraint { 190 pub fn width(&self) -> Constraint {
178 match self { 191 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),
180 Self::SearchBar => Constraint::Min(16), 197 Self::SearchBar => Constraint::Min(16),
181 Self::MessageBar => Constraint::Min(3), 198 Self::MessageBar => Constraint::Min(3),
182 Self::ItemList | Self::SingleItemInfo => Constraint::Min(9), 199 Self::ItemList | Self::SingleItemInfo | Self::ChannelDisplay => Constraint::Min(9),
183 Self::SearchFilters => Constraint::Length(5), 200 Self::SearchFilters => Constraint::Length(5),
184 } 201 }
185 } 202 }
@@ -187,11 +204,14 @@ impl PageItems {
187 pub fn height(&self) -> Constraint { 204 pub fn height(&self) -> Constraint {
188 match self { 205 match self {
189 Self::Popular 206 Self::Popular
207 | Self::ChannelMain
208 | Self::ChannelVideos
209 | Self::ChannelPlaylists
190 | Self::Trending 210 | Self::Trending
191 | Self::MessageBar 211 | Self::MessageBar
192 | Self::SearchBar 212 | Self::SearchBar
193 | Self::SearchFilters => Constraint::Length(3), 213 | Self::SearchFilters => Constraint::Length(3),
194 Self::ItemList | Self::SingleItemInfo => Constraint::Min(6), 214 Self::ItemList | Self::SingleItemInfo | Self::ChannelDisplay => Constraint::Min(6),
195 } 215 }
196 } 216 }
197} 217}
@@ -253,3 +273,22 @@ fn singleitem_default() -> PageConfig {
253 message: String::from("Loading item details..."), 273 message: String::from("Loading item details..."),
254 } 274 }
255} 275}
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> {
31 url: fullplaylist.thumbnail_url.clone(), 31 url: fullplaylist.thumbnail_url.clone(),
32 id: fullplaylist.id.clone(), 32 id: fullplaylist.id.clone(),
33 }, 33 },
34 Item::FullChannel(fullchannel) => DownloadRequest {
35 url: fullchannel.thumbnail_url.clone(),
36 id: fullchannel.id.clone(),
37 },
34 Item::Unknown(_) => return None, 38 Item::Unknown(_) => return None,
35 }) 39 })
36 } 40 }
@@ -62,7 +66,7 @@ async fn download_all_images_async(downloads: Vec<DownloadRequest>) {
62 if !path.exists() { 66 if !path.exists() {
63 actions.push(download_single( 67 actions.push(download_single(
64 download.url, 68 download.url,
65 path.to_owned().into_os_string().into_string().unwrap(), 69 path.clone().into_os_string().into_string().unwrap(),
66 )); 70 ));
67 } 71 }
68 72
src/global/structs/item.rs +59 −2
@@ -1,7 +1,9 @@
1use crate::global::functions::{date_text, secs_display_string, viewcount_text}; 1use crate::global::functions::{date_text, secs_display_string, viewcount_text};
2use invidious::structs::{ 2use invidious::structs::{
3 channel::Channel,
3 hidden::{ 4 hidden::{
4 Playlist, PlaylistItem, PopularItem, SearchItem, SearchItemTransition, TrendingVideo, 5 ChannelVideo, Playlist, PlaylistItem, PopularItem, SearchItem, SearchItemTransition,
6 TrendingVideo,
5 }, 7 },
6 universal::Playlist as FullPlaylist, 8 universal::Playlist as FullPlaylist,
7 video::Video, 9 video::Video,
@@ -18,6 +20,7 @@ pub enum Item {
18 MiniChannel(MiniChannelItem), 20 MiniChannel(MiniChannelItem),
19 FullVideo(FullVideoItem), 21 FullVideo(FullVideoItem),
20 FullPlaylist(FullPlaylistItem), 22 FullPlaylist(FullPlaylistItem),
23 FullChannel(FullChannelItem),
21 Unknown(SearchItemTransition), 24 Unknown(SearchItemTransition),
22} 25}
23 26
@@ -85,6 +88,19 @@ pub struct FullPlaylistItem {
85 pub videos: Vec<Item>, 88 pub videos: Vec<Item>,
86} 89}
87 90
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
88impl Display for Item { 104impl Display for Item {
89 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 105 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
90 f.write_str(match self { 106 f.write_str(match self {
@@ -93,6 +109,7 @@ impl Display for Item {
93 Self::MiniChannel(channel) => &channel.name, 109 Self::MiniChannel(channel) => &channel.name,
94 Self::FullVideo(video) => &video.title, 110 Self::FullVideo(video) => &video.title,
95 Self::FullPlaylist(playlist) => &playlist.title, 111 Self::FullPlaylist(playlist) => &playlist.title,
112 Self::FullChannel(channel) => &channel.name,
96 Self::Unknown(_) => "Unknown item", 113 Self::Unknown(_) => "Unknown item",
97 }) 114 })
98 } 115 }
@@ -144,6 +161,7 @@ impl Item {
144 Self::MiniChannel(channel) => &channel.id, 161 Self::MiniChannel(channel) => &channel.id,
145 Self::FullVideo(video) => &video.id, 162 Self::FullVideo(video) => &video.id,
146 Self::FullPlaylist(playlist) => &playlist.id, 163 Self::FullPlaylist(playlist) => &playlist.id,
164 Self::FullChannel(channel) => &channel.id,
147 Self::Unknown(_) => "invalid", 165 Self::Unknown(_) => "invalid",
148 } 166 }
149 } 167 }
@@ -297,7 +315,7 @@ impl Item {
297 Self::MiniVideo(MiniVideoItem { 315 Self::MiniVideo(MiniVideoItem {
298 title: original.title, 316 title: original.title,
299 id: original.id, 317 id: original.id,
300 thumbnail_url: original.thumbnails[image_index].url.to_owned(), 318 thumbnail_url: original.thumbnails[image_index].url.clone(),
301 length: secs_display_string(original.length), 319 length: secs_display_string(original.length),
302 views: None, 320 views: None,
303 channel: original.author, 321 channel: original.author,
@@ -306,4 +324,43 @@ impl Item {
306 description: None, 324 description: None,
307 }) 325 })
308 } 326 }
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 }
309} 366}
src/global/structs/keyaction.rs +13
@@ -4,13 +4,26 @@ use serde::{Deserialize, Serialize};
4// Each key + modifier is bind to a key in a HashMap<KeyCode, HashMap<u8, KeyAction>> 4// Each key + modifier is bind to a key in a HashMap<KeyCode, HashMap<u8, KeyAction>>
5#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug)] 5#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug)]
6pub enum KeyAction { 6pub enum KeyAction {
7 /// Moves cursor to the left direction, or to the first item
7 MoveLeft, 8 MoveLeft,
9 /// Moves cursor to the right direction, or to the last item
8 MoveRight, 10 MoveRight,
11 /// Moves cursor up
9 MoveUp, 12 MoveUp,
13 /// Moves cursor dowm
10 MoveDown, 14 MoveDown,
15 /// select the current item
11 Select, 16 Select,
17 /// deselect the current item, reverts the cursor back to its hover state
12 Deselect, 18 Deselect,
19 /// exits/quits the entire app
13 Exit, 20 Exit,
21 /// revert last history
14 Back, 22 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
15 Reload, 28 Reload,
16} 29}
src/global/structs/page.rs +30 −3
@@ -6,11 +6,12 @@ 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, Eq)] 9#[derive(Clone, PartialEq)]
10pub enum Page { 10pub enum Page {
11 MainMenu(MainMenuPage), 11 MainMenu(MainMenuPage),
12 Search(Search), 12 Search(Search),
13 SingleItem(SingleItemPage), 13 SingleItem(SingleItemPage),
14 ChannelDisplay(ChannelDisplayPage),
14} 15}
15 16
16impl Debug for Page { 17impl Debug for Page {
@@ -21,11 +22,22 @@ impl Debug for Page {
21 Self::MainMenu(_) => "MainMenu", 22 Self::MainMenu(_) => "MainMenu",
22 Self::Search(_) => "Search", 23 Self::Search(_) => "Search",
23 Self::SingleItem(_) => "SingleItem", 24 Self::SingleItem(_) => "SingleItem",
25 Self::ChannelDisplay(_) => "ChannelDisplay",
24 } 26 }
25 )) 27 ))
26 } 28 }
27} 29}
28 30
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
29impl Default for Page { 41impl Default for Page {
30 fn default() -> Self { 42 fn default() -> Self {
31 Self::MainMenu(MainMenuPage::default()) 43 Self::MainMenu(MainMenuPage::default())
@@ -37,7 +49,7 @@ impl Key for Page {
37} 49}
38 50
39/// page variants for the main menu 51/// page variants for the main menu
40#[derive(Clone, PartialEq, Eq)] 52#[derive(Clone, Copy, PartialEq)]
41pub enum MainMenuPage { 53pub enum MainMenuPage {
42 Trending, 54 Trending,
43 Popular, 55 Popular,
@@ -49,8 +61,21 @@ impl Default for MainMenuPage {
49 } 61 }
50} 62}
51 63
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
52/// Different items to be displayed on a single item page 77/// Different items to be displayed on a single item page
53#[derive(Clone, PartialEq, Eq)] 78#[derive(Clone, PartialEq)]
54pub enum SingleItemPage { 79pub enum SingleItemPage {
55 Video(String), 80 Video(String),
56 Playlist(String), 81 Playlist(String),
@@ -63,6 +88,7 @@ impl Page {
63 Self::MainMenu(_) => pages_config.main_menu.clone(), 88 Self::MainMenu(_) => pages_config.main_menu.clone(),
64 Self::Search(_) => pages_config.search.clone(), 89 Self::Search(_) => pages_config.search.clone(),
65 Self::SingleItem(_) => pages_config.singleitem.clone(), 90 Self::SingleItem(_) => pages_config.singleitem.clone(),
91 Self::ChannelDisplay(_) => pages_config.channeldisplay.clone(),
66 } 92 }
67 } 93 }
68 94
@@ -73,6 +99,7 @@ impl Page {
73 Self::MainMenu(_) => pages_config.main_menu.message.clone(), 99 Self::MainMenu(_) => pages_config.main_menu.message.clone(),
74 Self::Search(_) => pages_config.search.message.clone(), 100 Self::Search(_) => pages_config.search.message.clone(),
75 Self::SingleItem(_) => pages_config.singleitem.message.clone(), 101 Self::SingleItem(_) => pages_config.singleitem.message.clone(),
102 Self::ChannelDisplay(_) => pages_config.channeldisplay.message.clone(),
76 } 103 }
77 } 104 }
78} 105}
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, Eq)] 22#[derive(Clone, PartialEq)]
23pub struct TaskQueue { 23pub struct TaskQueue {
24 pub render: RenderTask, 24 pub render: RenderTask,
25 pub reload: bool, 25 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 {
53 // entire page being taken up by the image 53 // entire page being taken up by the image
54 width: Some(if let Item::MiniChannel(_) = item { 54 width: Some(if let Item::MiniChannel(_) = item {
55 area.width / 2 55 area.width / 2
56 } else if let Item::FullChannel(_) = item {
57 area.width / 4
56 } else { 58 } else {
57 area.width 59 area.width
58 } as u32), 60 } as u32),
@@ -84,13 +86,13 @@ impl FrameworkItem for ItemInfo {
84 Style::default().fg(appearance.colors.item_info.tag), 86 Style::default().fg(appearance.colors.item_info.tag),
85 ), 87 ),
86 ( 88 (
87 minivideo.title.to_owned(), 89 minivideo.title.clone(),
88 Style::default().fg(appearance.colors.item_info.title), 90 Style::default().fg(appearance.colors.item_info.title),
89 ), 91 ),
90 ], 92 ],
91 minivideo.description.as_ref().map(|description| { 93 minivideo.description.as_ref().map(|description| {
92 ( 94 (
93 description.to_owned(), 95 description.clone(),
94 Style::default().fg(appearance.colors.item_info.description), 96 Style::default().fg(appearance.colors.item_info.description),
95 ) 97 )
96 }), 98 }),
@@ -125,7 +127,7 @@ impl FrameworkItem for ItemInfo {
125 Style::default().fg(appearance.colors.item_info.tag), 127 Style::default().fg(appearance.colors.item_info.tag),
126 ), 128 ),
127 ( 129 (
128 miniplaylist.title.to_owned(), 130 miniplaylist.title.clone(),
129 Style::default().fg(appearance.colors.item_info.title), 131 Style::default().fg(appearance.colors.item_info.title),
130 ), 132 ),
131 ( 133 (
@@ -154,7 +156,7 @@ impl FrameworkItem for ItemInfo {
154 Style::default().fg(appearance.colors.item_info.tag), 156 Style::default().fg(appearance.colors.item_info.tag),
155 ), 157 ),
156 ( 158 (
157 minichannel.name.to_owned(), 159 minichannel.name.clone(),
158 Style::default().fg(appearance.colors.item_info.title), 160 Style::default().fg(appearance.colors.item_info.title),
159 ), 161 ),
160 ( 162 (
@@ -179,7 +181,7 @@ impl FrameworkItem for ItemInfo {
179 ), 181 ),
180 ], 182 ],
181 Some(( 183 Some((
182 minichannel.description.to_owned(), 184 minichannel.description.clone(),
183 Style::default().fg(appearance.colors.item_info.description), 185 Style::default().fg(appearance.colors.item_info.description),
184 )), 186 )),
185 ), 187 ),
@@ -190,7 +192,7 @@ impl FrameworkItem for ItemInfo {
190 Style::default().fg(appearance.colors.item_info.tag), 192 Style::default().fg(appearance.colors.item_info.tag),
191 ), 193 ),
192 ( 194 (
193 fullvideo.title.to_owned(), 195 fullvideo.title.clone(),
194 Style::default().fg(appearance.colors.item_info.title), 196 Style::default().fg(appearance.colors.item_info.title),
195 ), 197 ),
196 ( 198 (
@@ -218,7 +220,7 @@ impl FrameworkItem for ItemInfo {
218 ), 220 ),
219 ], 221 ],
220 Some(( 222 Some((
221 fullvideo.description.to_owned(), 223 fullvideo.description.clone(),
222 Style::default().fg(appearance.colors.item_info.description), 224 Style::default().fg(appearance.colors.item_info.description),
223 )), 225 )),
224 ), 226 ),
@@ -229,7 +231,7 @@ impl FrameworkItem for ItemInfo {
229 Style::default().fg(appearance.colors.item_info.tag), 231 Style::default().fg(appearance.colors.item_info.tag),
230 ), 232 ),
231 ( 233 (
232 fullplaylist.title.to_owned(), 234 fullplaylist.title.clone(),
233 Style::default().fg(appearance.colors.item_info.title), 235 Style::default().fg(appearance.colors.item_info.title),
234 ), 236 ),
235 ( 237 (
@@ -250,7 +252,43 @@ impl FrameworkItem for ItemInfo {
250 ), 252 ),
251 ], 253 ],
252 Some(( 254 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(),
254 Style::default().fg(appearance.colors.item_info.description), 292 Style::default().fg(appearance.colors.item_info.description),
255 )), 293 )),
256 ), 294 ),
src/items/itemlist.rs +10 −4
@@ -12,8 +12,9 @@ use crate::{
12 global::{ 12 global::{
13 functions::download_all_images, 13 functions::download_all_images,
14 structs::{ 14 structs::{
15 FullPlaylistItem, FullVideoItem, InvidiousClient, Item, KeyAction, MainMenuPage, 15 ChannelDisplayPage, ChannelDisplayPageType, FullPlaylistItem, FullVideoItem,
16 MiniPlaylistItem, MiniVideoItem, Page, SingleItemPage, Task, Tasks, 16 InvidiousClient, Item, KeyAction, MainMenuPage, MiniChannelItem, MiniPlaylistItem,
17 MiniVideoItem, Page, SingleItemPage, Task, Tasks,
17 }, 18 },
18 }, 19 },
19}; 20};
@@ -99,7 +100,7 @@ impl FrameworkItem for ItemList {
99 100
100 // creates the grid 101 // creates the grid
101 let grid = self.grid.clone(); 102 let grid = self.grid.clone();
102 let chunks = grid.chunks(area).unwrap()[0].to_owned(); 103 let chunks = grid.chunks(area).unwrap()[0].clone();
103 104
104 // creates the text list in cell (0, 1) 105 // creates the text list in cell (0, 1)
105 self.textlist.set_height(chunks[0].height); 106 self.textlist.set_height(chunks[0].height);
@@ -227,7 +228,12 @@ impl FrameworkItem for ItemList {
227 | Item::FullPlaylist(FullPlaylistItem { id, .. }) => { 228 | Item::FullPlaylist(FullPlaylistItem { id, .. }) => {
228 Page::SingleItem(SingleItemPage::Playlist(id.clone())) 229 Page::SingleItem(SingleItemPage::Playlist(id.clone()))
229 } 230 }
230 Item::MiniChannel(_) => unimplemented!(), 231 Item::MiniChannel(MiniChannelItem { id, .. }) => {
232 Page::ChannelDisplay(ChannelDisplayPage {
233 id: id.clone(),
234 r#type: ChannelDisplayPageType::Main,
235 })
236 }
231 _ => panic!("wtf did you just selected"), 237 _ => panic!("wtf did you just selected"),
232 }; 238 };
233 framework 239 framework
src/items/mod.rs +2
@@ -13,3 +13,5 @@ mod searchfilters;
13pub use searchfilters::*; 13pub use searchfilters::*;
14mod singleitem; 14mod singleitem;
15pub use singleitem::*; 15pub use singleitem::*;
16mod channeldisplay;
17pub use channeldisplay::*;
src/items/pagebutton.rs +28 −4
@@ -1,6 +1,8 @@
1use crate::{ 1use crate::{
2 config::AppearanceConfig, 2 config::AppearanceConfig,
3 global::structs::{MainMenuPage, Page, Task, Tasks}, 3 global::structs::{
4 ChannelDisplayPage, ChannelDisplayPageType, MainMenuPage, Page, Task, Tasks,
5 },
4}; 6};
5use tui::{ 7use tui::{
6 layout::Alignment, 8 layout::Alignment,
@@ -14,13 +16,28 @@ use tui_additions::framework::FrameworkItem;
14pub enum PageButton { 16pub enum PageButton {
15 Trending, 17 Trending,
16 Popular, 18 Popular,
19 ChannelMain,
20 ChannelVideos,
21 ChannelPlaylists,
17} 22}
18 23
19impl PageButton { 24impl PageButton {
20 pub fn page(&self) -> Page { 25 pub fn page(&self, current_page: &Page) -> Page {
21 match self { 26 match self {
22 Self::Trending => Page::MainMenu(MainMenuPage::Trending), 27 Self::Trending => Page::MainMenu(MainMenuPage::Trending),
23 Self::Popular => Page::MainMenu(MainMenuPage::Popular), 28 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 }),
24 } 41 }
25 } 42 }
26} 43}
@@ -30,6 +47,9 @@ impl ToString for PageButton {
30 match self { 47 match self {
31 Self::Popular => String::from("Popular"), 48 Self::Popular => String::from("Popular"),
32 Self::Trending => String::from("Trending"), 49 Self::Trending => String::from("Trending"),
50 Self::ChannelMain => String::from("Main"),
51 Self::ChannelVideos => String::from("Videos"),
52 Self::ChannelPlaylists => String::from("Playlists"),
33 } 53 }
34 } 54 }
35} 55}
@@ -49,7 +69,8 @@ impl FrameworkItem for PageButton {
49 } 69 }
50 70
51 let appearance = framework.data.global.get::<AppearanceConfig>().unwrap(); 71 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();
53 74
54 let block = Block::default() 75 let block = Block::default()
55 .border_type(appearance.borders) 76 .border_type(appearance.borders)
@@ -70,8 +91,11 @@ impl FrameworkItem for PageButton {
70 91
71 // when selected creates a load page task, but returns false to show that it is not being selected 92 // when selected creates a load page task, but returns false to show that it is not being selected
72 fn select(&mut self, framework: &mut tui_additions::framework::FrameworkClean) -> bool { 93 fn select(&mut self, framework: &mut tui_additions::framework::FrameworkClean) -> bool {
94 let current_page = framework.data.state.get::<Page>().unwrap().clone();
73 let tasks = framework.data.state.get_mut::<Tasks>().unwrap(); 95 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)));
75 99
76 false 100 false
77 } 101 }
src/items/singleitem.rs +1 −1
@@ -404,7 +404,7 @@ impl FrameworkItem for SingleItem {
404 let appearance = framework.data.global.get::<AppearanceConfig>().unwrap(); 404 let appearance = framework.data.global.get::<AppearanceConfig>().unwrap();
405 self.update_appearance(appearance, &info); 405 self.update_appearance(appearance, &info);
406 406
407 let chunks = self.grid.chunks(area).unwrap()[0].to_owned(); 407 let chunks = self.grid.chunks(area).unwrap()[0].clone();
408 408
409 frame.render_widget(self.grid.clone(), area); 409 frame.render_widget(self.grid.clone(), area);
410 410
src/run.rs +28
@@ -100,6 +100,34 @@ pub fn run(
100 .push(Task::ClearPage); 100 .push(Task::ClearPage);
101 } 101 }
102 } 102 }
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 }
103 KeyAction::Select => { 131 KeyAction::Select => {
104 let _ = framework.select(); 132 let _ = framework.select();
105 } 133 }