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