Commit ddb15ba639

ddb15ba639bedeb51a949e00019f20823aae8c6b

parent: 4cc2206d3e

Unsigned

Siriusmart <71584876+Siriusmart@users.noreply.github.com> · 2022-07-14 18:00 UTC

v0.4.4

Layout: unified · split

Cargo.lock +1 −1
@@ -1716,7 +1716,7 @@ dependencies = [
1716 1716
1717[[package]] 1717[[package]]
1718name = "youtube-tui" 1718name = "youtube-tui"
1719version = "0.4.2" 1719version = "0.4.4"
1720dependencies = [ 1720dependencies = [
1721 "chrono", 1721 "chrono",
1722 "crossterm", 1722 "crossterm",
Cargo.toml +1 −1
@@ -1,6 +1,6 @@
1[package] 1[package]
2name = "youtube-tui" 2name = "youtube-tui"
3version = "0.4.3" 3version = "0.4.4"
4edition = "2021" 4edition = "2021"
5authors = ["Siriusmart <siriusmart@tuta.io>"] 5authors = ["Siriusmart <siriusmart@tuta.io>"]
6description = "An aesthetically pleasing YouTube TUI written in Rust" 6description = "An aesthetically pleasing YouTube TUI written in Rust"
README.md +11 −8
@@ -20,13 +20,17 @@ This program is being actively developed and there will be new features coming u
20 20
21[YouTube TUI user manual](https://siriusmart.github.io/youtube-tui) 21[YouTube TUI user manual](https://siriusmart.github.io/youtube-tui)
22 22
23> ### What's new in this commit 23## Chnagelogs
24> 24
25> * Refresh pages 25#### Added
26> * Fixed cache not being cleared after exit 26
27> * Key modifiers for key bindings 27* Added default select item for each page (can be changed in `layouts.yml`)
28> * Image loading can be disabled in main config 28
29#### Fixes
29 30
31* Video list view in playlists not working
32* Channel view scroll causes panic
33* Search options gray backgound + image covering popup
30 34
31## Installation 35## Installation
32 36
@@ -91,10 +95,9 @@ Here's the [opened issue](https://github.com/iv-org/invidious/issues/3154)
91 95
92## Todo (First piority on top) 96## Todo (First piority on top)
93 97
94* Put hard coded options into config files
95* User manual + documentations
96* Go directly to a page by URL 98* Go directly to a page by URL
97* Vim-like commands in status bar 99* Vim-like commands in status bar
100* Save as local playlist/video
98* Command line launch options 101* Command line launch options
99* Channel search and channel video sort 102* Channel search and channel video sort
100* Recommended videos 103* Recommended videos
src/app/app.rs +43 −7
@@ -1,7 +1,7 @@
1use std::collections::LinkedList; 1use std::collections::LinkedList;
2 2
3use crate::{ 3use crate::{
4 structs::{AppHistory, Item, Page, SearchSettings, State, WatchHistory}, 4 structs::{AppHistory, Item, Page, SearchSettings, State, WatchHistory, MessageText},
5 traits::ItemTrait, 5 traits::ItemTrait,
6}; 6};
7use crossterm::event::KeyEvent; 7use crossterm::event::KeyEvent;
@@ -14,7 +14,7 @@ use tui::{
14 Frame, 14 Frame,
15}; 15};
16 16
17use super::config::{Action, Config}; 17use super::config::{Action, Config, LayoutConfig};
18 18
19#[derive(Clone)] 19#[derive(Clone)]
20pub struct App { 20pub struct App {
@@ -25,7 +25,7 @@ pub struct App {
25 pub hover: Option<(usize, usize)>, // x, y 25 pub hover: Option<(usize, usize)>, // x, y
26 pub selected: Option<(usize, usize)>, 26 pub selected: Option<(usize, usize)>,
27 pub client: Client, 27 pub client: Client,
28 pub message: Option<String>, 28 pub message: MessageText,
29 pub load: bool, 29 pub load: bool,
30 pub render: bool, 30 pub render: bool,
31 pub popup_focus: bool, 31 pub popup_focus: bool,
@@ -35,6 +35,7 @@ pub struct App {
35 pub search_text: String, 35 pub search_text: String,
36 pub search_index: usize, 36 pub search_index: usize,
37 pub page_no: usize, 37 pub page_no: usize,
38 pub term_clear: bool,
38} 39}
39 40
40pub struct AppNoState { 41pub struct AppNoState {
@@ -44,7 +45,7 @@ pub struct AppNoState {
44 pub hover: Option<(usize, usize)>, // x, y 45 pub hover: Option<(usize, usize)>, // x, y
45 pub selected: Option<(usize, usize)>, 46 pub selected: Option<(usize, usize)>,
46 pub client: Client, 47 pub client: Client,
47 pub message: Option<String>, 48 pub message: MessageText,
48 pub load: bool, 49 pub load: bool,
49 pub render: bool, 50 pub render: bool,
50 pub popup_focus: bool, 51 pub popup_focus: bool,
@@ -54,6 +55,7 @@ pub struct AppNoState {
54 pub search_text: String, 55 pub search_text: String,
55 pub search_index: usize, 56 pub search_index: usize,
56 pub page_no: usize, 57 pub page_no: usize,
58 pub term_clear: bool,
57} 59}
58 60
59impl AppNoState { 61impl AppNoState {
@@ -75,6 +77,7 @@ impl AppNoState {
75 search_text: app.search_text, 77 search_text: app.search_text,
76 search_index: app.search_index, 78 search_index: app.search_index,
77 page_no: app.page_no, 79 page_no: app.page_no,
80 term_clear: app.term_clear,
78 }; 81 };
79 (out, app.state) 82 (out, app.state)
80 } 83 }
@@ -98,6 +101,7 @@ impl AppNoState {
98 search_index: app.search_index, 101 search_index: app.search_index,
99 page_no: app.page_no, 102 page_no: app.page_no,
100 state, 103 state,
104 term_clear: app.term_clear,
101 } 105 }
102 } 106 }
103} 107}
@@ -114,7 +118,7 @@ impl Default for App {
114 client: Client::new(config.main.server_url.clone()), 118 client: Client::new(config.main.server_url.clone()),
115 selected: None, 119 selected: None,
116 hover: None, 120 hover: None,
117 message: None, 121 message: MessageText::None,
118 load: true, 122 load: true,
119 render: true, 123 render: true,
120 popup_focus: false, 124 popup_focus: false,
@@ -125,6 +129,7 @@ impl Default for App {
125 search_text: String::new(), 129 search_text: String::new(),
126 search_index: 0, 130 search_index: 0,
127 page_no: 1, 131 page_no: 1,
132 term_clear: false,
128 } 133 }
129 } 134 }
130} 135}
@@ -179,6 +184,7 @@ impl App {
179 Action::Refresh => { 184 Action::Refresh => {
180 self.state.reset(); 185 self.state.reset();
181 self.load = true; 186 self.load = true;
187 self.render = true;
182 } 188 }
183 Action::Select => { 189 Action::Select => {
184 if self.hover.is_some() && self.selected.is_none() { 190 if self.hover.is_some() && self.selected.is_none() {
@@ -199,6 +205,8 @@ impl App {
199 self.selected = Some((x, y)); 205 self.selected = Some((x, y));
200 } 206 }
201 207
208 self.render = true;
209
202 return self; 210 return self;
203 } 211 }
204 } 212 }
@@ -206,6 +214,7 @@ impl App {
206 if self.selected.is_some() { 214 if self.selected.is_some() {
207 self.selected = None; 215 self.selected = None;
208 self.popup_focus = false; 216 self.popup_focus = false;
217 self.render = true;
209 return self; 218 return self;
210 } 219 }
211 } 220 }
@@ -217,6 +226,7 @@ impl App {
217 Some((x, y)) => match action { 226 Some((x, y)) => match action {
218 Action::Up => { 227 Action::Up => {
219 if *y > 0 { 228 if *y > 0 {
229 self.render = true;
220 let temp_y = *y - 1; 230 let temp_y = *y - 1;
221 if *x > self.selectable[temp_y].len() { 231 if *x > self.selectable[temp_y].len() {
222 let temp_x = self.selectable[temp_y].len(); 232 let temp_x = self.selectable[temp_y].len();
@@ -232,6 +242,7 @@ impl App {
232 } 242 }
233 Action::Down => { 243 Action::Down => {
234 if *y < self.selectable.len() - 1 { 244 if *y < self.selectable.len() - 1 {
245 self.render = true;
235 *y += 1; 246 *y += 1;
236 if *x > self.selectable[*y].len() - 1 { 247 if *x > self.selectable[*y].len() - 1 {
237 *x = self.selectable[*y].len() - 1; 248 *x = self.selectable[*y].len() - 1;
@@ -241,12 +252,14 @@ impl App {
241 252
242 Action::Left => { 253 Action::Left => {
243 if *x > 0 { 254 if *x > 0 {
255 self.render = true;
244 *x -= 1; 256 *x -= 1;
245 } 257 }
246 } 258 }
247 259
248 Action::Right => { 260 Action::Right => {
249 if *x < self.selectable[*y].len() - 1 { 261 if *x < self.selectable[*y].len() - 1 {
262 self.render = true;
250 *x += 1; 263 *x += 1;
251 } 264 }
252 } 265 }
@@ -255,15 +268,19 @@ impl App {
255 }, 268 },
256 None => match action { 269 None => match action {
257 Action::Up => { 270 Action::Up => {
271 self.render = true;
258 self.hover = Some((0, 0)); 272 self.hover = Some((0, 0));
259 } 273 }
260 Action::Down => { 274 Action::Down => {
275 self.render = true;
261 self.hover = Some((0, self.selectable.len() - 1)); 276 self.hover = Some((0, self.selectable.len() - 1));
262 } 277 }
263 Action::Left => { 278 Action::Left => {
279 self.render = true;
264 self.hover = Some((0, 0)); 280 self.hover = Some((0, 0));
265 } 281 }
266 Action::Right => { 282 Action::Right => {
283 self.render = true;
267 self.hover = Some((0, self.selectable.len() - 1)); 284 self.hover = Some((0, self.selectable.len() - 1));
268 } 285 }
269 _ => {} 286 _ => {}
@@ -351,6 +368,7 @@ impl App {
351 368
352 frame.render_widget(Block::default(), chunks.next().unwrap()); 369 frame.render_widget(Block::default(), chunks.next().unwrap());
353 370
371 let popup_focus = app.popup_focus;
354 for (x, (chunk, item)) in chunks 372 for (x, (chunk, item)) in chunks
355 .zip(row.items.iter_mut().map(|i| &mut i.item)) 373 .zip(row.items.iter_mut().map(|i| &mut i.item))
356 .enumerate() 374 .enumerate()
@@ -358,7 +376,6 @@ impl App {
358 let selected = app.selected == Some((x, y)); 376 let selected = app.selected == Some((x, y));
359 377
360 let hover = hover_selected == Some((x, y)); 378 let hover = hover_selected == Some((x, y));
361 let popup_focus = app.popup_focus;
362 379
363 let hold = item.render_item(frame, chunk, app, selected, hover, popup_focus, false); 380 let hold = item.render_item(frame, chunk, app, selected, hover, popup_focus, false);
364 381
@@ -381,7 +398,7 @@ impl App {
381 398
382 pub fn pop(mut self) -> (App, bool) { 399 pub fn pop(mut self) -> (App, bool) {
383 if self.history.len() == 0 { 400 if self.history.len() == 0 {
384 self.message = Some(String::from("This is the beginning of history")); 401 self.message = MessageText::Text(String::from("This is the beginning of history"));
385 return (self, false); 402 return (self, false);
386 } 403 }
387 404
@@ -405,6 +422,7 @@ impl App {
405 search_text: app_history.search_text, 422 search_text: app_history.search_text,
406 search_index: app_history.search_index, 423 search_index: app_history.search_index,
407 page_no: app_history.page_no, 424 page_no: app_history.page_no,
425 term_clear: false,
408 }; 426 };
409 427
410 (self, true) 428 (self, true)
@@ -413,4 +431,22 @@ impl App {
413 pub fn home(&mut self) { 431 pub fn home(&mut self) {
414 *self = App::default(); 432 *self = App::default();
415 } 433 }
434
435 pub fn page_layout(&self) -> LayoutConfig {
436 match self.page {
437 Page::Search => self.config.layouts.search.clone(),
438 Page::MainMenu(_) => self.config.layouts.main_menu.clone(),
439 Page::ItemDisplay(_) => self.config.layouts.item_info.clone(),
440 Page::Channel(_, _) => self.config.layouts.channel.clone(),
441 }
442 }
443
444 pub fn page_default(&self) -> Option<(usize, usize)> {
445 match self.page {
446 Page::Search => self.config.layouts.search.def_selected,
447 Page::MainMenu(_) => self.config.layouts.main_menu.def_selected,
448 Page::ItemDisplay(_) => self.config.layouts.item_info.def_selected,
449 Page::Channel(_, _) => self.config.layouts.channel.def_selected,
450 }
451 }
416} 452}
src/app/config/layouts.rs +1
@@ -62,6 +62,7 @@ pub struct LayoutConfig {
62 pub layout: Vec<RowTransitional>, 62 pub layout: Vec<RowTransitional>,
63 pub min: (u16, u16), 63 pub min: (u16, u16),
64 pub message: String, 64 pub message: String,
65 pub def_selected: Option<(usize, usize)>,
65} 66}
66 67
67impl Into<State> for LayoutConfig { 68impl Into<State> for LayoutConfig {
src/app/config/main.rs +1 −1
@@ -8,7 +8,7 @@ fn max_watch_history_default() -> usize {
8} 8}
9 9
10fn server_url_default() -> String { 10fn server_url_default() -> String {
11 String::from("https://vid.puffyan.us") 11 String::from("https://invidious.flokinet.to")
12} 12}
13 13
14fn env_default() -> HashMap<String, String> { 14fn env_default() -> HashMap<String, String> {
src/app/pages/channel.rs +10 −3
@@ -133,7 +133,7 @@ impl ItemTrait for ChannelItem {
133 selected: bool, 133 selected: bool,
134 hover: bool, 134 hover: bool,
135 popup_focus: bool, 135 popup_focus: bool,
136 _: bool, 136 popup_render: bool,
137 ) -> (bool, AppNoState) { 137 ) -> (bool, AppNoState) {
138 let mut out = (false, app); 138 let mut out = (false, app);
139 139
@@ -163,12 +163,15 @@ impl ItemTrait for ChannelItem {
163 163
164 let inner = block.inner(rect); 164 let inner = block.inner(rect);
165 frame.render_widget(block, rect); 165 frame.render_widget(block, rect);
166 if !popup_render {
166 frame.render_widget( 167 frame.render_widget(
167 ItemDisplay { 168 ItemDisplay {
168 item: ListItem::FullChannel(channel.clone()), 169 item: ListItem::FullChannel(channel.clone()),
170 render_image: !popup_focus,
169 }, 171 },
170 inner, 172 inner,
171 ); 173 );
174 }
172 } 175 }
173 ChannelDisplayItem::Videos(videos, textlist) => { 176 ChannelDisplayItem::Videos(videos, textlist) => {
174 let split = HorizontalSplit::default() 177 let split = HorizontalSplit::default()
@@ -209,10 +212,11 @@ impl ItemTrait for ChannelItem {
209 } 212 }
210 213
211 if let Some(item) = videos.iter().nth(textlist.selected) { 214 if let Some(item) = videos.iter().nth(textlist.selected) {
212 if !popup_focus { 215 if !popup_render {
213 frame.render_widget( 216 frame.render_widget(
214 ItemDisplay { 217 ItemDisplay {
215 item: ListItem::MiniVideo(item.clone()), 218 item: ListItem::MiniVideo(item.clone()),
219 render_image: !popup_focus,
216 }, 220 },
217 chunks[1], 221 chunks[1],
218 ); 222 );
@@ -251,6 +255,7 @@ impl ItemTrait for ChannelItem {
251 frame.render_widget( 255 frame.render_widget(
252 ItemDisplay { 256 ItemDisplay {
253 item: ListItem::MiniPlayList(item.clone()), 257 item: ListItem::MiniPlayList(item.clone()),
258 render_image: !popup_focus,
254 }, 259 },
255 chunks[1], 260 chunks[1],
256 ); 261 );
@@ -351,8 +356,9 @@ impl ItemTrait for ChannelItem {
351 _ => {} 356 _ => {}
352 }, 357 },
353 358
359 ChannelDisplayItem::Home(_) => {},
354 _ => unreachable!(), 360 _ => unreachable!(),
355 }, 361 },
356 _ => { 362 _ => {
357 unreachable!() 363 unreachable!()
358 } 364 }
@@ -460,6 +466,7 @@ impl PageTrait for Channel {
460 ], 466 ],
461 min: (46, 15), 467 min: (46, 15),
462 message: String::from("Loading channel info..."), 468 message: String::from("Loading channel info..."),
469 def_selected: None,
463 } 470 }
464 } 471 }
465} 472}
src/app/pages/global.rs +17 −11
@@ -6,16 +6,16 @@ use tui::{
6 backend::Backend, 6 backend::Backend,
7 layout::{Alignment, Rect}, 7 layout::{Alignment, Rect},
8 style::{Color, Style}, 8 style::{Color, Style},
9 widgets::{Block, BorderType, Borders, Clear, Paragraph}, 9 widgets::{Block, BorderType, Borders, Paragraph, Clear},
10 Frame, 10 Frame,
11}; 11};
12 12
13use crate::{ 13use crate::{
14 app::app::{App, AppNoState}, 14 app::app::{App, AppNoState},
15 functions::center_rect, 15 functions::center_rect,
16 structs::{Item, Page, WatchHistory}, 16 structs::{Item, Page, WatchHistory, MessageText},
17 traits::ItemTrait, 17 traits::ItemTrait,
18 widgets::{force_clear::ForceClear, horizontal_split::HorizontalSplit}, 18 widgets::{ horizontal_split::HorizontalSplit},
19}; 19};
20 20
21#[derive(Debug, Clone, Serialize, Deserialize)] 21#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -55,9 +55,10 @@ impl ItemTrait for GlobalItem {
55 GlobalItem::SearchBar => true, 55 GlobalItem::SearchBar => true,
56 GlobalItem::SearchSettings => { 56 GlobalItem::SearchSettings => {
57 app.popup_focus = true; 57 app.popup_focus = true;
58 app.term_clear = true;
58 true 59 true
59 } 60 }
60 _ => false, 61 GlobalItem::MessageBar => unreachable!()
61 }; 62 };
62 63
63 (app, selected) 64 (app, selected)
@@ -74,11 +75,13 @@ impl ItemTrait for GlobalItem {
74 match self { 75 match self {
75 GlobalItem::SearchBar => match key.code { 76 GlobalItem::SearchBar => match key.code {
76 KeyCode::Char(c) => { 77 KeyCode::Char(c) => {
78 app.render = true;
77 app.search_text.insert(app.search_index, c); 79 app.search_text.insert(app.search_index, c);
78 app.search_index += 1; 80 app.search_index += 1;
79 } 81 }
80 KeyCode::Backspace => { 82 KeyCode::Backspace => {
81 if app.search_index != 0 && app.search_text.len() != 0 { 83 if app.search_index != 0 && app.search_text.len() != 0 {
84 app.render = true;
82 app.search_text = format!( 85 app.search_text = format!(
83 "{}{}", 86 "{}{}",
84 &app.search_text[0..app.search_index - 1], 87 &app.search_text[0..app.search_index - 1],
@@ -89,17 +92,20 @@ impl ItemTrait for GlobalItem {
89 } 92 }
90 KeyCode::Left => { 93 KeyCode::Left => {
91 if app.search_index > 0 { 94 if app.search_index > 0 {
95 app.render = true;
92 app.search_index -= 1; 96 app.search_index -= 1;
93 } 97 }
94 } 98 }
95 KeyCode::Right => { 99 KeyCode::Right => {
96 if app.search_index < app.search_text.len() { 100 if app.search_index < app.search_text.len() {
101 app.render = true;
97 app.search_index += 1; 102 app.search_index += 1;
98 } 103 }
99 } 104 }
100 KeyCode::Enter => { 105 KeyCode::Enter => {
106 app.render = true;
101 if app.search_text.len() == 0 { 107 if app.search_text.len() == 0 {
102 app.message = Some(String::from("Search term cannot be empty")); 108 app.message = MessageText::Text(String::from("Search term cannot be empty"));
103 } else { 109 } else {
104 let state = app.config.layouts.search.clone().into(); 110 let state = app.config.layouts.search.clone().into();
105 let mut history = app.history.clone(); 111 let mut history = app.history.clone();
@@ -181,7 +187,7 @@ impl ItemTrait for GlobalItem {
181 Color::Reset 187 Color::Reset
182 })); 188 }));
183 let paragraph = 189 let paragraph =
184 Paragraph::new(message.clone().unwrap_or(String::from("All good :)"))) 190 Paragraph::new(message.clone().to_string())
185 .block(block); 191 .block(block);
186 frame.render_widget(paragraph, rect); 192 frame.render_widget(paragraph, rect);
187 } 193 }
@@ -240,6 +246,9 @@ impl ItemTrait for GlobalItem {
240 .selected_style(Style::default().fg(Color::LightRed)); 246 .selected_style(Style::default().fg(Color::LightRed));
241 } 247 }
242 248
249 frame.render_widget(Clear, chunks[0]);
250 frame.render_widget(Clear, chunks[1]);
251
243 frame.render_widget( 252 frame.render_widget(
244 out.1.search_settings.text_list.clone(), 253 out.1.search_settings.text_list.clone(),
245 chunks[0], 254 chunks[0],
@@ -252,12 +261,9 @@ impl ItemTrait for GlobalItem {
252 chunks[1], 261 chunks[1],
253 ); 262 );
254 263
255 frame.render_widget(ForceClear, chunks[0]);
256
257 frame.render_widget(ForceClear, chunks[1]);
258 } 264 }
259 Err(rect) => { 265 Err(_) => {
260 frame.render_widget(Clear, rect); 266 out.1.message = MessageText::Text(String::from("Screen too small"));
261 } 267 }
262 } 268 }
263 //panic!("{:?}", rect); 269 //panic!("{:?}", rect);
src/app/pages/item_info.rs +14 −10
@@ -10,7 +10,7 @@ use crate::{
10 pages::{channel::*, global::*}, 10 pages::{channel::*, global::*},
11 }, 11 },
12 functions::download_all_thumbnails, 12 functions::download_all_thumbnails,
13 structs::{FullPlayList, FullVideo, Item, ListItem, Page, WatchHistory}, 13 structs::{FullPlayList, FullVideo, Item, ListItem, Page, WatchHistory, MessageText},
14 traits::{ItemTrait, PageTrait}, 14 traits::{ItemTrait, PageTrait},
15 widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList}, 15 widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList},
16}; 16};
@@ -133,14 +133,14 @@ impl ItemTrait for ItemInfoItem {
133 133
134 match command.run_command(&env) { 134 match command.run_command(&env) {
135 Some(e) => { 135 Some(e) => {
136 app.message = Some(format!("Unknown variable `{}`", e)) 136 app.message = MessageText::Text(format!("Unknown variable `{}`", e))
137 } 137 }
138 None => app.message = Some(command.message.clone()), 138 None => app.message = MessageText::Text(command.message.clone()),
139 } 139 }
140 } 140 }
141 None => { 141 None => {
142 app.message = 142 app.message =
143 Some(format!("Unkown command `{}`", &command.command)); 143 MessageText::Text(format!("Unkown command `{}`", &command.command));
144 } 144 }
145 }; 145 };
146 } 146 }
@@ -204,14 +204,14 @@ impl ItemTrait for ItemInfoItem {
204 match command.run_command(&env) { 204 match command.run_command(&env) {
205 Some(e) => { 205 Some(e) => {
206 app.message = 206 app.message =
207 Some(format!("Unknown variable `{}`", e)) 207 MessageText::Text(format!("Unknown variable `{}`", e))
208 } 208 }
209 None => app.message = Some(command.message.clone()), 209 None => app.message = MessageText::Text(command.message.clone()),
210 } 210 }
211 } 211 }
212 None => { 212 None => {
213 app.message = 213 app.message =
214 Some(format!("Unkown command `{}`", &command.command)); 214 MessageText::Text(format!("Unkown command `{}`", &command.command));
215 } 215 }
216 }; 216 };
217 } 217 }
@@ -231,7 +231,7 @@ impl ItemTrait for ItemInfoItem {
231 } 231 }
232 232
233 x => { 233 x => {
234 let state = app.config.layouts.channel.clone().into(); 234 let state = app.config.layouts.item_info.clone().into();
235 let mut history = app.history.clone(); 235 let mut history = app.history.clone();
236 history.push(app.into()); 236 history.push(app.into());
237 237
@@ -270,6 +270,7 @@ impl ItemTrait for ItemInfoItem {
270 match &app.page { 270 match &app.page {
271 Page::ItemDisplay(display_item) => match display_item { 271 Page::ItemDisplay(display_item) => match display_item {
272 DisplayItem::Video(id) => { 272 DisplayItem::Video(id) => {
273 // panic!("Got here");
273 let mut list = TextList::default(); 274 let mut list = TextList::default();
274 let video: FullVideo = app.client.video(id, None)?.into(); 275 let video: FullVideo = app.client.video(id, None)?.into();
275 if app.config.main.display_thumbnails { 276 if app.config.main.display_thumbnails {
@@ -405,9 +406,10 @@ impl ItemTrait for ItemInfoItem {
405 406
406 frame.render_widget(split, rect); 407 frame.render_widget(split, rect);
407 408
408 if !popup_focus { 409 if !popup_render {
409 let item_display = ItemDisplay { 410 let item_display = ItemDisplay {
410 item: ListItem::FullVideo(videoinfo.video.clone()), 411 item: ListItem::FullVideo(videoinfo.video.clone()),
412 render_image: !popup_focus,
411 }; 413 };
412 414
413 frame.render_widget(item_display, chunks[0]); 415 frame.render_widget(item_display, chunks[0]);
@@ -431,9 +433,10 @@ impl ItemTrait for ItemInfoItem {
431 433
432 frame.render_widget(split, rect); 434 frame.render_widget(split, rect);
433 435
434 if !popup_focus { 436 if !popup_render {
435 let item_display = ItemDisplay { 437 let item_display = ItemDisplay {
436 item: ListItem::FullPlayList(playlistinfo.playlist.clone()), 438 item: ListItem::FullPlayList(playlistinfo.playlist.clone()),
439 render_image: !popup_focus,
437 }; 440 };
438 441
439 frame.render_widget(item_display, chunks[0]); 442 frame.render_widget(item_display, chunks[0]);
@@ -536,6 +539,7 @@ impl PageTrait for ItemInfo {
536 ], 539 ],
537 min: (21, 12), 540 min: (21, 12),
538 message: String::from("Loading item info..."), 541 message: String::from("Loading item info..."),
542 def_selected: Some((0,1)),
539 } 543 }
540 } 544 }
541} 545}
src/app/pages/main_menu.rs +3 −2
@@ -209,8 +209,8 @@ impl ItemTrait for MainMenuItem {
209 } 209 }
210 210
211 if let Some(item) = videos.iter().nth(list.selected) { 211 if let Some(item) = videos.iter().nth(list.selected) {
212 if !popup_focus { 212 if !popup_render {
213 frame.render_widget(ItemDisplay { item: item.clone() }, chunks[1]); 213 frame.render_widget(ItemDisplay { item: item.clone(), render_image: !popup_focus }, chunks[1]);
214 } 214 }
215 } 215 }
216 216
@@ -387,6 +387,7 @@ impl PageTrait for MainMenu {
387 ], 387 ],
388 min: (45, 15), 388 min: (45, 15),
389 message: String::from("Loading home page..."), 389 message: String::from("Loading home page..."),
390 def_selected: None,
390 } 391 }
391 } 392 }
392} 393}
src/app/pages/search.rs +3 −2
@@ -324,8 +324,8 @@ impl ItemTrait for SearchItem {
324 324
325 if let Some(result) = results { 325 if let Some(result) = results {
326 if let Some(item) = result.iter().nth(text_list.selected) { 326 if let Some(item) = result.iter().nth(text_list.selected) {
327 if !popup_focus { 327 if !popup_render {
328 frame.render_widget(ItemDisplay { item: item.clone() }, chunks[1]); 328 frame.render_widget(ItemDisplay { item: item.clone(), render_image: !popup_focus }, chunks[1]);
329 } 329 }
330 } 330 }
331 } 331 }
@@ -383,6 +383,7 @@ impl PageTrait for Search {
383 ], 383 ],
384 min: (45, 12), 384 min: (45, 12),
385 message: String::from("Loading search results..."), 385 message: String::from("Loading search results..."),
386 def_selected: Some((0,1)),
386 } 387 }
387 } 388 }
388} 389}
src/main.rs +15 −4
@@ -10,7 +10,7 @@ use tui::{
10}; 10};
11use youtube_tui::{ 11use youtube_tui::{
12 app::{app::App, config::Action}, 12 app::{app::App, config::Action},
13 structs::{Row, RowItem, State}, 13 structs::{Row, RowItem, State, MessageText},
14}; 14};
15 15
16fn main() -> Result<(), Box<dyn Error>> { 16fn main() -> Result<(), Box<dyn Error>> {
@@ -42,13 +42,17 @@ fn main() -> Result<(), Box<dyn Error>> {
42fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<(), Box<dyn Error>> { 42fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<(), Box<dyn Error>> {
43 loop { 43 loop {
44 if app.render { 44 if app.render {
45 if app.term_clear {
46 terminal.clear()?;
47 app.term_clear = false;
48 }
45 let hold = ui(&mut terminal, app); 49 let hold = ui(&mut terminal, app);
46 app = hold.0; 50 app = hold.0;
47 hold.1?; 51 hold.1?;
48 } 52 }
49 53
50 if app.load { 54 if app.load {
51 app.message = Some(app.page.message(&app.config)); 55 app.message = MessageText::Text(app.page.message(&app.config));
52 let mut watch_history = app.watch_history.clone(); 56 let mut watch_history = app.watch_history.clone();
53 terminal.clear()?; 57 terminal.clear()?;
54 let hold = ui(&mut terminal, app); 58 let hold = ui(&mut terminal, app);
@@ -70,7 +74,7 @@ fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<(
70 item: row_item.item.clone(), 74 item: row_item.item.clone(),
71 ..*row_item 75 ..*row_item
72 }); 76 });
73 app.message = Some(e.to_string()); 77 app.message = MessageText::Text(e.to_string());
74 } 78 }
75 } 79 }
76 } 80 }
@@ -83,11 +87,18 @@ fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<(
83 87
84 app.watch_history = watch_history; 88 app.watch_history = watch_history;
85 app.state = State(new_state); 89 app.state = State(new_state);
90 app.selectable = App::selectable(&app.state);
86 91
87 app.load = false; 92 app.load = false;
88 terminal.clear()?; 93 terminal.clear()?;
89 let hold = ui(&mut terminal, app); 94 let hold = ui(&mut terminal, app);
90 app = hold.0; 95 app = hold.0;
96
97 let selected = app.page_default();
98
99 app.selected = selected;
100 app.hover = selected;
101 app.render = true;
91 } else { 102 } else {
92 match event::read()? { 103 match event::read()? {
93 event::Event::Key(key) => { 104 event::Event::Key(key) => {
@@ -143,7 +154,7 @@ fn ui<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> (App, Result<(),
143 154
144 app = recv.recv().unwrap(); 155 app = recv.recv().unwrap();
145 156
146 app.message = None; 157 app.message = MessageText::None;
147 app.render = false; 158 app.render = false;
148 159
149 match res { 160 match res {
src/structs/apphistory.rs +3 −3
@@ -2,7 +2,7 @@ use invidious::blocking::Client;
2 2
3use crate::{app::app::App, structs::Page}; 3use crate::{app::app::App, structs::Page};
4 4
5use super::{SearchSettings, State}; 5use super::{SearchSettings, State, MessageText};
6 6
7#[derive(Clone)] 7#[derive(Clone)]
8pub struct AppHistory { 8pub struct AppHistory {
@@ -12,7 +12,7 @@ pub struct AppHistory {
12 pub hover: Option<(usize, usize)>, // x, y 12 pub hover: Option<(usize, usize)>, // x, y
13 pub selected: Option<(usize, usize)>, 13 pub selected: Option<(usize, usize)>,
14 pub client: Client, 14 pub client: Client,
15 pub message: Option<String>, 15 pub message: MessageText,
16 pub load: bool, 16 pub load: bool,
17 pub render: bool, 17 pub render: bool,
18 pub popup_focus: bool, 18 pub popup_focus: bool,
@@ -30,7 +30,7 @@ impl From<App> for AppHistory {
30 selectable: original.selectable, 30 selectable: original.selectable,
31 hover: original.hover, 31 hover: original.hover,
32 // selected: original.selected, 32 // selected: original.selected,
33 selected: None, 33 selected: original.selected,
34 client: original.client, 34 client: original.client,
35 message: original.message, 35 message: original.message,
36 load: original.load, 36 load: original.load,
src/structs/messagetext.rs added +22
@@ -0,0 +1,22 @@
1#[derive(Clone, PartialEq, Eq)]
2pub enum MessageText {
3 Command(String),
4 Text(String),
5 None,
6}
7
8impl ToString for MessageText {
9 fn to_string(&self) -> String {
10 match self {
11 Self::Command(cmd) => format!(":{}", cmd),
12 Self::Text(s) => s.clone(),
13 Self::None => String::from("All good :)"),
14 }
15 }
16}
17
18impl MessageText {
19 pub fn is_some(&self) -> bool{
20 *self != Self::None
21 }
22}
src/structs/mod.rs +3
@@ -33,3 +33,6 @@ pub use minichannel::*;
33 33
34mod fullchannel; 34mod fullchannel;
35pub use fullchannel::*; 35pub use fullchannel::*;
36
37mod messagetext;
38pub use messagetext::*;
src/widgets/force_clear.rs deleted −20
@@ -1,20 +0,0 @@
1use tui::{
2 buffer::Buffer,
3 layout::Rect,
4 style::{Color, Style},
5 widgets::Widget,
6};
7
8pub struct ForceClear;
9
10impl Widget for ForceClear {
11 fn render(self, rect: Rect, buffer: &mut Buffer) {
12 for y in rect.y..rect.y + rect.height {
13 for x in rect.x..rect.x + rect.width {
14 buffer
15 .get_mut(x, y)
16 .set_style(Style::default().bg(Color::DarkGray));
17 }
18 }
19 }
20}
src/widgets/item_display.rs +20 −9
@@ -11,6 +11,7 @@ use crate::structs::ListItem;
11#[derive(Clone)] 11#[derive(Clone)]
12pub struct ItemDisplay { 12pub struct ItemDisplay {
13 pub item: ListItem, 13 pub item: ListItem,
14 pub render_image: bool,
14} 15}
15 16
16impl Widget for ItemDisplay { 17impl Widget for ItemDisplay {
@@ -40,7 +41,9 @@ impl Widget for ItemDisplay {
40 ..Default::default() 41 ..Default::default()
41 }; 42 };
42 43
43 let _ = print_from_file(path.as_os_str(), &conf); 44 if self.render_image {
45 let _ = print_from_file(path.as_os_str(), &conf);
46 }
44 } 47 }
45 48
46 let mut y = if exists { 49 let mut y = if exists {
@@ -81,7 +84,7 @@ impl Widget for ItemDisplay {
81 if y < area.height + area.y { 84 if y < area.height + area.y {
82 let rect = Rect { 85 let rect = Rect {
83 x: area.x, 86 x: area.x,
84 y: y, 87 y,
85 width: area.width, 88 width: area.width,
86 height: area.height + area.y - y, 89 height: area.height + area.y - y,
87 }; 90 };
@@ -114,8 +117,9 @@ impl Widget for ItemDisplay {
114 y: image_transform.y as i16, 117 y: image_transform.y as i16,
115 ..Default::default() 118 ..Default::default()
116 }; 119 };
117 120 if self.render_image {
118 let _ = print_from_file(path.as_os_str(), &conf); 121 let _ = print_from_file(path.as_os_str(), &conf);
122 }
119 } 123 }
120 124
121 let mut y = if exists { 125 let mut y = if exists {
@@ -162,7 +166,7 @@ impl Widget for ItemDisplay {
162 if y < area.height + area.y { 166 if y < area.height + area.y {
163 let rect = Rect { 167 let rect = Rect {
164 x: area.x, 168 x: area.x,
165 y: y, 169 y,
166 width: area.width, 170 width: area.width,
167 height: area.height + area.y - y, 171 height: area.height + area.y - y,
168 }; 172 };
@@ -197,8 +201,9 @@ impl Widget for ItemDisplay {
197 y: image_transform.y as i16, 201 y: image_transform.y as i16,
198 ..Default::default() 202 ..Default::default()
199 }; 203 };
200 204 if self.render_image{
201 let _ = print_from_file(path.as_os_str(), &conf); 205 let _ = print_from_file(path.as_os_str(), &conf);
206 }
202 } 207 }
203 208
204 let mut y = if exists { 209 let mut y = if exists {
@@ -272,8 +277,9 @@ impl Widget for ItemDisplay {
272 y: image_transform.y as i16, 277 y: image_transform.y as i16,
273 ..Default::default() 278 ..Default::default()
274 }; 279 };
275 280 if self.render_image {
276 let _ = print_from_file(path.as_os_str(), &conf); 281 let _ = print_from_file(path.as_os_str(), &conf);
282 }
277 } 283 }
278 284
279 let mut y = if exists { 285 let mut y = if exists {
@@ -339,7 +345,8 @@ impl Widget for ItemDisplay {
339 } 345 }
340 346
341 if item.len() > area.width as usize { 347 if item.len() > area.width as usize {
342 item = format!("{}...", &item[..area.width as usize - 3]); 348 // item = format!("{}...", &item[..area.width as usize - 3]);
349 item = format!("{}...", &item.get(..area.width as usize - 3).unwrap_or_default());
343 } 350 }
344 buf.set_string(area.x, y, item, style); 351 buf.set_string(area.x, y, item, style);
345 y += 1; 352 y += 1;
@@ -348,7 +355,7 @@ impl Widget for ItemDisplay {
348 if y < area.height + area.y { 355 if y < area.height + area.y {
349 let rect = Rect { 356 let rect = Rect {
350 x: area.x, 357 x: area.x,
351 y: y, 358 y,
352 width: area.width, 359 width: area.width,
353 height: area.height + area.y - y, 360 height: area.height + area.y - y,
354 }; 361 };
@@ -385,7 +392,9 @@ impl Widget for ItemDisplay {
385 ..Default::default() 392 ..Default::default()
386 }; 393 };
387 394
395 if self.render_image{
388 let _ = print_from_file(path.as_os_str(), &conf); 396 let _ = print_from_file(path.as_os_str(), &conf);
397 }
389 } 398 }
390 399
391 let mut y = if exists { 400 let mut y = if exists {
@@ -448,7 +457,9 @@ impl Widget for ItemDisplay {
448 ..Default::default() 457 ..Default::default()
449 }; 458 };
450 459
460 if self.render_image{
451 let _ = print_from_file(path.as_os_str(), &conf); 461 let _ = print_from_file(path.as_os_str(), &conf);
462 }
452 } 463 }
453 464
454 let mut y = if exists { 465 let mut y = if exists {
src/widgets/mod.rs −1
@@ -1,4 +1,3 @@
1pub mod force_clear;
2pub mod horizontal_split; 1pub mod horizontal_split;
3pub mod item_display; 2pub mod item_display;
4pub mod text_list; 3pub mod text_list;
src/widgets/text_list.rs +7
@@ -136,6 +136,10 @@ impl TextList {
136 } 136 }
137 137
138 pub fn down(&mut self) { 138 pub fn down(&mut self) {
139 if self.items.len() == 0 {
140 return;
141 }
142
139 if self.selected < self.items.len() - 1 { 143 if self.selected < self.items.len() - 1 {
140 self.selected += 1; 144 self.selected += 1;
141 } 145 }
@@ -143,6 +147,9 @@ impl TextList {
143 } 147 }
144 148
145 pub fn up(&mut self) { 149 pub fn up(&mut self) {
150 if self.items.len() == 0 {
151 return;
152 }
146 if self.selected > 0 { 153 if self.selected > 0 {
147 self.selected -= 1; 154 self.selected -= 1;
148 } 155 }