Commit 7df2107eb9
Unsigned
Layout: unified · split
README.md +7 −6
| @@ -1,14 +1,15 @@ | |||
| 1 | ## Warning: This program is made for Linux machines (And maybe MacOS?) | 1 | ## Warning: |
| 2 | * This app is incomplete and is missing many features | ||
| 3 | * This app is only for *\*nix* systems | ||
| 2 | 4 | ||
| 3 | ## Changes made in this commit | 5 | ## Changes made in this commit |
| 4 | * Watch history page | 6 | * Added search filters |
| 5 | * Config files in `~/.config/youtube-tui` | ||
| 6 | 7 | ||
| 7 | ## Installation | 8 | ## Installation |
| 8 | Requirements: Git, Cargo and the Rust Compiler | 9 | Requirements: Git, Cargo and the Rust Compiler |
| 9 | 10 | ||
| 10 | ```bash | 11 | ```bash |
| 11 | git clone https://github.com/Siriusmart/youtube-tui && cd youtube-tui && cargo build | 12 | cargo install youtube-tui |
| 12 | ``` | 13 | ``` |
| 13 | 14 | ||
| 14 | ## Features | 15 | ## Features |
| @@ -94,8 +95,8 @@ The config files are located in `~/.config/youtube-tui`, run the program once to | |||
| 94 | > | 95 | > |
| 95 | 96 | ||
| 96 | ## To Do | 97 | ## To Do |
| 97 | * Make the search bar functional | 98 | * Search |
| 98 | * View channels | 99 | * Adaptive config files (auto update when config files when there are new options in the config) |
| 99 | 100 | ||
| 100 | ## Bugs | 101 | ## Bugs |
| 101 | * If there is a bug please open a GitHub issue thx :)\ No newline at end of file | 102 | * If there is a bug please open a GitHub issue thx :)\ No newline at end of file |
src/app/app.rs +58 −17
| @@ -5,7 +5,7 @@ use std::{ | |||
| 5 | 5 | ||
| 6 | use crate::{ | 6 | use crate::{ |
| 7 | app::pages::main_menu::*, | 7 | app::pages::main_menu::*, |
| 8 | structs::{AppHistory, Item, Page, Row, WatchHistory}, | 8 | structs::{AppHistory, Item, Page, Row, SearchSettings, WatchHistory}, |
| 9 | traits::{KeyInput, SelectItem}, | 9 | traits::{KeyInput, SelectItem}, |
| 10 | }; | 10 | }; |
| 11 | use crossterm::event::KeyCode; | 11 | use crossterm::event::KeyCode; |
| @@ -18,7 +18,7 @@ use tui::{ | |||
| 18 | Frame, | 18 | Frame, |
| 19 | }; | 19 | }; |
| 20 | 20 | ||
| 21 | use super::config::Config; | 21 | use super::{config::Config, pages::item_info::ItemInfo}; |
| 22 | 22 | ||
| 23 | #[derive(Debug)] | 23 | #[derive(Debug)] |
| 24 | pub struct App { | 24 | pub struct App { |
| @@ -32,8 +32,10 @@ pub struct App { | |||
| 32 | pub message: Arc<Mutex<Option<String>>>, | 32 | pub message: Arc<Mutex<Option<String>>>, |
| 33 | pub load: bool, | 33 | pub load: bool, |
| 34 | pub render: bool, | 34 | pub render: bool, |
| 35 | pub popup_focus: bool, | ||
| 35 | pub history: Vec<AppHistory>, | 36 | pub history: Vec<AppHistory>, |
| 36 | pub watch_history: WatchHistory, | 37 | pub watch_history: WatchHistory, |
| 38 | pub search_settings: SearchSettings, | ||
| 37 | } | 39 | } |
| 38 | 40 | ||
| 39 | impl Default for App { | 41 | impl Default for App { |
| @@ -50,9 +52,11 @@ impl Default for App { | |||
| 50 | message: Arc::new(Mutex::new(None)), | 52 | message: Arc::new(Mutex::new(None)), |
| 51 | load: true, | 53 | load: true, |
| 52 | render: true, | 54 | render: true, |
| 55 | popup_focus: false, | ||
| 53 | history: Vec::new(), | 56 | history: Vec::new(), |
| 54 | config: Config::load().unwrap(), | 57 | config: Config::load().unwrap(), |
| 55 | watch_history: WatchHistory::load(), | 58 | watch_history: WatchHistory::load(), |
| 59 | search_settings: SearchSettings::default(), | ||
| 56 | } | 60 | } |
| 57 | } | 61 | } |
| 58 | } | 62 | } |
| @@ -157,6 +161,7 @@ impl App { | |||
| 157 | KeyCode::Esc => { | 161 | KeyCode::Esc => { |
| 158 | if self.selected.is_some() { | 162 | if self.selected.is_some() { |
| 159 | self.selected = None; | 163 | self.selected = None; |
| 164 | self.popup_focus = false; | ||
| 160 | return self; | 165 | return self; |
| 161 | } | 166 | } |
| 162 | } | 167 | } |
| @@ -226,11 +231,17 @@ impl App { | |||
| 226 | 231 | ||
| 227 | pub fn render<B: Backend>(&mut self, frame: &mut Frame<B>) { | 232 | pub fn render<B: Backend>(&mut self, frame: &mut Frame<B>) { |
| 228 | let size = frame.size(); | 233 | let size = frame.size(); |
| 234 | let mut popups = Vec::new(); | ||
| 229 | 235 | ||
| 230 | if size.width < 45 || size.height < 16 { | 236 | let min = match self.page { |
| 237 | Page::MainMenu(_) => MainMenu::min(), | ||
| 238 | Page::ItemDisplay(_) => ItemInfo::min(), | ||
| 239 | }; | ||
| 240 | |||
| 241 | if size.width < min.0 || size.height < min.1 { | ||
| 231 | let paragraph = Paragraph::new(format!( | 242 | let paragraph = Paragraph::new(format!( |
| 232 | "Window too small. Minimum size 45 x 16. Current size is {} x {}", | 243 | "Window too small. Minimum size for this page is {} x {}. Current size is {} x {}", |
| 233 | size.width, size.height | 244 | min.0, min.1, size.width, size.height |
| 234 | )) | 245 | )) |
| 235 | .block(Block::default()) | 246 | .block(Block::default()) |
| 236 | .style(Style::default().fg(Color::Red)) | 247 | .style(Style::default().fg(Color::Red)) |
| @@ -304,25 +315,53 @@ impl App { | |||
| 304 | 315 | ||
| 305 | let hover = hover_selected == Some((x, y)); | 316 | let hover = hover_selected == Some((x, y)); |
| 306 | 317 | ||
| 307 | match item { | 318 | if match item { |
| 308 | Item::Global(i) => { | 319 | Item::Global(i) => i.render_item( |
| 309 | i.render_item( | 320 | frame, |
| 310 | frame, | 321 | chunk, |
| 311 | chunk, | 322 | selected, |
| 312 | selected, | 323 | hover, |
| 313 | hover, | 324 | false, |
| 314 | &*self.message.lock().unwrap(), | 325 | &*self.message.lock().unwrap(), |
| 315 | ); | 326 | &mut self.search_settings, |
| 316 | } | 327 | ), |
| 317 | Item::MainMenu(i) => { | 328 | Item::MainMenu(i) => { |
| 318 | i.render_item(frame, chunk, selected, hover, &self.page); | 329 | i.render_item(frame, chunk, selected, hover, self.popup_focus, &self.page); |
| 330 | false | ||
| 319 | } | 331 | } |
| 332 | |||
| 320 | Item::ItemInfo(i) => { | 333 | Item::ItemInfo(i) => { |
| 321 | i.render_item(frame, chunk, selected, hover); | 334 | i.render_item(frame, chunk, selected, hover, self.popup_focus); |
| 335 | false | ||
| 322 | } | 336 | } |
| 337 | } { | ||
| 338 | popups.push((item, selected, hover, chunk)); | ||
| 323 | } | 339 | } |
| 324 | } | 340 | } |
| 325 | } | 341 | } |
| 342 | |||
| 343 | for (item, selected, hover, chunk) in popups { | ||
| 344 | match item { | ||
| 345 | Item::Global(i) => { | ||
| 346 | i.render_item( | ||
| 347 | frame, | ||
| 348 | chunk, | ||
| 349 | selected, | ||
| 350 | hover, | ||
| 351 | true, | ||
| 352 | &*self.message.lock().unwrap(), | ||
| 353 | &mut self.search_settings, | ||
| 354 | ); | ||
| 355 | } | ||
| 356 | _ => {} // Item::MainMenu(i) => { | ||
| 357 | // i.render_item(frame, chunk, selected, hover, &self.page); | ||
| 358 | // } | ||
| 359 | |||
| 360 | // Item::ItemInfo(i) => { | ||
| 361 | // i.render_item(frame, chunk, selected, hover); | ||
| 362 | // } | ||
| 363 | } | ||
| 364 | } | ||
| 326 | } | 365 | } |
| 327 | 366 | ||
| 328 | pub fn pop(mut self) -> (App, bool) { | 367 | pub fn pop(mut self) -> (App, bool) { |
| @@ -346,6 +385,8 @@ impl App { | |||
| 346 | history: self.history.clone(), | 385 | history: self.history.clone(), |
| 347 | config: self.config, | 386 | config: self.config, |
| 348 | watch_history: self.watch_history, | 387 | watch_history: self.watch_history, |
| 388 | search_settings: self.search_settings, | ||
| 389 | popup_focus: app_history.popup_focus, | ||
| 349 | }; | 390 | }; |
| 350 | 391 | ||
| 351 | (self, true) | 392 | (self, true) |
src/app/pages/global.rs +95 −5
| @@ -5,18 +5,22 @@ use tui::{ | |||
| 5 | backend::Backend, | 5 | backend::Backend, |
| 6 | layout::{Alignment, Rect}, | 6 | layout::{Alignment, Rect}, |
| 7 | style::{Color, Style}, | 7 | style::{Color, Style}, |
| 8 | widgets::{Block, BorderType, Borders, Paragraph}, | 8 | widgets::{Block, BorderType, Borders, Clear, Paragraph}, |
| 9 | Frame, | 9 | Frame, |
| 10 | }; | 10 | }; |
| 11 | 11 | ||
| 12 | use crate::{ | 12 | use crate::{ |
| 13 | app::app::App, | 13 | app::app::App, |
| 14 | functions::center_rect, | ||
| 15 | structs::SearchSettings, | ||
| 14 | traits::{KeyInput, SelectItem}, | 16 | traits::{KeyInput, SelectItem}, |
| 17 | widgets::{force_clear::ForceClear, horizontal_split::HorizontalSplit}, | ||
| 15 | }; | 18 | }; |
| 16 | 19 | ||
| 17 | #[derive(Debug, Clone)] | 20 | #[derive(Debug, Clone)] |
| 18 | pub enum GlobalItem { | 21 | pub enum GlobalItem { |
| 19 | SearchBar(String), | 22 | SearchBar(String), |
| 23 | SearchSettings, | ||
| 20 | MessageBar, | 24 | MessageBar, |
| 21 | } | 25 | } |
| 22 | 26 | ||
| @@ -45,9 +49,13 @@ impl Mode { | |||
| 45 | } | 49 | } |
| 46 | 50 | ||
| 47 | impl SelectItem for GlobalItem { | 51 | impl SelectItem for GlobalItem { |
| 48 | fn select(&mut self, app: App) -> (App, bool) { | 52 | fn select(&mut self, mut app: App) -> (App, bool) { |
| 49 | let selected = match self { | 53 | let selected = match self { |
| 50 | GlobalItem::SearchBar(_) => true, | 54 | GlobalItem::SearchBar(_) => true, |
| 55 | GlobalItem::SearchSettings => { | ||
| 56 | app.popup_focus = true; | ||
| 57 | true | ||
| 58 | } | ||
| 51 | _ => false, | 59 | _ => false, |
| 52 | }; | 60 | }; |
| 53 | 61 | ||
| @@ -56,14 +64,14 @@ impl SelectItem for GlobalItem { | |||
| 56 | 64 | ||
| 57 | fn selectable(&self) -> bool { | 65 | fn selectable(&self) -> bool { |
| 58 | match self { | 66 | match self { |
| 59 | GlobalItem::SearchBar(_) => true, | 67 | GlobalItem::SearchBar(_) | GlobalItem::SearchSettings => true, |
| 60 | _ => false, | 68 | _ => false, |
| 61 | } | 69 | } |
| 62 | } | 70 | } |
| 63 | } | 71 | } |
| 64 | 72 | ||
| 65 | impl KeyInput for GlobalItem { | 73 | impl KeyInput for GlobalItem { |
| 66 | fn key_input(&mut self, key: KeyCode, app: App) -> (bool, App) { | 74 | fn key_input(&mut self, key: KeyCode, mut app: App) -> (bool, App) { |
| 67 | match self { | 75 | match self { |
| 68 | GlobalItem::SearchBar(search_bar) => match key { | 76 | GlobalItem::SearchBar(search_bar) => match key { |
| 69 | KeyCode::Char(c) => { | 77 | KeyCode::Char(c) => { |
| @@ -75,6 +83,9 @@ impl KeyInput for GlobalItem { | |||
| 75 | KeyCode::Enter => {} | 83 | KeyCode::Enter => {} |
| 76 | _ => {} | 84 | _ => {} |
| 77 | }, | 85 | }, |
| 86 | GlobalItem::SearchSettings => { | ||
| 87 | app.search_settings.key_input(key); | ||
| 88 | } | ||
| 78 | _ => {} | 89 | _ => {} |
| 79 | } | 90 | } |
| 80 | 91 | ||
| @@ -89,8 +100,11 @@ impl GlobalItem { | |||
| 89 | rect: Rect, | 100 | rect: Rect, |
| 90 | selected: bool, | 101 | selected: bool, |
| 91 | hover: bool, | 102 | hover: bool, |
| 103 | popup_render: bool, | ||
| 92 | message: &Option<String>, | 104 | message: &Option<String>, |
| 93 | ) { | 105 | search_settings: &mut SearchSettings, |
| 106 | ) -> bool { | ||
| 107 | let area = frame.size(); | ||
| 94 | match self { | 108 | match self { |
| 95 | GlobalItem::SearchBar(search) => { | 109 | GlobalItem::SearchBar(search) => { |
| 96 | let block = Block::default() | 110 | let block = Block::default() |
| @@ -123,6 +137,82 @@ impl GlobalItem { | |||
| 123 | .block(block); | 137 | .block(block); |
| 124 | frame.render_widget(paragraph, rect); | 138 | frame.render_widget(paragraph, rect); |
| 125 | } | 139 | } |
| 140 | GlobalItem::SearchSettings => { | ||
| 141 | let block = Block::default() | ||
| 142 | .border_type(BorderType::Rounded) | ||
| 143 | .borders(Borders::ALL) | ||
| 144 | .border_style(Style::default().fg(if selected { | ||
| 145 | Color::LightYellow | ||
| 146 | } else if hover { | ||
| 147 | Color::LightRed | ||
| 148 | } else { | ||
| 149 | Color::Reset | ||
| 150 | })); | ||
| 151 | let paragraph = Paragraph::new(String::from("...")).block(block); | ||
| 152 | frame.render_widget(paragraph, rect); | ||
| 153 | |||
| 154 | if selected { | ||
| 155 | if popup_render { | ||
| 156 | match center_rect((area.width * 70 / 100, area.height * 70 / 100), area) { | ||
| 157 | Ok(rect) => { | ||
| 158 | let split = HorizontalSplit::default() | ||
| 159 | .percentages(vec![40, 60]) | ||
| 160 | .border_style(Style::default().fg(if selected { | ||
| 161 | Color::LightBlue | ||
| 162 | } else if hover { | ||
| 163 | Color::LightRed | ||
| 164 | } else { | ||
| 165 | Color::Reset | ||
| 166 | })); | ||
| 167 | let chunks = split.inner(rect); | ||
| 168 | |||
| 169 | frame.render_widget(split, rect); | ||
| 170 | |||
| 171 | search_settings.text_list.area(chunks[0]); | ||
| 172 | |||
| 173 | if search_settings.row { | ||
| 174 | search_settings | ||
| 175 | .text_list | ||
| 176 | .selected_style(Style::default().fg(Color::LightRed)); | ||
| 177 | |||
| 178 | search_settings | ||
| 179 | .select_text_list | ||
| 180 | .selected_style(Style::default().fg(Color::LightYellow)); | ||
| 181 | } else { | ||
| 182 | search_settings | ||
| 183 | .text_list | ||
| 184 | .selected_style(Style::default().fg(Color::LightYellow)); | ||
| 185 | |||
| 186 | search_settings | ||
| 187 | .select_text_list | ||
| 188 | .selected_style(Style::default().fg(Color::LightRed)); | ||
| 189 | } | ||
| 190 | |||
| 191 | frame.render_widget(search_settings.text_list.clone(), chunks[0]); | ||
| 192 | |||
| 193 | search_settings.select_text_list.area(chunks[1]); | ||
| 194 | |||
| 195 | frame.render_widget( | ||
| 196 | search_settings.select_text_list.clone(), | ||
| 197 | chunks[1], | ||
| 198 | ); | ||
| 199 | |||
| 200 | frame.render_widget(ForceClear, chunks[0]); | ||
| 201 | |||
| 202 | frame.render_widget(ForceClear, chunks[1]); | ||
| 203 | } | ||
| 204 | Err(rect) => { | ||
| 205 | frame.render_widget(Clear, rect); | ||
| 206 | } | ||
| 207 | } | ||
| 208 | //panic!("{:?}", rect); | ||
| 209 | } else { | ||
| 210 | return true; | ||
| 211 | } | ||
| 212 | } | ||
| 213 | } | ||
| 126 | } | 214 | } |
| 215 | |||
| 216 | false | ||
| 127 | } | 217 | } |
| 128 | } | 218 | } |
src/app/pages/item_info.rs +11 −4
| @@ -306,6 +306,7 @@ impl ItemInfoItem { | |||
| 306 | rect: Rect, | 306 | rect: Rect, |
| 307 | selected: bool, | 307 | selected: bool, |
| 308 | hover: bool, | 308 | hover: bool, |
| 309 | popup_focus: bool, | ||
| 309 | ) { | 310 | ) { |
| 310 | match self { | 311 | match self { |
| 311 | ItemInfoItem::Video(videoinfo) => { | 312 | ItemInfoItem::Video(videoinfo) => { |
| @@ -335,11 +336,13 @@ impl ItemInfoItem { | |||
| 335 | 336 | ||
| 336 | frame.render_widget(split, rect); | 337 | frame.render_widget(split, rect); |
| 337 | 338 | ||
| 338 | let item_display = ItemDisplay { | 339 | if !popup_focus { |
| 339 | item: ListItem::FullVideo(videoinfo.video.clone()), | 340 | let item_display = ItemDisplay { |
| 340 | }; | 341 | item: ListItem::FullVideo(videoinfo.video.clone()), |
| 342 | }; | ||
| 341 | 343 | ||
| 342 | frame.render_widget(item_display, chunks[0]); | 344 | frame.render_widget(item_display, chunks[0]); |
| 345 | } | ||
| 343 | 346 | ||
| 344 | frame.render_widget(list, chunks[1]); | 347 | frame.render_widget(list, chunks[1]); |
| 345 | } | 348 | } |
| @@ -372,6 +375,10 @@ impl ItemInfo { | |||
| 372 | String::from("Loading item info...") | 375 | String::from("Loading item info...") |
| 373 | } | 376 | } |
| 374 | 377 | ||
| 378 | pub fn min() -> (u16, u16) { | ||
| 379 | (21, 12) | ||
| 380 | } | ||
| 381 | |||
| 375 | pub fn default() -> Vec<Row> { | 382 | pub fn default() -> Vec<Row> { |
| 376 | vec![ | 383 | vec![ |
| 377 | Row { | 384 | Row { |
src/app/pages/main_menu.rs +18 −5
| @@ -201,6 +201,7 @@ impl MainMenuItem { | |||
| 201 | rect: Rect, | 201 | rect: Rect, |
| 202 | selected: bool, | 202 | selected: bool, |
| 203 | hover: bool, | 203 | hover: bool, |
| 204 | popup_focus: bool, | ||
| 204 | page: &Page, | 205 | page: &Page, |
| 205 | ) { | 206 | ) { |
| 206 | let mut style = Style::default().fg(if selected { | 207 | let mut style = Style::default().fg(if selected { |
| @@ -258,7 +259,9 @@ impl MainMenuItem { | |||
| 258 | } | 259 | } |
| 259 | 260 | ||
| 260 | if let Some(item) = videos.iter().nth(list.selected) { | 261 | if let Some(item) = videos.iter().nth(list.selected) { |
| 261 | frame.render_widget(ItemDisplay { item: item.clone() }, chunks[1]); | 262 | if !popup_focus { |
| 263 | frame.render_widget(ItemDisplay { item: item.clone() }, chunks[1]); | ||
| 264 | } | ||
| 262 | } | 265 | } |
| 263 | 266 | ||
| 264 | frame.render_widget(list, chunks[0]); | 267 | frame.render_widget(list, chunks[0]); |
| @@ -305,13 +308,23 @@ impl MainMenu { | |||
| 305 | String::from("Loading home page...") | 308 | String::from("Loading home page...") |
| 306 | } | 309 | } |
| 307 | 310 | ||
| 311 | pub fn min() -> (u16, u16) { | ||
| 312 | (45, 15) | ||
| 313 | } | ||
| 314 | |||
| 308 | pub fn default() -> Vec<Row> { | 315 | pub fn default() -> Vec<Row> { |
| 309 | vec![ | 316 | vec![ |
| 310 | Row { | 317 | Row { |
| 311 | items: vec![RowItem { | 318 | items: vec![ |
| 312 | item: Item::Global(GlobalItem::SearchBar(String::new())), | 319 | RowItem { |
| 313 | constraint: Constraint::Percentage(100), | 320 | item: Item::Global(GlobalItem::SearchBar(String::new())), |
| 314 | }], | 321 | constraint: Constraint::Min(16), |
| 322 | }, | ||
| 323 | RowItem { | ||
| 324 | item: Item::Global(GlobalItem::SearchSettings), | ||
| 325 | constraint: Constraint::Length(5), | ||
| 326 | }, | ||
| 327 | ], | ||
| 315 | centered: false, | 328 | centered: false, |
| 316 | height: Constraint::Length(3), | 329 | height: Constraint::Length(3), |
| 317 | }, | 330 | }, |
src/functions/center_rect.rs added +36
| @@ -0,0 +1,36 @@ | |||
| 1 | use tui::layout::Rect; | ||
| 2 | |||
| 3 | pub fn center_rect(rect: (u16, u16), frame_rect: Rect) -> Result<Rect, Rect> { | ||
| 4 | let width_too_big = rect.0 > frame_rect.width; | ||
| 5 | let height_too_big = rect.1 > frame_rect.height; | ||
| 6 | |||
| 7 | if width_too_big || height_too_big { | ||
| 8 | return Err(Rect { | ||
| 9 | width: if width_too_big { | ||
| 10 | frame_rect.width | ||
| 11 | } else { | ||
| 12 | rect.0 | ||
| 13 | }, | ||
| 14 | height: if height_too_big { | ||
| 15 | frame_rect.height | ||
| 16 | } else { | ||
| 17 | rect.1 | ||
| 18 | }, | ||
| 19 | x: if width_too_big { | ||
| 20 | frame_rect.x | ||
| 21 | } else { | ||
| 22 | (frame_rect.x + frame_rect.width - rect.0) / 2 | ||
| 23 | }, | ||
| 24 | y: if height_too_big { | ||
| 25 | frame_rect.y | ||
| 26 | } else { | ||
| 27 | (frame_rect.y + frame_rect.height - rect.1) / 2 | ||
| 28 | }, | ||
| 29 | }); | ||
| 30 | } | ||
| 31 | |||
| 32 | let x = (frame_rect.x + frame_rect.width - rect.0) / 2; | ||
| 33 | let y = (frame_rect.y + frame_rect.height - rect.1) / 2; | ||
| 34 | |||
| 35 | Ok(Rect::new(x, y, rect.0, rect.1)) | ||
| 36 | } | ||
src/functions/mod.rs +4 −1
| @@ -2,4 +2,7 @@ mod download_all_thumbnails; | |||
| 2 | pub use download_all_thumbnails::*; | 2 | pub use download_all_thumbnails::*; |
| 3 | 3 | ||
| 4 | mod insert_vec; | 4 | mod insert_vec; |
| 5 | pub use insert_vec::*;\ No newline at end of file | 5 | pub use insert_vec::*; |
| 6 | |||
| 7 | mod center_rect; | ||
| 8 | pub use center_rect::*;\ No newline at end of file | ||
src/structs/apphistory.rs +2
| @@ -18,6 +18,7 @@ pub struct AppHistory { | |||
| 18 | pub message: Arc<Mutex<Option<String>>>, | 18 | pub message: Arc<Mutex<Option<String>>>, |
| 19 | pub load: bool, | 19 | pub load: bool, |
| 20 | pub render: bool, | 20 | pub render: bool, |
| 21 | pub popup_focus: bool, | ||
| 21 | } | 22 | } |
| 22 | 23 | ||
| 23 | impl From<App> for AppHistory { | 24 | impl From<App> for AppHistory { |
| @@ -32,6 +33,7 @@ impl From<App> for AppHistory { | |||
| 32 | message: original.message, | 33 | message: original.message, |
| 33 | load: original.load, | 34 | load: original.load, |
| 34 | render: original.render, | 35 | render: original.render, |
| 36 | popup_focus: original.popup_focus, | ||
| 35 | } | 37 | } |
| 36 | } | 38 | } |
| 37 | } | 39 | } |
src/structs/mod.rs +4 −1
| @@ -17,4 +17,7 @@ mod fullvideo; | |||
| 17 | pub use fullvideo::*; | 17 | pub use fullvideo::*; |
| 18 | 18 | ||
| 19 | mod watchhistory; | 19 | mod watchhistory; |
| 20 | pub use watchhistory::*;\ No newline at end of file | 20 | pub use watchhistory::*; |
| 21 | |||
| 22 | mod search_settings; | ||
| 23 | pub use search_settings::*;\ No newline at end of file | ||
src/structs/search_settings.rs added +361
| @@ -0,0 +1,361 @@ | |||
| 1 | use crossterm::event::KeyCode; | ||
| 2 | |||
| 3 | use crate::widgets::text_list::TextList; | ||
| 4 | |||
| 5 | #[derive(Debug, Clone)] | ||
| 6 | pub struct SearchSettings { | ||
| 7 | pub sort_by: SearchSettingsSortBy, | ||
| 8 | pub date: Option<SearchSettingsDate>, | ||
| 9 | pub duartion: Option<SearchSettingsDuration>, | ||
| 10 | pub r#type: Option<SearchSettingsType>, | ||
| 11 | |||
| 12 | pub row: bool, // left: true, right: false | ||
| 13 | |||
| 14 | pub text_list: TextList, | ||
| 15 | pub select_text_list: TextList, | ||
| 16 | } | ||
| 17 | |||
| 18 | impl Default for SearchSettings { | ||
| 19 | fn default() -> Self { | ||
| 20 | let mut text_list = TextList::default(); | ||
| 21 | text_list.items = vec![ | ||
| 22 | String::from("Sort by"), | ||
| 23 | String::from("Date"), | ||
| 24 | String::from("Duration"), | ||
| 25 | String::from("Type"), | ||
| 26 | String::from("Reset All"), | ||
| 27 | ]; | ||
| 28 | |||
| 29 | let mut out = SearchSettings { | ||
| 30 | sort_by: SearchSettingsSortBy::Relevance, | ||
| 31 | date: None, | ||
| 32 | duartion: None, | ||
| 33 | r#type: None, | ||
| 34 | |||
| 35 | row: true, | ||
| 36 | |||
| 37 | text_list, | ||
| 38 | select_text_list: TextList::default(), | ||
| 39 | }; | ||
| 40 | |||
| 41 | out.update_left(); | ||
| 42 | |||
| 43 | out | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | impl SearchSettings { | ||
| 48 | pub fn to_vec(self) -> Vec<String> { | ||
| 49 | let mut vec = vec![self.sort_by.as_url_string()]; | ||
| 50 | |||
| 51 | if let Some(date) = self.date { | ||
| 52 | vec.push(date.as_url_string()); | ||
| 53 | } | ||
| 54 | |||
| 55 | if let Some(duration) = self.duartion { | ||
| 56 | vec.push(duration.as_url_string()); | ||
| 57 | } | ||
| 58 | |||
| 59 | if let Some(r#type) = self.r#type { | ||
| 60 | vec.push(r#type.as_url_string()); | ||
| 61 | } | ||
| 62 | |||
| 63 | vec | ||
| 64 | } | ||
| 65 | |||
| 66 | pub fn key_input(&mut self, keycode: KeyCode) { | ||
| 67 | match keycode { | ||
| 68 | KeyCode::Up => { | ||
| 69 | if self.row { | ||
| 70 | self.text_list.up(); | ||
| 71 | self.update_left() | ||
| 72 | } else { | ||
| 73 | self.select_text_list.up(); | ||
| 74 | |||
| 75 | match self.text_list.selected { | ||
| 76 | 0 => self.sort_by = SearchSettingsSortBy::index_to_value(self.select_text_list.selected), | ||
| 77 | 1 => self.date = SearchSettingsDate::index_to_value(self.select_text_list.selected), | ||
| 78 | 2 => self.duartion = SearchSettingsDuration::index_to_value(self.select_text_list.selected), | ||
| 79 | 3 => self.r#type = SearchSettingsType::index_to_value(self.select_text_list.selected), | ||
| 80 | _ => {} | ||
| 81 | } | ||
| 82 | } | ||
| 83 | } | ||
| 84 | KeyCode::Down => { | ||
| 85 | if self.row { | ||
| 86 | self.text_list.down(); | ||
| 87 | self.update_left() | ||
| 88 | } else { | ||
| 89 | self.select_text_list.down(); | ||
| 90 | |||
| 91 | match self.text_list.selected { | ||
| 92 | 0 => self.sort_by = SearchSettingsSortBy::index_to_value(self.select_text_list.selected), | ||
| 93 | 1 => self.date = SearchSettingsDate::index_to_value(self.select_text_list.selected), | ||
| 94 | 2 => self.duartion = SearchSettingsDuration::index_to_value(self.select_text_list.selected), | ||
| 95 | 3 => self.r#type = SearchSettingsType::index_to_value(self.select_text_list.selected), | ||
| 96 | _ => {} | ||
| 97 | } | ||
| 98 | } | ||
| 99 | } | ||
| 100 | KeyCode::Left => { | ||
| 101 | self.row = true; | ||
| 102 | } | ||
| 103 | KeyCode::Right => { | ||
| 104 | self.row = false; | ||
| 105 | } | ||
| 106 | KeyCode::Enter => { | ||
| 107 | if self.text_list.selected == 4 && !self.row { | ||
| 108 | *self = Self::default(); | ||
| 109 | self.text_list.selected = 4; | ||
| 110 | self.update_left(); | ||
| 111 | } else { | ||
| 112 | self.row = false; | ||
| 113 | } | ||
| 114 | } | ||
| 115 | _ => {} | ||
| 116 | } | ||
| 117 | } | ||
| 118 | |||
| 119 | pub fn update_left(&mut self) { | ||
| 120 | match self.text_list.selected { | ||
| 121 | 0 => { | ||
| 122 | self.select_text_list.items = SearchSettingsSortBy::as_vec(); | ||
| 123 | self.select_text_list.selected = SearchSettingsSortBy::value_to_index(self.sort_by); | ||
| 124 | } | ||
| 125 | 1 => { | ||
| 126 | self.select_text_list.items = SearchSettingsDate::as_vec(); | ||
| 127 | self.select_text_list.selected = SearchSettingsDate::value_to_index(self.date); | ||
| 128 | } | ||
| 129 | 2 => { | ||
| 130 | self.select_text_list.items = SearchSettingsDuration::as_vec(); | ||
| 131 | self.select_text_list.selected = | ||
| 132 | SearchSettingsDuration::value_to_index(self.duartion); | ||
| 133 | } | ||
| 134 | 3 => { | ||
| 135 | self.select_text_list.items = SearchSettingsType::as_vec(); | ||
| 136 | self.select_text_list.selected = SearchSettingsType::value_to_index(self.r#type); | ||
| 137 | } | ||
| 138 | 4 => { | ||
| 139 | self.select_text_list.items = vec![String::from("Reset All")]; | ||
| 140 | self.select_text_list.selected = 0; | ||
| 141 | } | ||
| 142 | _ => {} | ||
| 143 | } | ||
| 144 | } | ||
| 145 | } | ||
| 146 | |||
| 147 | pub trait AsUrlString { | ||
| 148 | fn as_url_string(&self) -> String; | ||
| 149 | } | ||
| 150 | |||
| 151 | #[derive(Debug, Clone, Copy)] | ||
| 152 | pub enum SearchSettingsSortBy { | ||
| 153 | Relevance, | ||
| 154 | Rating, | ||
| 155 | Date, | ||
| 156 | ViewCount, | ||
| 157 | } | ||
| 158 | |||
| 159 | impl AsUrlString for SearchSettingsSortBy { | ||
| 160 | fn as_url_string(&self) -> String { | ||
| 161 | format!( | ||
| 162 | "sort_by={}", | ||
| 163 | match self { | ||
| 164 | SearchSettingsSortBy::Relevance => String::from("relevance"), | ||
| 165 | SearchSettingsSortBy::Rating => String::from("rating"), | ||
| 166 | SearchSettingsSortBy::Date => String::from("upload_date"), | ||
| 167 | SearchSettingsSortBy::ViewCount => String::from("view_count"), | ||
| 168 | } | ||
| 169 | ) | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 173 | impl SearchSettingsSortBy { | ||
| 174 | pub fn as_vec() -> Vec<String> { | ||
| 175 | vec![ | ||
| 176 | String::from("Relevance"), | ||
| 177 | String::from("Rating"), | ||
| 178 | String::from("Date"), | ||
| 179 | String::from("View Count"), | ||
| 180 | ] | ||
| 181 | } | ||
| 182 | |||
| 183 | pub fn index_to_value(index: usize) -> SearchSettingsSortBy { | ||
| 184 | match index { | ||
| 185 | 0 => SearchSettingsSortBy::Relevance, | ||
| 186 | 1 => SearchSettingsSortBy::Rating, | ||
| 187 | 2 => SearchSettingsSortBy::Date, | ||
| 188 | 3 => SearchSettingsSortBy::ViewCount, | ||
| 189 | _ => unreachable!(), | ||
| 190 | } | ||
| 191 | } | ||
| 192 | |||
| 193 | pub fn value_to_index(value: SearchSettingsSortBy) -> usize { | ||
| 194 | match value { | ||
| 195 | SearchSettingsSortBy::Relevance => 0, | ||
| 196 | SearchSettingsSortBy::Rating => 1, | ||
| 197 | SearchSettingsSortBy::Date => 2, | ||
| 198 | SearchSettingsSortBy::ViewCount => 3, | ||
| 199 | } | ||
| 200 | } | ||
| 201 | } | ||
| 202 | |||
| 203 | #[derive(Debug, Clone, Copy)] | ||
| 204 | pub enum SearchSettingsDate { | ||
| 205 | Hour, | ||
| 206 | Day, | ||
| 207 | Week, | ||
| 208 | Month, | ||
| 209 | Year, | ||
| 210 | } | ||
| 211 | |||
| 212 | impl AsUrlString for SearchSettingsDate { | ||
| 213 | fn as_url_string(&self) -> String { | ||
| 214 | format!( | ||
| 215 | "date={}", | ||
| 216 | match self { | ||
| 217 | SearchSettingsDate::Hour => String::from("hour"), | ||
| 218 | SearchSettingsDate::Day => String::from("today"), | ||
| 219 | SearchSettingsDate::Week => String::from("week"), | ||
| 220 | SearchSettingsDate::Month => String::from("month"), | ||
| 221 | SearchSettingsDate::Year => String::from("year"), | ||
| 222 | } | ||
| 223 | ) | ||
| 224 | } | ||
| 225 | } | ||
| 226 | |||
| 227 | impl SearchSettingsDate { | ||
| 228 | pub fn as_vec() -> Vec<String> { | ||
| 229 | vec![ | ||
| 230 | String::from("No Filter"), | ||
| 231 | String::from("Hour"), | ||
| 232 | String::from("Day"), | ||
| 233 | String::from("Week"), | ||
| 234 | String::from("Month"), | ||
| 235 | String::from("Year"), | ||
| 236 | ] | ||
| 237 | } | ||
| 238 | |||
| 239 | pub fn index_to_value(index: usize) -> Option<SearchSettingsDate> { | ||
| 240 | match index { | ||
| 241 | 0 => None, | ||
| 242 | 1 => Some(SearchSettingsDate::Hour), | ||
| 243 | 2 => Some(SearchSettingsDate::Day), | ||
| 244 | 3 => Some(SearchSettingsDate::Week), | ||
| 245 | 4 => Some(SearchSettingsDate::Month), | ||
| 246 | 5 => Some(SearchSettingsDate::Year), | ||
| 247 | _ => unreachable!(), | ||
| 248 | } | ||
| 249 | } | ||
| 250 | |||
| 251 | pub fn value_to_index(value: Option<SearchSettingsDate>) -> usize { | ||
| 252 | match value { | ||
| 253 | None => 0, | ||
| 254 | Some(SearchSettingsDate::Hour) => 1, | ||
| 255 | Some(SearchSettingsDate::Day) => 2, | ||
| 256 | Some(SearchSettingsDate::Week) => 3, | ||
| 257 | Some(SearchSettingsDate::Month) => 4, | ||
| 258 | Some(SearchSettingsDate::Year) => 5, | ||
| 259 | } | ||
| 260 | } | ||
| 261 | } | ||
| 262 | |||
| 263 | #[derive(Debug, Clone, Copy)] | ||
| 264 | pub enum SearchSettingsDuration { | ||
| 265 | Short, | ||
| 266 | Long, | ||
| 267 | } | ||
| 268 | |||
| 269 | impl AsUrlString for SearchSettingsDuration { | ||
| 270 | fn as_url_string(&self) -> String { | ||
| 271 | format!( | ||
| 272 | "duration={}", | ||
| 273 | match self { | ||
| 274 | SearchSettingsDuration::Short => String::from("short"), | ||
| 275 | SearchSettingsDuration::Long => String::from("long"), | ||
| 276 | } | ||
| 277 | ) | ||
| 278 | } | ||
| 279 | } | ||
| 280 | |||
| 281 | impl SearchSettingsDuration { | ||
| 282 | pub fn as_vec() -> Vec<String> { | ||
| 283 | vec![ | ||
| 284 | String::from("No Filter"), | ||
| 285 | String::from("Short"), | ||
| 286 | String::from("Long"), | ||
| 287 | ] | ||
| 288 | } | ||
| 289 | |||
| 290 | pub fn index_to_value(index: usize) -> Option<SearchSettingsDuration> { | ||
| 291 | match index { | ||
| 292 | 0 => None, | ||
| 293 | 1 => Some(SearchSettingsDuration::Short), | ||
| 294 | 2 => Some(SearchSettingsDuration::Long), | ||
| 295 | _ => unreachable!(), | ||
| 296 | } | ||
| 297 | } | ||
| 298 | |||
| 299 | pub fn value_to_index(value: Option<SearchSettingsDuration>) -> usize { | ||
| 300 | match value { | ||
| 301 | None => 0, | ||
| 302 | Some(SearchSettingsDuration::Short) => 1, | ||
| 303 | Some(SearchSettingsDuration::Long) => 2, | ||
| 304 | } | ||
| 305 | } | ||
| 306 | } | ||
| 307 | |||
| 308 | #[derive(Debug, Clone, Copy)] | ||
| 309 | pub enum SearchSettingsType { | ||
| 310 | Video, | ||
| 311 | Channel, | ||
| 312 | Playlist, | ||
| 313 | All, | ||
| 314 | } | ||
| 315 | |||
| 316 | impl AsUrlString for SearchSettingsType { | ||
| 317 | fn as_url_string(&self) -> String { | ||
| 318 | format!( | ||
| 319 | "type={}", | ||
| 320 | match self { | ||
| 321 | SearchSettingsType::Video => String::from("video"), | ||
| 322 | SearchSettingsType::Channel => String::from("channel"), | ||
| 323 | SearchSettingsType::Playlist => String::from("playlist"), | ||
| 324 | SearchSettingsType::All => String::from("all"), | ||
| 325 | } | ||
| 326 | ) | ||
| 327 | } | ||
| 328 | } | ||
| 329 | |||
| 330 | impl SearchSettingsType { | ||
| 331 | pub fn as_vec() -> Vec<String> { | ||
| 332 | vec![ | ||
| 333 | String::from("No Filter"), | ||
| 334 | String::from("Video"), | ||
| 335 | String::from("Channel"), | ||
| 336 | String::from("Playlist"), | ||
| 337 | String::from("All"), | ||
| 338 | ] | ||
| 339 | } | ||
| 340 | |||
| 341 | pub fn index_to_value(index: usize) -> Option<SearchSettingsType> { | ||
| 342 | match index { | ||
| 343 | 0 => None, | ||
| 344 | 1 => Some(SearchSettingsType::Video), | ||
| 345 | 2 => Some(SearchSettingsType::Channel), | ||
| 346 | 3 => Some(SearchSettingsType::Playlist), | ||
| 347 | 4 => Some(SearchSettingsType::All), | ||
| 348 | _ => unreachable!(), | ||
| 349 | } | ||
| 350 | } | ||
| 351 | |||
| 352 | pub fn value_to_index(value: Option<SearchSettingsType>) -> usize { | ||
| 353 | match value { | ||
| 354 | None => 0, | ||
| 355 | Some(SearchSettingsType::Video) => 1, | ||
| 356 | Some(SearchSettingsType::Channel) => 2, | ||
| 357 | Some(SearchSettingsType::Playlist) => 3, | ||
| 358 | Some(SearchSettingsType::All) => 4, | ||
| 359 | } | ||
| 360 | } | ||
| 361 | } | ||
src/widgets/force_clear.rs added +13
| @@ -0,0 +1,13 @@ | |||
| 1 | use tui::{widgets::Widget, buffer::Buffer, layout::Rect, style::{Color, Style}}; | ||
| 2 | |||
| 3 | pub struct ForceClear; | ||
| 4 | |||
| 5 | impl Widget for ForceClear { | ||
| 6 | fn render(self, rect: Rect, buffer: &mut Buffer) { | ||
| 7 | for y in rect.y..rect.y + rect.height { | ||
| 8 | for x in rect.x..rect.x + rect.width { | ||
| 9 | buffer.get_mut(x, y).set_style(Style::default().bg(Color::DarkGray)); | ||
| 10 | } | ||
| 11 | } | ||
| 12 | } | ||
| 13 | } | ||
src/widgets/mod.rs +1
| @@ -1,3 +1,4 @@ | |||
| 1 | pub mod horizontal_split; | 1 | pub mod horizontal_split; |
| 2 | pub mod item_display; | 2 | pub mod item_display; |
| 3 | pub mod text_list; | 3 | pub mod text_list; |
| 4 | pub mod force_clear;\ No newline at end of file | ||