Commit 9aedf4a98d
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.1" | |
| 1719 | version = "0.4.2" | |
| 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.1" | |
| 3 | version = "0.4.2" | |
| 4 | 4 | edition = "2021" |
| 5 | 5 | authors = ["Siriusmart <siriusmart@tuta.io>"] |
| 6 | 6 | description = "An aesthetically pleasing YouTube TUI written in Rust" |
README.md +3 −4
| @@ -18,8 +18,8 @@ This program is being actively developed and there will be new features coming u | ||
| 18 | 18 | |
| 19 | 19 | > ### What's new in this commit |
| 20 | 20 | > |
| 21 | > * Fixed text list not scrolling with cursor bug (where the cursor just goes out of the screen) | |
| 22 | > * Improvements to the `render()` method | |
| 21 | > * `layouts.yml` in `.config/youtube-tui`, now you can customize your screen layout | |
| 22 | > * More improvements to the `render()` method (no more `.clone()` used) | |
| 23 | 23 | |
| 24 | 24 | ## Installation |
| 25 | 25 | |
| @@ -40,7 +40,7 @@ The binary is located at `./target/release/youtube-tui`, go move it to other loc | ||
| 40 | 40 | > |
| 41 | 41 | > This program does not requires any dependencies, but it is suggested these three things on your system that can be launched via command: |
| 42 | 42 | > |
| 43 | > 1. A video player (Default to `mpv`) | |
| 43 | > 1. A video player (Defaults to `mpv`) | |
| 44 | 44 | > 2. A terminal emulator (Defaults to `konsole`) |
| 45 | 45 | > 3. A YouTube downloader (Defaults to `yt-dlp`, strongly suggest NOT to use `youtube-dl` because it is now very slow) |
| 46 | 46 | > |
| @@ -59,7 +59,6 @@ youtube-tui # or path to the binary | ||
| 59 | 59 | |Key|What does it do| |
| 60 | 60 | |---|---| |
| 61 | 61 | |Arrow/Vim keys|Move in corresponding direction| |
| 62 | |Right arrow|Move cursor right | |
| 63 | 62 | |Enter|Select/Launch| |
| 64 | 63 | |Q|Quit the program| |
| 65 | 64 | |
src/app/app.rs +76 −22
| @@ -23,7 +23,7 @@ use super::{ | ||
| 23 | 23 | pages::{channel::Channel, item_info::ItemInfo, search::Search}, |
| 24 | 24 | }; |
| 25 | 25 | |
| 26 | #[derive(Debug, Clone)] | |
| 26 | #[derive(Clone)] | |
| 27 | 27 | pub struct App { |
| 28 | 28 | pub config: Config, |
| 29 | 29 | pub page: Page, |
| @@ -32,7 +32,7 @@ pub struct App { | ||
| 32 | 32 | pub hover: Option<(usize, usize)>, // x, y |
| 33 | 33 | pub selected: Option<(usize, usize)>, |
| 34 | 34 | pub client: Client, |
| 35 | pub message: Arc<Mutex<Option<String>>>, | |
| 35 | pub message: Option<String>, | |
| 36 | 36 | pub load: bool, |
| 37 | 37 | pub render: bool, |
| 38 | 38 | pub popup_focus: bool, |
| @@ -43,10 +43,72 @@ pub struct App { | ||
| 43 | 43 | pub page_no: usize, |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | pub struct AppNoState { | |
| 47 | pub config: Config, | |
| 48 | pub page: Page, | |
| 49 | pub selectable: Vec<Vec<(usize, usize)>>, | |
| 50 | pub hover: Option<(usize, usize)>, // x, y | |
| 51 | pub selected: Option<(usize, usize)>, | |
| 52 | pub client: Client, | |
| 53 | pub message: Option<String>, | |
| 54 | pub load: bool, | |
| 55 | pub render: bool, | |
| 56 | pub popup_focus: bool, | |
| 57 | pub history: Vec<AppHistory>, | |
| 58 | pub watch_history: WatchHistory, | |
| 59 | pub search_settings: SearchSettings, | |
| 60 | pub search_text: String, | |
| 61 | pub page_no: usize, | |
| 62 | } | |
| 63 | ||
| 64 | impl AppNoState { | |
| 65 | pub fn split(app: App) -> (Self, Vec<Row>) { | |
| 66 | let out = Self { | |
| 67 | config: app.config, | |
| 68 | page: app.page, | |
| 69 | selectable: app.selectable, | |
| 70 | hover: app.hover, | |
| 71 | selected: app.selected, | |
| 72 | client: app.client, | |
| 73 | message: app.message, | |
| 74 | load: app.load, | |
| 75 | render: app.render, | |
| 76 | popup_focus: app.popup_focus, | |
| 77 | history: app.history, | |
| 78 | watch_history: app.watch_history, | |
| 79 | search_settings: app.search_settings, | |
| 80 | search_text: app.search_text, | |
| 81 | page_no: app.page_no, | |
| 82 | }; | |
| 83 | (out, app.state) | |
| 84 | } | |
| 85 | ||
| 86 | pub fn join(app: Self, state: Vec<Row>) -> App { | |
| 87 | App { | |
| 88 | config: app.config, | |
| 89 | page: app.page, | |
| 90 | selectable: app.selectable, | |
| 91 | hover: app.hover, | |
| 92 | selected: app.selected, | |
| 93 | client: app.client, | |
| 94 | message: app.message, | |
| 95 | load: app.load, | |
| 96 | render: app.render, | |
| 97 | popup_focus: app.popup_focus, | |
| 98 | history: app.history, | |
| 99 | watch_history: app.watch_history, | |
| 100 | search_settings: app.search_settings, | |
| 101 | search_text: app.search_text, | |
| 102 | page_no: app.page_no, | |
| 103 | state, | |
| 104 | } | |
| 105 | } | |
| 106 | } | |
| 107 | ||
| 46 | 108 | impl Default for App { |
| 47 | 109 | fn default() -> Self { |
| 48 | 110 | let config = Config::load().unwrap(); |
| 49 | let state = MainMenu::default(); | |
| 111 | let state = config.layouts.main_menu.clone().into(); | |
| 50 | 112 | let selectable = App::selectable(&state); |
| 51 | 113 | Self { |
| 52 | 114 | page: Page::default(), |
| @@ -55,7 +117,7 @@ impl Default for App { | ||
| 55 | 117 | client: Client::new(config.main.server_url.clone()), |
| 56 | 118 | selected: None, |
| 57 | 119 | hover: None, |
| 58 | message: Arc::new(Mutex::new(None)), | |
| 120 | message: None, | |
| 59 | 121 | load: true, |
| 60 | 122 | render: true, |
| 61 | 123 | popup_focus: false, |
| @@ -213,12 +275,7 @@ impl App { | ||
| 213 | 275 | let size = frame.size(); |
| 214 | 276 | let mut popups = Vec::new(); |
| 215 | 277 | |
| 216 | let min = match self.page { | |
| 217 | Page::MainMenu(_) => MainMenu::min(), | |
| 218 | Page::ItemDisplay(_) => ItemInfo::min(), | |
| 219 | Page::Search => Search::min(), | |
| 220 | Page::Channel(_, _) => Channel::min(), | |
| 221 | }; | |
| 278 | let min = self.page.min(&self.config); | |
| 222 | 279 | |
| 223 | 280 | if size.width < min.0 || size.height < min.1 { |
| 224 | 281 | let paragraph = Paragraph::new(format!( |
| @@ -248,7 +305,7 @@ impl App { | ||
| 248 | 305 | ) |
| 249 | 306 | .split(size); |
| 250 | 307 | |
| 251 | let mut state = self.state.clone(); | |
| 308 | let (mut app, mut state) = AppNoState::split(self); | |
| 252 | 309 | |
| 253 | 310 | for (y, (row, row_chunk)) in state |
| 254 | 311 | .iter_mut() |
| @@ -294,15 +351,14 @@ impl App { | ||
| 294 | 351 | .zip(row.items.iter_mut().map(|i| &mut i.item)) |
| 295 | 352 | .enumerate() |
| 296 | 353 | { |
| 297 | let selected = self.selected == Some((x, y)); | |
| 354 | let selected = app.selected == Some((x, y)); | |
| 298 | 355 | |
| 299 | 356 | let hover = hover_selected == Some((x, y)); |
| 300 | let popup_focus = self.popup_focus; | |
| 357 | let popup_focus = app.popup_focus; | |
| 301 | 358 | |
| 302 | let hold = | |
| 303 | item.render_item(frame, chunk, self, selected, hover, popup_focus, false); | |
| 359 | let hold = item.render_item(frame, chunk, app, selected, hover, popup_focus, false); | |
| 304 | 360 | |
| 305 | self = hold.1; | |
| 361 | app = hold.1; | |
| 306 | 362 | |
| 307 | 363 | if hold.0 { |
| 308 | 364 | popups.push((item, selected, hover, chunk)); |
| @@ -311,19 +367,17 @@ impl App { | ||
| 311 | 367 | } |
| 312 | 368 | |
| 313 | 369 | for (item, selected, hover, chunk) in popups { |
| 314 | let hold = item.render_item(frame, chunk, self, selected, hover, true, true); | |
| 315 | self = hold.1; | |
| 316 | ||
| 370 | let hold = item.render_item(frame, chunk, app, selected, hover, true, true); | |
| 371 | app = hold.1; | |
| 317 | 372 | } |
| 318 | 373 | |
| 319 | self.state = state; | |
| 320 | ||
| 374 | self = AppNoState::join(app, state); | |
| 321 | 375 | self |
| 322 | 376 | } |
| 323 | 377 | |
| 324 | 378 | pub fn pop(mut self) -> (App, bool) { |
| 325 | 379 | if self.history.len() == 0 { |
| 326 | *self.message.lock().unwrap() = Some(String::from("This is the beginning of history")); | |
| 380 | self.message = Some(String::from("This is the beginning of history")); | |
| 327 | 381 | return (self, false); |
| 328 | 382 | } |
| 329 | 383 | |
src/app/config/commands.rs +14 −2
| @@ -3,13 +3,13 @@ use std::{collections::HashMap, thread}; | ||
| 3 | 3 | |
| 4 | 4 | use crate::traits::ConfigItem; |
| 5 | 5 | |
| 6 | #[derive(Serialize, Deserialize, Clone, Debug)] | |
| 6 | #[derive(Serialize, Deserialize, Clone)] | |
| 7 | 7 | pub struct Command { |
| 8 | 8 | pub args: Vec<String>, |
| 9 | 9 | pub message: String, |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | #[derive(Serialize, Deserialize, Clone, Debug)] | |
| 12 | #[derive(Serialize, Deserialize, Clone)] | |
| 13 | 13 | pub struct CommandsConfig(pub HashMap<String, Command>); |
| 14 | 14 | |
| 15 | 15 | impl Command { |
| @@ -99,6 +99,18 @@ impl Default for CommandsConfig { | ||
| 99 | 99 | ], |
| 100 | 100 | "Opened mpv in new konsole window", |
| 101 | 101 | ); |
| 102 | out.insert( | |
| 103 | "audio_loop", | |
| 104 | vec![ | |
| 105 | "konsole", | |
| 106 | "-e", | |
| 107 | "mpv", | |
| 108 | "{embed_url}", | |
| 109 | "--no-video", | |
| 110 | "--loop", | |
| 111 | ], | |
| 112 | "Opened mpv in new konsole window", | |
| 113 | ); | |
| 102 | 114 | out.insert( |
| 103 | 115 | "video_downloader", |
| 104 | 116 | vec![ |
src/app/config/config.rs +7 −2
| @@ -1,14 +1,17 @@ | ||
| 1 | 1 | use std::error::Error; |
| 2 | 2 | |
| 3 | use super::{commands::CommandsConfig, MainConfig, PageCommandsConfig, KeybindingsConfig}; | |
| 3 | use super::{ | |
| 4 | commands::CommandsConfig, KeybindingsConfig, LayoutsConfigs, MainConfig, PageCommandsConfig, | |
| 5 | }; | |
| 4 | 6 | use crate::traits::ConfigItem; |
| 5 | 7 | |
| 6 | #[derive(Clone, Debug)] | |
| 8 | #[derive(Clone)] | |
| 7 | 9 | pub struct Config { |
| 8 | 10 | pub commands: CommandsConfig, |
| 9 | 11 | pub main: MainConfig, |
| 10 | 12 | pub page_commands: PageCommandsConfig, |
| 11 | 13 | pub keybindings: KeybindingsConfig, |
| 14 | pub layouts: LayoutsConfigs, | |
| 12 | 15 | } |
| 13 | 16 | |
| 14 | 17 | impl Default for Config { |
| @@ -18,6 +21,7 @@ impl Default for Config { | ||
| 18 | 21 | main: MainConfig::default(), |
| 19 | 22 | page_commands: PageCommandsConfig::default(), |
| 20 | 23 | keybindings: KeybindingsConfig::default(), |
| 24 | layouts: LayoutsConfigs::default(), | |
| 21 | 25 | } |
| 22 | 26 | } |
| 23 | 27 | } |
| @@ -29,6 +33,7 @@ impl Config { | ||
| 29 | 33 | commands: CommandsConfig::load()?, |
| 30 | 34 | page_commands: PageCommandsConfig::load()?, |
| 31 | 35 | keybindings: KeybindingsConfig::load()?.into(), |
| 36 | layouts: LayoutsConfigs::load()?, | |
| 32 | 37 | }) |
| 33 | 38 | } |
| 34 | 39 | } |
src/app/config/keybindings.rs +10 −11
| @@ -1,11 +1,11 @@ | ||
| 1 | 1 | use std::collections::HashMap; |
| 2 | 2 | |
| 3 | 3 | use crossterm::event::KeyCode; |
| 4 | use serde::{Serialize, Deserialize}; | |
| 4 | use serde::{Deserialize, Serialize}; | |
| 5 | 5 | |
| 6 | 6 | use crate::traits::ConfigItem; |
| 7 | 7 | |
| 8 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] | |
| 8 | #[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq)] | |
| 9 | 9 | pub enum Action { |
| 10 | 10 | Up, |
| 11 | 11 | Down, |
| @@ -21,7 +21,7 @@ pub enum Action { | ||
| 21 | 21 | ClearHistory, |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)] | |
| 24 | #[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] | |
| 25 | 25 | pub enum KeyCodeTransitional { |
| 26 | 26 | Backspace, |
| 27 | 27 | Enter, |
| @@ -64,7 +64,7 @@ impl Into<KeyCode> for KeyCodeTransitional { | ||
| 64 | 64 | Self::Char(c) => KeyCode::Char(c), |
| 65 | 65 | Self::Null => KeyCode::Null, |
| 66 | 66 | Self::Esc => KeyCode::Esc, |
| 67 | } | |
| 67 | } | |
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
| @@ -80,8 +80,8 @@ impl Into<KeybindingsConfig> for KeybindingsConfigTransitional { | ||
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | #[derive(Serialize, Deserialize, Debug, Clone)] | |
| 84 | pub struct KeybindingsConfigTransitional (pub HashMap<KeyCodeTransitional, Action>); | |
| 83 | #[derive(Serialize, Deserialize, Clone)] | |
| 84 | pub struct KeybindingsConfigTransitional(pub HashMap<KeyCodeTransitional, Action>); | |
| 85 | 85 | |
| 86 | 86 | impl Default for KeybindingsConfigTransitional { |
| 87 | 87 | fn default() -> Self { |
| @@ -103,7 +103,7 @@ impl Default for KeybindingsConfigTransitional { | ||
| 103 | 103 | out.insert(KeyCodeTransitional::Enter, Action::Select); |
| 104 | 104 | out.insert(KeyCodeTransitional::Esc, Action::Deselect); |
| 105 | 105 | out.insert(KeyCodeTransitional::Char('q'), Action::Exit); |
| 106 | ||
| 106 | ||
| 107 | 107 | out.insert(KeyCodeTransitional::Home, Action::Home); |
| 108 | 108 | out.insert(KeyCodeTransitional::Backspace, Action::Back); |
| 109 | 109 | out.insert(KeyCodeTransitional::End, Action::ClearHistory); |
| @@ -118,11 +118,10 @@ impl Default for KeybindingsConfig { | ||
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | #[derive(Debug, Clone)] | |
| 122 | pub struct KeybindingsConfig (pub HashMap<KeyCode, Action>); | |
| 123 | ||
| 121 | #[derive(Clone)] | |
| 122 | pub struct KeybindingsConfig(pub HashMap<KeyCode, Action>); | |
| 124 | 123 | |
| 125 | impl ConfigItem<'_> for KeybindingsConfig { | |
| 124 | impl ConfigItem<'_> for KeybindingsConfig { | |
| 126 | 125 | type Struct = KeybindingsConfigTransitional; |
| 127 | 126 | const FILE_NAME: &'static str = "keybindings.yml"; |
| 128 | 127 | } |
src/app/config/layouts.rs added +175
| @@ -0,0 +1,175 @@ | ||
| 1 | use crate::{ | |
| 2 | app::pages::{ | |
| 3 | channel::{Channel, ChannelDisplayItem, ChannelItem, ChannelPage}, | |
| 4 | global::GlobalItem, | |
| 5 | item_info::{ItemInfo, ItemInfoItem}, | |
| 6 | main_menu::{MainMenu, MainMenuItem, MainMenuSelector}, | |
| 7 | search::{Search, SearchItem}, | |
| 8 | }, | |
| 9 | structs::{Item, Row, RowItem}, | |
| 10 | traits::{ConfigItem, PageTrait}, | |
| 11 | widgets::text_list::TextList, | |
| 12 | }; | |
| 13 | use serde::{Deserialize, Serialize}; | |
| 14 | use tui::layout::Constraint; | |
| 15 | ||
| 16 | #[derive(Serialize, Deserialize, Clone)] | |
| 17 | pub struct LayoutsConfigs { | |
| 18 | #[serde(default = "MainMenu::default")] | |
| 19 | pub main_menu: LayoutConfig, | |
| 20 | #[serde(default = "Channel::default")] | |
| 21 | pub channel: LayoutConfig, | |
| 22 | #[serde(default = "ItemInfo::default")] | |
| 23 | pub item_info: LayoutConfig, | |
| 24 | #[serde(default = "Search::default")] | |
| 25 | pub search: LayoutConfig, | |
| 26 | } | |
| 27 | ||
| 28 | impl Default for LayoutsConfigs { | |
| 29 | fn default() -> Self { | |
| 30 | Self { | |
| 31 | main_menu: MainMenu::default(), | |
| 32 | channel: Channel::default(), | |
| 33 | item_info: ItemInfo::default(), | |
| 34 | search: Search::default(), | |
| 35 | } | |
| 36 | } | |
| 37 | } | |
| 38 | ||
| 39 | #[derive(Serialize, Deserialize, Clone, Copy)] | |
| 40 | pub enum ConstraintTransitional { | |
| 41 | Percentage(u16), | |
| 42 | Ratio(u32, u32), | |
| 43 | Length(u16), | |
| 44 | Max(u16), | |
| 45 | Min(u16), | |
| 46 | } | |
| 47 | ||
| 48 | impl Into<Constraint> for ConstraintTransitional { | |
| 49 | fn into(self) -> Constraint { | |
| 50 | match self { | |
| 51 | Self::Percentage(i) => Constraint::Percentage(i), | |
| 52 | Self::Ratio(i1, i2) => Constraint::Ratio(i1, i2), | |
| 53 | Self::Length(i) => Constraint::Length(i), | |
| 54 | Self::Max(i) => Constraint::Max(i), | |
| 55 | Self::Min(i) => Constraint::Min(i), | |
| 56 | } | |
| 57 | } | |
| 58 | } | |
| 59 | ||
| 60 | #[derive(Serialize, Deserialize, Clone)] | |
| 61 | pub struct LayoutConfig { | |
| 62 | pub layout: Vec<RowTransitional>, | |
| 63 | pub min: (u16, u16), | |
| 64 | pub message: String, | |
| 65 | } | |
| 66 | ||
| 67 | impl Into<Vec<Row>> for LayoutConfig { | |
| 68 | fn into(self) -> Vec<Row> { | |
| 69 | self.layout.into_iter().map(|item| item.into()).collect() | |
| 70 | } | |
| 71 | } | |
| 72 | ||
| 73 | #[derive(Serialize, Deserialize, Clone)] | |
| 74 | pub struct RowTransitional { | |
| 75 | pub items: Vec<RowItemTransitional>, | |
| 76 | pub centered: bool, | |
| 77 | pub height: ConstraintTransitional, | |
| 78 | } | |
| 79 | ||
| 80 | impl Into<Row> for RowTransitional { | |
| 81 | fn into(self) -> Row { | |
| 82 | Row { | |
| 83 | items: self.items.into_iter().map(|item| item.into()).collect(), | |
| 84 | centered: self.centered, | |
| 85 | height: self.height.into(), | |
| 86 | } | |
| 87 | } | |
| 88 | } | |
| 89 | ||
| 90 | #[derive(Serialize, Deserialize, Clone)] | |
| 91 | pub struct RowItemTransitional { | |
| 92 | pub item: ItemTransitional, | |
| 93 | pub constraint: ConstraintTransitional, | |
| 94 | } | |
| 95 | ||
| 96 | impl Into<RowItem> for RowItemTransitional { | |
| 97 | fn into(self) -> RowItem { | |
| 98 | RowItem { | |
| 99 | item: self.item.into(), | |
| 100 | constraint: self.constraint.into(), | |
| 101 | } | |
| 102 | } | |
| 103 | } | |
| 104 | ||
| 105 | #[derive(Serialize, Deserialize, Clone)] | |
| 106 | pub enum ItemTransitional { | |
| 107 | Global(GlobalItem), | |
| 108 | MainMenu(MainMenuItemTransitional), | |
| 109 | ItemInfo, | |
| 110 | Search(SearchItemTransitional), | |
| 111 | Channel(ChannelItemTransitional), | |
| 112 | } | |
| 113 | ||
| 114 | impl Into<Item> for ItemTransitional { | |
| 115 | fn into(self) -> Item { | |
| 116 | match self { | |
| 117 | Self::Global(i) => Item::Global(i), | |
| 118 | Self::MainMenu(i) => Item::MainMenu(i.into()), | |
| 119 | Self::ItemInfo => Item::ItemInfo(ItemInfoItem::Unknown), | |
| 120 | Self::Search(i) => Item::Search(i.into()), | |
| 121 | Self::Channel(i) => Item::Channel(i.into()), | |
| 122 | } | |
| 123 | } | |
| 124 | } | |
| 125 | ||
| 126 | #[derive(Serialize, Deserialize, Clone, Copy)] | |
| 127 | pub enum MainMenuItemTransitional { | |
| 128 | SelectorTab(MainMenuSelector), | |
| 129 | VideoList, | |
| 130 | } | |
| 131 | ||
| 132 | impl Into<MainMenuItem> for MainMenuItemTransitional { | |
| 133 | fn into(self) -> MainMenuItem { | |
| 134 | match self { | |
| 135 | Self::SelectorTab(i) => MainMenuItem::SeletorTab(i), | |
| 136 | Self::VideoList => MainMenuItem::VideoList(None), | |
| 137 | } | |
| 138 | } | |
| 139 | } | |
| 140 | ||
| 141 | #[derive(Serialize, Deserialize, Clone, Copy)] | |
| 142 | pub enum ChannelItemTransitional { | |
| 143 | InfoDisplay, | |
| 144 | SelectItems(ChannelPage), | |
| 145 | } | |
| 146 | ||
| 147 | impl Into<ChannelItem> for ChannelItemTransitional { | |
| 148 | fn into(self) -> ChannelItem { | |
| 149 | match self { | |
| 150 | Self::InfoDisplay => ChannelItem::InfoDisplay(ChannelDisplayItem::Unknown), | |
| 151 | Self::SelectItems(i) => ChannelItem::SelectItems(i), | |
| 152 | } | |
| 153 | } | |
| 154 | } | |
| 155 | ||
| 156 | #[derive(Serialize, Deserialize, Clone, Copy)] | |
| 157 | pub enum SearchItemTransitional { | |
| 158 | Search, | |
| 159 | } | |
| 160 | ||
| 161 | impl Into<SearchItem> for SearchItemTransitional { | |
| 162 | fn into(self) -> SearchItem { | |
| 163 | match self { | |
| 164 | Self::Search => SearchItem::Search { | |
| 165 | results: None, | |
| 166 | text_list: TextList::default(), | |
| 167 | }, | |
| 168 | } | |
| 169 | } | |
| 170 | } | |
| 171 | ||
| 172 | impl ConfigItem<'_> for LayoutsConfigs { | |
| 173 | type Struct = LayoutsConfigs; | |
| 174 | const FILE_NAME: &'static str = "layouts.yml"; | |
| 175 | } | |
src/app/config/main.rs +1 −1
| @@ -22,7 +22,7 @@ fn env_default() -> HashMap<String, String> { | ||
| 22 | 22 | out |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
| 25 | #[derive(Clone, Serialize, Deserialize)] | |
| 26 | 26 | pub struct MainConfig { |
| 27 | 27 | #[serde(default = "max_watch_history_default")] |
| 28 | 28 | pub max_watch_history: usize, |
src/app/config/mod.rs +3
| @@ -11,3 +11,6 @@ pub use page_commands::*; | ||
| 11 | 11 | |
| 12 | 12 | mod keybindings; |
| 13 | 13 | pub use keybindings::*; |
| 14 | ||
| 15 | mod layouts; | |
| 16 | pub use layouts::*; | |
src/app/config/page_commands.rs +3 −2
| @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; | ||
| 4 | 4 | |
| 5 | 5 | use crate::traits::ConfigItem; |
| 6 | 6 | |
| 7 | #[derive(Debug, Clone, Serialize, Deserialize)] | |
| 7 | #[derive(Clone, Serialize, Deserialize)] | |
| 8 | 8 | pub struct PageCommandsConfig(pub HashMap<String, Vec<PageCommand>>); |
| 9 | 9 | |
| 10 | 10 | impl PageCommandsConfig { |
| @@ -22,6 +22,7 @@ impl Default for PageCommandsConfig { | ||
| 22 | 22 | vec![ |
| 23 | 23 | PageCommand::from("Watch video", "video_player"), |
| 24 | 24 | PageCommand::from("Play audio", "audio_player"), |
| 25 | PageCommand::from("Play audio (loop)", "audio_loop"), | |
| 25 | 26 | PageCommand::from("Download video", "video_downloader"), |
| 26 | 27 | PageCommand::from("Download audio", "audio_downloader"), |
| 27 | 28 | PageCommand::from("Visit channel", "{goto_channel}"), |
| @@ -51,7 +52,7 @@ impl Default for PageCommandsConfig { | ||
| 51 | 52 | } |
| 52 | 53 | } |
| 53 | 54 | |
| 54 | #[derive(Debug, Clone, Serialize, Deserialize)] | |
| 55 | #[derive(Clone, Serialize, Deserialize)] | |
| 55 | 56 | pub struct PageCommand { |
| 56 | 57 | pub label: String, |
| 57 | 58 | pub command: String, |
src/app/pages/channel.rs +77 −77
| @@ -1,20 +1,25 @@ | ||
| 1 | 1 | use std::{collections::LinkedList, error::Error}; |
| 2 | 2 | |
| 3 | 3 | use crossterm::event::KeyCode; |
| 4 | use serde::{Deserialize, Serialize}; | |
| 4 | 5 | use tui::{ |
| 5 | 6 | backend::Backend, |
| 6 | layout::{Alignment, Constraint, Rect}, | |
| 7 | layout::{Alignment, Rect}, | |
| 7 | 8 | style::{Color, Style}, |
| 8 | 9 | widgets::{Block, BorderType, Borders, Paragraph}, |
| 9 | 10 | Frame, |
| 10 | 11 | }; |
| 11 | 12 | |
| 12 | 13 | use crate::{ |
| 13 | app::{app::App, config::Action}, | |
| 14 | functions::download_all_thumbnails, | |
| 15 | structs::{ | |
| 16 | FullChannel, Item, ListItem, MiniPlayList, MiniVideo, Page, Row, RowItem, WatchHistory, | |
| 14 | app::{ | |
| 15 | app::{App, AppNoState}, | |
| 16 | config::{ | |
| 17 | Action, ChannelItemTransitional, ConstraintTransitional, ItemTransitional, | |
| 18 | LayoutConfig, RowItemTransitional, RowTransitional, | |
| 19 | }, | |
| 17 | 20 | }, |
| 21 | functions::download_all_thumbnails, | |
| 22 | structs::{FullChannel, Item, ListItem, MiniPlayList, MiniVideo, Page, WatchHistory}, | |
| 18 | 23 | traits::{ItemTrait, PageTrait}, |
| 19 | 24 | widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList}, |
| 20 | 25 | }; |
| @@ -24,7 +29,7 @@ use super::{ | ||
| 24 | 29 | item_info::{DisplayItem, ItemInfo}, |
| 25 | 30 | }; |
| 26 | 31 | |
| 27 | #[derive(Debug, Clone, Copy, PartialEq)] | |
| 32 | #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] | |
| 28 | 33 | pub enum ChannelPage { |
| 29 | 34 | Home, |
| 30 | 35 | Playlists, |
| @@ -118,22 +123,15 @@ impl ItemTrait for ChannelItem { | ||
| 118 | 123 | } |
| 119 | 124 | |
| 120 | 125 | fn render_item<B: Backend>( |
| 121 | // &mut self, | |
| 122 | // frame: &mut Frame<B>, | |
| 123 | // rect: Rect, | |
| 124 | // selected: bool, | |
| 125 | // hover: bool, | |
| 126 | // popup_focus: bool, | |
| 127 | // page: &Page, | |
| 128 | 126 | &mut self, |
| 129 | 127 | frame: &mut Frame<B>, |
| 130 | 128 | rect: Rect, |
| 131 | app: App, | |
| 129 | app: AppNoState, | |
| 132 | 130 | selected: bool, |
| 133 | 131 | hover: bool, |
| 134 | 132 | popup_focus: bool, |
| 135 | 133 | _: bool, |
| 136 | ) -> (bool, App) { | |
| 134 | ) -> (bool, AppNoState) { | |
| 137 | 135 | let mut out = (false, app); |
| 138 | 136 | |
| 139 | 137 | let mut style = Style::default().fg(if selected { |
| @@ -300,7 +298,7 @@ impl ItemTrait for ChannelItem { | ||
| 300 | 298 | Action::FirstItem => textlist.first(), |
| 301 | 299 | Action::LastItem => textlist.last(), |
| 302 | 300 | Action::Select => { |
| 303 | let state = ItemInfo::default(); | |
| 301 | let state = app.config.layouts.item_info.clone().into(); | |
| 304 | 302 | let mut history = app.history.clone(); |
| 305 | 303 | history.push(app.into()); |
| 306 | 304 | |
| @@ -330,7 +328,7 @@ impl ItemTrait for ChannelItem { | ||
| 330 | 328 | Action::FirstItem => textlist.first(), |
| 331 | 329 | Action::LastItem => textlist.last(), |
| 332 | 330 | Action::Select => { |
| 333 | let state = ItemInfo::default(); | |
| 331 | let state = app.config.layouts.item_info.clone().into(); | |
| 334 | 332 | let mut history = app.history.clone(); |
| 335 | 333 | history.push(app.into()); |
| 336 | 334 | |
| @@ -370,7 +368,7 @@ impl ItemTrait for ChannelItem { | ||
| 370 | 368 | return (app, false); |
| 371 | 369 | } |
| 372 | 370 | |
| 373 | let state = Channel::default(); | |
| 371 | let state = app.config.layouts.channel.clone().into(); | |
| 374 | 372 | let mut history = app.history.clone(); |
| 375 | 373 | history.push(app.into()); |
| 376 | 374 | |
| @@ -399,64 +397,66 @@ impl ItemTrait for ChannelItem { | ||
| 399 | 397 | pub struct Channel; |
| 400 | 398 | |
| 401 | 399 | impl PageTrait for Channel { |
| 402 | fn message() -> String { | |
| 403 | String::from("Loading channel info...") | |
| 404 | } | |
| 405 | ||
| 406 | fn min() -> (u16, u16) { | |
| 407 | (45, 15) | |
| 408 | } | |
| 409 | ||
| 410 | fn default() -> Vec<Row> { | |
| 411 | vec![ | |
| 412 | Row { | |
| 413 | items: vec![ | |
| 414 | RowItem { | |
| 415 | item: Item::Global(GlobalItem::SearchBar), | |
| 416 | constraint: Constraint::Min(16), | |
| 417 | }, | |
| 418 | RowItem { | |
| 419 | item: Item::Global(GlobalItem::SearchSettings), | |
| 420 | constraint: Constraint::Length(5), | |
| 421 | }, | |
| 422 | ], | |
| 423 | centered: false, | |
| 424 | height: Constraint::Length(3), | |
| 425 | }, | |
| 426 | Row { | |
| 427 | items: vec![ | |
| 428 | RowItem { | |
| 429 | item: Item::Channel(ChannelItem::SelectItems(ChannelPage::Home)), | |
| 430 | constraint: Constraint::Length(15), | |
| 431 | }, | |
| 432 | RowItem { | |
| 433 | item: Item::Channel(ChannelItem::SelectItems(ChannelPage::Videos)), | |
| 434 | constraint: Constraint::Length(15), | |
| 435 | }, | |
| 436 | RowItem { | |
| 437 | item: Item::Channel(ChannelItem::SelectItems(ChannelPage::Playlists)), | |
| 438 | constraint: Constraint::Length(15), | |
| 439 | }, | |
| 440 | ], | |
| 441 | centered: true, | |
| 442 | height: Constraint::Length(3), | |
| 443 | }, | |
| 444 | Row { | |
| 445 | items: vec![RowItem { | |
| 446 | item: Item::Channel(ChannelItem::InfoDisplay(ChannelDisplayItem::Unknown)), | |
| 447 | constraint: Constraint::Percentage(100), | |
| 448 | }], | |
| 449 | centered: false, | |
| 450 | height: Constraint::Min(6), | |
| 451 | }, | |
| 452 | Row { | |
| 453 | items: vec![RowItem { | |
| 454 | item: Item::Global(GlobalItem::MessageBar), | |
| 455 | constraint: Constraint::Percentage(100), | |
| 456 | }], | |
| 457 | centered: false, | |
| 458 | height: Constraint::Length(3), | |
| 459 | }, | |
| 460 | ] | |
| 400 | fn default() -> LayoutConfig { | |
| 401 | LayoutConfig { | |
| 402 | layout: vec![ | |
| 403 | RowTransitional { | |
| 404 | items: vec![ | |
| 405 | RowItemTransitional { | |
| 406 | item: ItemTransitional::Global(GlobalItem::SearchBar), | |
| 407 | constraint: ConstraintTransitional::Min(16), | |
| 408 | }, | |
| 409 | RowItemTransitional { | |
| 410 | item: ItemTransitional::Global(GlobalItem::SearchSettings), | |
| 411 | constraint: ConstraintTransitional::Length(5), | |
| 412 | }, | |
| 413 | ], | |
| 414 | centered: false, | |
| 415 | height: ConstraintTransitional::Length(3), | |
| 416 | }, | |
| 417 | RowTransitional { | |
| 418 | items: vec![ | |
| 419 | RowItemTransitional { | |
| 420 | item: ItemTransitional::Channel(ChannelItemTransitional::SelectItems( | |
| 421 | ChannelPage::Home, | |
| 422 | )), | |
| 423 | constraint: ConstraintTransitional::Length(15), | |
| 424 | }, | |
| 425 | RowItemTransitional { | |
| 426 | item: ItemTransitional::Channel(ChannelItemTransitional::SelectItems( | |
| 427 | ChannelPage::Videos, | |
| 428 | )), | |
| 429 | constraint: ConstraintTransitional::Length(15), | |
| 430 | }, | |
| 431 | RowItemTransitional { | |
| 432 | item: ItemTransitional::Channel(ChannelItemTransitional::SelectItems( | |
| 433 | ChannelPage::Playlists, | |
| 434 | )), | |
| 435 | constraint: ConstraintTransitional::Length(15), | |
| 436 | }, | |
| 437 | ], | |
| 438 | centered: true, | |
| 439 | height: ConstraintTransitional::Length(3), | |
| 440 | }, | |
| 441 | RowTransitional { | |
| 442 | items: vec![RowItemTransitional { | |
| 443 | item: ItemTransitional::Channel(ChannelItemTransitional::InfoDisplay), | |
| 444 | constraint: ConstraintTransitional::Percentage(100), | |
| 445 | }], | |
| 446 | centered: false, | |
| 447 | height: ConstraintTransitional::Min(6), | |
| 448 | }, | |
| 449 | RowTransitional { | |
| 450 | items: vec![RowItemTransitional { | |
| 451 | item: ItemTransitional::Global(GlobalItem::MessageBar), | |
| 452 | constraint: ConstraintTransitional::Percentage(100), | |
| 453 | }], | |
| 454 | centered: false, | |
| 455 | height: ConstraintTransitional::Length(3), | |
| 456 | }, | |
| 457 | ], | |
| 458 | min: (46, 15), | |
| 459 | message: String::from("Loading channel info..."), | |
| 460 | } | |
| 461 | 461 | } |
| 462 | 462 | } |
src/app/pages/global.rs +8 −9
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | use std::fmt; |
| 2 | 2 | |
| 3 | 3 | use crossterm::event::KeyCode; |
| 4 | use serde::{Deserialize, Serialize}; | |
| 4 | 5 | use tui::{ |
| 5 | 6 | backend::Backend, |
| 6 | 7 | layout::{Alignment, Rect}, |
| @@ -10,7 +11,7 @@ use tui::{ | ||
| 10 | 11 | }; |
| 11 | 12 | |
| 12 | 13 | use crate::{ |
| 13 | app::app::App, | |
| 14 | app::app::{App, AppNoState}, | |
| 14 | 15 | functions::center_rect, |
| 15 | 16 | structs::{Item, Page, WatchHistory}, |
| 16 | 17 | traits::{ItemTrait, PageTrait}, |
| @@ -19,7 +20,7 @@ use crate::{ | ||
| 19 | 20 | |
| 20 | 21 | use super::search::Search; |
| 21 | 22 | |
| 22 | #[derive(Debug, Clone)] | |
| 23 | #[derive(Debug, Clone, Serialize, Deserialize)] | |
| 23 | 24 | pub enum GlobalItem { |
| 24 | 25 | SearchBar, |
| 25 | 26 | SearchSettings, |
| @@ -82,10 +83,9 @@ impl ItemTrait for GlobalItem { | ||
| 82 | 83 | } |
| 83 | 84 | KeyCode::Enter => { |
| 84 | 85 | if app.search_text.len() == 0 { |
| 85 | *app.message.lock().unwrap() = | |
| 86 | Some(String::from("Search term cannot be empty")); | |
| 86 | app.message = Some(String::from("Search term cannot be empty")); | |
| 87 | 87 | } else { |
| 88 | let state = Search::default(); | |
| 88 | let state = app.config.layouts.search.clone().into(); | |
| 89 | 89 | let mut history = app.history.clone(); |
| 90 | 90 | let search_text = app.search_text.clone(); |
| 91 | 91 | let search_settings = app.search_settings.clone(); |
| @@ -121,12 +121,12 @@ impl ItemTrait for GlobalItem { | ||
| 121 | 121 | &mut self, |
| 122 | 122 | frame: &mut Frame<B>, |
| 123 | 123 | rect: Rect, |
| 124 | app: App, | |
| 124 | app: AppNoState, | |
| 125 | 125 | selected: bool, |
| 126 | 126 | hover: bool, |
| 127 | 127 | _: bool, |
| 128 | 128 | popup_render: bool, |
| 129 | ) -> (bool, App) { | |
| 129 | ) -> (bool, AppNoState) { | |
| 130 | 130 | let area = frame.size(); |
| 131 | 131 | let mut out = (false, app); |
| 132 | 132 | match self { |
| @@ -151,8 +151,7 @@ impl ItemTrait for GlobalItem { | ||
| 151 | 151 | frame.render_widget(paragraph, rect); |
| 152 | 152 | } |
| 153 | 153 | GlobalItem::MessageBar => { |
| 154 | let message = out.1.message.lock().unwrap(); | |
| 155 | // let color = Color::LightYellow; | |
| 154 | let message = out.1.message.clone(); | |
| 156 | 155 | let block = Block::default() |
| 157 | 156 | .border_type(BorderType::Rounded) |
| 158 | 157 | .borders(Borders::ALL) |
src/app/pages/item_info.rs +60 −71
| @@ -2,33 +2,36 @@ use std::{collections::LinkedList, error::Error}; | ||
| 2 | 2 | |
| 3 | 3 | use crate::{ |
| 4 | 4 | app::{ |
| 5 | app::App, | |
| 6 | config::{Action, PageCommand}, | |
| 5 | app::{App, AppNoState}, | |
| 6 | config::{ | |
| 7 | Action, ConstraintTransitional, ItemTransitional, LayoutConfig, PageCommand, | |
| 8 | RowItemTransitional, RowTransitional, | |
| 9 | }, | |
| 7 | 10 | pages::{channel::*, global::*}, |
| 8 | 11 | }, |
| 9 | 12 | functions::download_all_thumbnails, |
| 10 | structs::{FullPlayList, FullVideo, Item, ListItem, Page, Row, RowItem, WatchHistory}, | |
| 13 | structs::{FullPlayList, FullVideo, Item, ListItem, Page, WatchHistory}, | |
| 11 | 14 | traits::{ItemTrait, PageTrait}, |
| 12 | 15 | widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList}, |
| 13 | 16 | }; |
| 14 | 17 | use crossterm::event::KeyCode; |
| 15 | 18 | use tui::{ |
| 16 | 19 | backend::Backend, |
| 17 | layout::{Constraint, Rect}, | |
| 20 | layout::Rect, | |
| 18 | 21 | style::{Color, Style}, |
| 19 | 22 | Frame, |
| 20 | 23 | }; |
| 21 | 24 | |
| 22 | 25 | use super::global::GlobalItem; |
| 23 | 26 | |
| 24 | #[derive(Debug, Clone)] | |
| 27 | #[derive(Clone)] | |
| 25 | 28 | pub enum ItemInfoItem { |
| 26 | 29 | Unknown, |
| 27 | 30 | Video(VideoItemInfo), |
| 28 | 31 | PlayList(PlayListItemInfo), |
| 29 | 32 | } |
| 30 | 33 | |
| 31 | #[derive(Debug, Clone)] | |
| 34 | #[derive(Clone)] | |
| 32 | 35 | pub struct VideoItemInfo { |
| 33 | 36 | video: FullVideo, |
| 34 | 37 | list: TextList, |
| @@ -36,7 +39,7 @@ pub struct VideoItemInfo { | ||
| 36 | 39 | commands: Vec<PageCommand>, |
| 37 | 40 | } |
| 38 | 41 | |
| 39 | #[derive(Debug, Clone)] | |
| 42 | #[derive(Clone)] | |
| 40 | 43 | pub struct PlayListItemInfo { |
| 41 | 44 | playlist: FullPlayList, |
| 42 | 45 | video_view_list: TextList, |
| @@ -46,7 +49,7 @@ pub struct PlayListItemInfo { | ||
| 46 | 49 | commands: Vec<PageCommand>, |
| 47 | 50 | } |
| 48 | 51 | |
| 49 | #[derive(Debug, Clone, Copy)] | |
| 52 | #[derive(Clone, Copy)] | |
| 50 | 53 | pub enum PlayListDisplayView { |
| 51 | 54 | VideoList, |
| 52 | 55 | PlayListView, |
| @@ -72,7 +75,7 @@ impl ItemTrait for ItemInfoItem { | ||
| 72 | 75 | true |
| 73 | 76 | } |
| 74 | 77 | |
| 75 | fn key_input(&mut self, key: KeyCode, app: App) -> (bool, App) { | |
| 78 | fn key_input(&mut self, key: KeyCode, mut app: App) -> (bool, App) { | |
| 76 | 79 | let action = match app.config.keybindings.0.get(&key) { |
| 77 | 80 | Some(action) => *action, |
| 78 | 81 | None => return (false, app), |
| @@ -89,7 +92,7 @@ impl ItemTrait for ItemInfoItem { | ||
| 89 | 92 | match command.command.as_str() { |
| 90 | 93 | "{toggle_mode}" => videoinfo.mode.toggle(), |
| 91 | 94 | "{goto_channel}" => { |
| 92 | let state = Channel::default(); | |
| 95 | let state = app.config.layouts.channel.clone().into(); | |
| 93 | 96 | let mut history = app.history.clone(); |
| 94 | 97 | history.push(app.into()); |
| 95 | 98 | |
| @@ -126,17 +129,13 @@ impl ItemTrait for ItemInfoItem { | ||
| 126 | 129 | |
| 127 | 130 | match command.run_command(&env) { |
| 128 | 131 | Some(e) => { |
| 129 | *app.message.lock().unwrap() = | |
| 130 | Some(format!("Unknown variable `{}`", e)) | |
| 131 | } | |
| 132 | None => { | |
| 133 | *app.message.lock().unwrap() = | |
| 134 | Some(command.message.clone()) | |
| 132 | app.message = Some(format!("Unknown variable `{}`", e)) | |
| 135 | 133 | } |
| 134 | None => app.message = Some(command.message.clone()), | |
| 136 | 135 | } |
| 137 | 136 | } |
| 138 | 137 | None => { |
| 139 | *app.message.lock().unwrap() = | |
| 138 | app.message = | |
| 140 | 139 | Some(format!("Unkown command `{}`", &command.command)); |
| 141 | 140 | } |
| 142 | 141 | }; |
| @@ -159,7 +158,7 @@ impl ItemTrait for ItemInfoItem { | ||
| 159 | 158 | match command.command.as_str() { |
| 160 | 159 | "{toggle_mode}" => playlistinfo.mode.toggle(), |
| 161 | 160 | "{goto_channel}" => { |
| 162 | let state = Channel::default(); | |
| 161 | let state = app.config.layouts.channel.clone().into(); | |
| 163 | 162 | let mut history = app.history.clone(); |
| 164 | 163 | history.push(app.into()); |
| 165 | 164 | |
| @@ -200,17 +199,14 @@ impl ItemTrait for ItemInfoItem { | ||
| 200 | 199 | |
| 201 | 200 | match command.run_command(&env) { |
| 202 | 201 | Some(e) => { |
| 203 | *app.message.lock().unwrap() = | |
| 202 | app.message = | |
| 204 | 203 | Some(format!("Unknown variable `{}`", e)) |
| 205 | 204 | } |
| 206 | None => { | |
| 207 | *app.message.lock().unwrap() = | |
| 208 | Some(command.message.clone()) | |
| 209 | } | |
| 205 | None => app.message = Some(command.message.clone()), | |
| 210 | 206 | } |
| 211 | 207 | } |
| 212 | 208 | None => { |
| 213 | *app.message.lock().unwrap() = | |
| 209 | app.message = | |
| 214 | 210 | Some(format!("Unkown command `{}`", &command.command)); |
| 215 | 211 | } |
| 216 | 212 | }; |
| @@ -231,7 +227,7 @@ impl ItemTrait for ItemInfoItem { | ||
| 231 | 227 | } |
| 232 | 228 | |
| 233 | 229 | x => { |
| 234 | let state = ItemInfo::default(); | |
| 230 | let state = app.config.layouts.channel.clone().into(); | |
| 235 | 231 | let mut history = app.history.clone(); |
| 236 | 232 | history.push(app.into()); |
| 237 | 233 | |
| @@ -357,12 +353,12 @@ impl ItemTrait for ItemInfoItem { | ||
| 357 | 353 | &mut self, |
| 358 | 354 | frame: &mut Frame<B>, |
| 359 | 355 | rect: Rect, |
| 360 | app: App, | |
| 356 | app: AppNoState, | |
| 361 | 357 | selected: bool, |
| 362 | 358 | hover: bool, |
| 363 | 359 | popup_focus: bool, |
| 364 | 360 | popup_render: bool, |
| 365 | ) -> (bool, App) { | |
| 361 | ) -> (bool, AppNoState) { | |
| 366 | 362 | let out = (false, app); |
| 367 | 363 | |
| 368 | 364 | if popup_render { |
| @@ -495,50 +491,43 @@ pub enum DisplayItem { | ||
| 495 | 491 | } |
| 496 | 492 | |
| 497 | 493 | pub struct ItemInfo; |
| 498 | ||
| 499 | 494 | impl PageTrait for ItemInfo { |
| 500 | fn message() -> String { | |
| 501 | String::from("Loading item info...") | |
| 502 | } | |
| 503 | ||
| 504 | fn min() -> (u16, u16) { | |
| 505 | (21, 12) | |
| 506 | } | |
| 507 | ||
| 508 | fn default() -> Vec<Row> { | |
| 509 | vec![ | |
| 510 | Row { | |
| 511 | items: vec![ | |
| 512 | RowItem { | |
| 513 | item: Item::Global(GlobalItem::SearchBar), | |
| 514 | constraint: Constraint::Min(16), | |
| 515 | }, | |
| 516 | RowItem { | |
| 517 | item: Item::Global(GlobalItem::SearchSettings), | |
| 518 | constraint: Constraint::Length(5), | |
| 519 | }, | |
| 520 | ], | |
| 521 | centered: false, | |
| 522 | height: Constraint::Length(3), | |
| 523 | }, | |
| 524 | Row { | |
| 525 | items: vec![RowItem { | |
| 526 | item: Item::ItemInfo(ItemInfoItem::Unknown), | |
| 527 | constraint: Constraint::Percentage(100), | |
| 528 | }], | |
| 529 | centered: false, | |
| 530 | height: Constraint::Min(6), | |
| 531 | }, | |
| 532 | Row { | |
| 533 | items: vec![RowItem { | |
| 534 | item: Item::Global(GlobalItem::MessageBar), | |
| 535 | constraint: Constraint::Percentage(100), | |
| 536 | }], | |
| 537 | centered: false, | |
| 538 | height: Constraint::Length(3), | |
| 539 | }, | |
| 540 | ] | |
| 495 | fn default() -> LayoutConfig { | |
| 496 | LayoutConfig { | |
| 497 | layout: vec![ | |
| 498 | RowTransitional { | |
| 499 | items: vec![ | |
| 500 | RowItemTransitional { | |
| 501 | item: ItemTransitional::Global(GlobalItem::SearchBar), | |
| 502 | constraint: ConstraintTransitional::Min(16), | |
| 503 | }, | |
| 504 | RowItemTransitional { | |
| 505 | item: ItemTransitional::Global(GlobalItem::SearchSettings), | |
| 506 | constraint: ConstraintTransitional::Length(5), | |
| 507 | }, | |
| 508 | ], | |
| 509 | centered: false, | |
| 510 | height: ConstraintTransitional::Length(3), | |
| 511 | }, | |
| 512 | RowTransitional { | |
| 513 | items: vec![RowItemTransitional { | |
| 514 | item: ItemTransitional::ItemInfo, | |
| 515 | constraint: ConstraintTransitional::Percentage(100), | |
| 516 | }], | |
| 517 | centered: false, | |
| 518 | height: ConstraintTransitional::Min(6), | |
| 519 | }, | |
| 520 | RowTransitional { | |
| 521 | items: vec![RowItemTransitional { | |
| 522 | item: ItemTransitional::Global(GlobalItem::MessageBar), | |
| 523 | constraint: ConstraintTransitional::Percentage(100), | |
| 524 | }], | |
| 525 | centered: false, | |
| 526 | height: ConstraintTransitional::Length(3), | |
| 527 | }, | |
| 528 | ], | |
| 529 | min: (21, 12), | |
| 530 | message: String::from("Loading item info..."), | |
| 531 | } | |
| 541 | 532 | } |
| 542 | 533 | } |
| 543 | ||
| 544 | impl ItemInfoItem {} | |
src/app/pages/main_menu.rs +73 −68
| @@ -2,19 +2,23 @@ use std::{collections::LinkedList, error::Error, fs}; | ||
| 2 | 2 | |
| 3 | 3 | use crate::{ |
| 4 | 4 | app::{ |
| 5 | app::App, | |
| 6 | config::Action, | |
| 5 | app::{App, AppNoState}, | |
| 6 | config::{ | |
| 7 | Action, ConstraintTransitional, ItemTransitional, LayoutConfig, | |
| 8 | MainMenuItemTransitional, RowItemTransitional, RowTransitional, | |
| 9 | }, | |
| 7 | 10 | pages::{global::*, item_info::*}, |
| 8 | 11 | }, |
| 9 | 12 | functions::download_all_thumbnails, |
| 10 | structs::{Item, ListItem, Page, Row, RowItem, WatchHistory}, | |
| 13 | structs::{Item, ListItem, Page, WatchHistory}, | |
| 11 | 14 | traits::{ItemTrait, PageTrait}, |
| 12 | 15 | widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList}, |
| 13 | 16 | }; |
| 14 | 17 | use crossterm::event::KeyCode; |
| 18 | use serde::{Deserialize, Serialize}; | |
| 15 | 19 | use tui::{ |
| 16 | 20 | backend::Backend, |
| 17 | layout::{Alignment, Constraint, Rect}, | |
| 21 | layout::{Alignment, Rect}, | |
| 18 | 22 | style::{Color, Style}, |
| 19 | 23 | widgets::{Block, BorderType, Borders, Paragraph}, |
| 20 | 24 | Frame, |
| @@ -137,12 +141,12 @@ impl ItemTrait for MainMenuItem { | ||
| 137 | 141 | &mut self, |
| 138 | 142 | frame: &mut Frame<B>, |
| 139 | 143 | rect: Rect, |
| 140 | app: App, | |
| 144 | app: AppNoState, | |
| 141 | 145 | selected: bool, |
| 142 | 146 | hover: bool, |
| 143 | 147 | popup_focus: bool, |
| 144 | 148 | popup_render: bool, |
| 145 | ) -> (bool, App) { | |
| 149 | ) -> (bool, AppNoState) { | |
| 146 | 150 | let out = (false, app); |
| 147 | 151 | |
| 148 | 152 | if popup_render { |
| @@ -250,7 +254,7 @@ impl ItemTrait for MainMenuItem { | ||
| 250 | 254 | Action::FirstItem => textlist.first(), |
| 251 | 255 | Action::LastItem => textlist.last(), |
| 252 | 256 | Action::Select => { |
| 253 | let state = ItemInfo::default(); | |
| 257 | let state = app.config.layouts.item_info.clone().into(); | |
| 254 | 258 | let mut history = app.history.clone(); |
| 255 | 259 | history.push(app.into()); |
| 256 | 260 | |
| @@ -297,7 +301,7 @@ pub fn textlist_from_video_list(original: &LinkedList<ListItem>) -> Vec<String> | ||
| 297 | 301 | original.iter().map(|item| item.to_string()).collect() |
| 298 | 302 | } |
| 299 | 303 | |
| 300 | #[derive(Debug, Clone, Copy, PartialEq)] | |
| 304 | #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] | |
| 301 | 305 | pub enum MainMenuSelector { |
| 302 | 306 | Trending, |
| 303 | 307 | Popular, |
| @@ -311,66 +315,67 @@ impl Default for MainMenuSelector { | ||
| 311 | 315 | } |
| 312 | 316 | |
| 313 | 317 | pub struct MainMenu; |
| 314 | ||
| 315 | 318 | impl PageTrait for MainMenu { |
| 316 | fn message() -> String { | |
| 317 | String::from("Loading home page...") | |
| 318 | } | |
| 319 | ||
| 320 | fn min() -> (u16, u16) { | |
| 321 | (45, 15) | |
| 322 | } | |
| 323 | ||
| 324 | fn default() -> Vec<Row> { | |
| 325 | vec![ | |
| 326 | Row { | |
| 327 | items: vec![ | |
| 328 | RowItem { | |
| 329 | item: Item::Global(GlobalItem::SearchBar), | |
| 330 | constraint: Constraint::Min(16), | |
| 331 | }, | |
| 332 | RowItem { | |
| 333 | item: Item::Global(GlobalItem::SearchSettings), | |
| 334 | constraint: Constraint::Length(5), | |
| 335 | }, | |
| 336 | ], | |
| 337 | centered: false, | |
| 338 | height: Constraint::Length(3), | |
| 339 | }, | |
| 340 | Row { | |
| 341 | items: vec![ | |
| 342 | RowItem { | |
| 343 | item: Item::MainMenu(MainMenuItem::SeletorTab(MainMenuSelector::Popular)), | |
| 344 | constraint: Constraint::Length(15), | |
| 345 | }, | |
| 346 | RowItem { | |
| 347 | item: Item::MainMenu(MainMenuItem::SeletorTab(MainMenuSelector::Trending)), | |
| 348 | constraint: Constraint::Length(15), | |
| 349 | }, | |
| 350 | RowItem { | |
| 351 | item: Item::MainMenu(MainMenuItem::SeletorTab(MainMenuSelector::History)), | |
| 352 | constraint: Constraint::Length(15), | |
| 353 | }, | |
| 354 | ], | |
| 355 | centered: true, | |
| 356 | height: Constraint::Length(3), | |
| 357 | }, | |
| 358 | Row { | |
| 359 | items: vec![RowItem { | |
| 360 | item: Item::MainMenu(MainMenuItem::VideoList(None)), | |
| 361 | constraint: Constraint::Percentage(100), | |
| 362 | }], | |
| 363 | centered: false, | |
| 364 | height: Constraint::Min(6), | |
| 365 | }, | |
| 366 | Row { | |
| 367 | items: vec![RowItem { | |
| 368 | item: Item::Global(GlobalItem::MessageBar), | |
| 369 | constraint: Constraint::Percentage(100), | |
| 370 | }], | |
| 371 | centered: false, | |
| 372 | height: Constraint::Length(3), | |
| 373 | }, | |
| 374 | ] | |
| 319 | fn default() -> LayoutConfig { | |
| 320 | LayoutConfig { | |
| 321 | layout: vec![ | |
| 322 | RowTransitional { | |
| 323 | items: vec![ | |
| 324 | RowItemTransitional { | |
| 325 | item: ItemTransitional::Global(GlobalItem::SearchBar), | |
| 326 | constraint: ConstraintTransitional::Min(16), | |
| 327 | }, | |
| 328 | RowItemTransitional { | |
| 329 | item: ItemTransitional::Global(GlobalItem::SearchSettings), | |
| 330 | constraint: ConstraintTransitional::Length(5), | |
| 331 | }, | |
| 332 | ], | |
| 333 | centered: false, | |
| 334 | height: ConstraintTransitional::Length(3), | |
| 335 | }, | |
| 336 | RowTransitional { | |
| 337 | items: vec![ | |
| 338 | RowItemTransitional { | |
| 339 | item: ItemTransitional::MainMenu( | |
| 340 | MainMenuItemTransitional::SelectorTab(MainMenuSelector::Popular), | |
| 341 | ), | |
| 342 | constraint: ConstraintTransitional::Length(15), | |
| 343 | }, | |
| 344 | RowItemTransitional { | |
| 345 | item: ItemTransitional::MainMenu( | |
| 346 | MainMenuItemTransitional::SelectorTab(MainMenuSelector::Trending), | |
| 347 | ), | |
| 348 | constraint: ConstraintTransitional::Length(15), | |
| 349 | }, | |
| 350 | RowItemTransitional { | |
| 351 | item: ItemTransitional::MainMenu( | |
| 352 | MainMenuItemTransitional::SelectorTab(MainMenuSelector::History), | |
| 353 | ), | |
| 354 | constraint: ConstraintTransitional::Length(15), | |
| 355 | }, | |
| 356 | ], | |
| 357 | centered: true, | |
| 358 | height: ConstraintTransitional::Length(3), | |
| 359 | }, | |
| 360 | RowTransitional { | |
| 361 | items: vec![RowItemTransitional { | |
| 362 | item: ItemTransitional::MainMenu(MainMenuItemTransitional::VideoList), | |
| 363 | constraint: ConstraintTransitional::Percentage(100), | |
| 364 | }], | |
| 365 | centered: false, | |
| 366 | height: ConstraintTransitional::Min(6), | |
| 367 | }, | |
| 368 | RowTransitional { | |
| 369 | items: vec![RowItemTransitional { | |
| 370 | item: ItemTransitional::Global(GlobalItem::MessageBar), | |
| 371 | constraint: ConstraintTransitional::Percentage(100), | |
| 372 | }], | |
| 373 | centered: false, | |
| 374 | height: ConstraintTransitional::Length(3), | |
| 375 | }, | |
| 376 | ], | |
| 377 | min: (45, 15), | |
| 378 | message: String::from("Loading home page..."), | |
| 379 | } | |
| 375 | 380 | } |
| 376 | 381 | } |
src/app/pages/search.rs +53 −58
| @@ -4,17 +4,21 @@ use crossterm::event::KeyCode; | ||
| 4 | 4 | use invidious::structs::hidden::SearchItem as InvidiousSearchItem; |
| 5 | 5 | use tui::{ |
| 6 | 6 | backend::Backend, |
| 7 | layout::{Constraint, Rect}, | |
| 7 | layout::Rect, | |
| 8 | 8 | style::{Color, Style}, |
| 9 | 9 | Frame, |
| 10 | 10 | }; |
| 11 | 11 | |
| 12 | 12 | use crate::{ |
| 13 | app::{app::App, config::Action}, | |
| 14 | functions::download_all_thumbnails, | |
| 15 | structs::{ | |
| 16 | Item, ListItem, MiniChannel, MiniPlayList, MiniVideo, Page, Row, RowItem, WatchHistory, | |
| 13 | app::{ | |
| 14 | app::{App, AppNoState}, | |
| 15 | config::{ | |
| 16 | Action, ConstraintTransitional, ItemTransitional, LayoutConfig, RowItemTransitional, | |
| 17 | RowTransitional, SearchItemTransitional, | |
| 18 | }, | |
| 17 | 19 | }, |
| 20 | functions::download_all_thumbnails, | |
| 21 | structs::{Item, ListItem, MiniChannel, MiniPlayList, MiniVideo, Page, WatchHistory}, | |
| 18 | 22 | traits::{ItemTrait, PageTrait}, |
| 19 | 23 | widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList}, |
| 20 | 24 | }; |
| @@ -68,7 +72,7 @@ impl ItemTrait for SearchItem { | ||
| 68 | 72 | *results = None; |
| 69 | 73 | *text_list = TextList::default(); |
| 70 | 74 | |
| 71 | let state = Search::default(); | |
| 75 | let state = app.config.layouts.search.clone().into(); | |
| 72 | 76 | let mut history = app.history.clone(); |
| 73 | 77 | let search_text = app.search_text.clone(); |
| 74 | 78 | let search_settings = app.search_settings.clone(); |
| @@ -91,7 +95,7 @@ impl ItemTrait for SearchItem { | ||
| 91 | 95 | } |
| 92 | 96 | |
| 93 | 97 | ListItem::MiniVideo(video) => { |
| 94 | let state = ItemInfo::default(); | |
| 98 | let state = app.config.layouts.item_info.clone().into(); | |
| 95 | 99 | let mut history = app.history.clone(); |
| 96 | 100 | history.push(app.into()); |
| 97 | 101 | |
| @@ -110,7 +114,7 @@ impl ItemTrait for SearchItem { | ||
| 110 | 114 | } |
| 111 | 115 | |
| 112 | 116 | ListItem::MiniPlayList(playlist) => { |
| 113 | let state = ItemInfo::default(); | |
| 117 | let state = app.config.layouts.item_info.clone().into(); | |
| 114 | 118 | let mut history = app.history.clone(); |
| 115 | 119 | history.push(app.into()); |
| 116 | 120 | |
| @@ -129,7 +133,7 @@ impl ItemTrait for SearchItem { | ||
| 129 | 133 | } |
| 130 | 134 | |
| 131 | 135 | ListItem::MiniChannel(channel) => { |
| 132 | let state = Channel::default(); | |
| 136 | let state = app.config.layouts.channel.clone().into(); | |
| 133 | 137 | let mut history = app.history.clone(); |
| 134 | 138 | history.push(app.into()); |
| 135 | 139 | |
| @@ -238,9 +242,7 @@ impl ItemTrait for SearchItem { | ||
| 238 | 242 | items.push_front(ListItem::PageTurner(false)); |
| 239 | 243 | } |
| 240 | 244 | |
| 241 | if items.len() == minimum_length { | |
| 242 | *app.message.lock().unwrap() = Some(String::from("No results found")); | |
| 243 | } else { | |
| 245 | if items.len() != minimum_length { | |
| 244 | 246 | items.push_back(ListItem::PageTurner(true)); |
| 245 | 247 | } |
| 246 | 248 | |
| @@ -288,12 +290,12 @@ impl ItemTrait for SearchItem { | ||
| 288 | 290 | &mut self, |
| 289 | 291 | frame: &mut Frame<B>, |
| 290 | 292 | rect: Rect, |
| 291 | app: App, | |
| 293 | app: AppNoState, | |
| 292 | 294 | selected: bool, |
| 293 | 295 | hover: bool, |
| 294 | 296 | popup_focus: bool, |
| 295 | 297 | popup_render: bool, |
| 296 | ) -> (bool, App) { | |
| 298 | ) -> (bool, AppNoState) { | |
| 297 | 299 | let out = (false, app); |
| 298 | 300 | |
| 299 | 301 | if popup_render { |
| @@ -345,49 +347,42 @@ impl ItemTrait for SearchItem { | ||
| 345 | 347 | pub struct Search; |
| 346 | 348 | |
| 347 | 349 | impl PageTrait for Search { |
| 348 | fn message() -> String { | |
| 349 | String::from("Loading search results...") | |
| 350 | } | |
| 351 | ||
| 352 | fn min() -> (u16, u16) { | |
| 353 | (45, 12) | |
| 354 | } | |
| 355 | ||
| 356 | fn default() -> Vec<Row> { | |
| 357 | vec![ | |
| 358 | Row { | |
| 359 | items: vec![ | |
| 360 | RowItem { | |
| 361 | item: Item::Global(GlobalItem::SearchBar), | |
| 362 | constraint: Constraint::Min(16), | |
| 363 | }, | |
| 364 | RowItem { | |
| 365 | item: Item::Global(GlobalItem::SearchSettings), | |
| 366 | constraint: Constraint::Length(5), | |
| 367 | }, | |
| 368 | ], | |
| 369 | centered: false, | |
| 370 | height: Constraint::Length(3), | |
| 371 | }, | |
| 372 | Row { | |
| 373 | items: vec![RowItem { | |
| 374 | item: Item::Search(SearchItem::Search { | |
| 375 | results: None, | |
| 376 | text_list: TextList::default(), | |
| 377 | }), | |
| 378 | constraint: Constraint::Percentage(100), | |
| 379 | }], | |
| 380 | centered: false, | |
| 381 | height: Constraint::Min(6), | |
| 382 | }, | |
| 383 | Row { | |
| 384 | items: vec![RowItem { | |
| 385 | item: Item::Global(GlobalItem::MessageBar), | |
| 386 | constraint: Constraint::Percentage(100), | |
| 387 | }], | |
| 388 | centered: false, | |
| 389 | height: Constraint::Length(3), | |
| 390 | }, | |
| 391 | ] | |
| 350 | fn default() -> LayoutConfig { | |
| 351 | LayoutConfig { | |
| 352 | layout: vec![ | |
| 353 | RowTransitional { | |
| 354 | items: vec![ | |
| 355 | RowItemTransitional { | |
| 356 | item: ItemTransitional::Global(GlobalItem::SearchBar), | |
| 357 | constraint: ConstraintTransitional::Min(16), | |
| 358 | }, | |
| 359 | RowItemTransitional { | |
| 360 | item: ItemTransitional::Global(GlobalItem::SearchSettings), | |
| 361 | constraint: ConstraintTransitional::Length(5), | |
| 362 | }, | |
| 363 | ], | |
| 364 | centered: false, | |
| 365 | height: ConstraintTransitional::Length(3), | |
| 366 | }, | |
| 367 | RowTransitional { | |
| 368 | items: vec![RowItemTransitional { | |
| 369 | item: ItemTransitional::Search(SearchItemTransitional::Search), | |
| 370 | constraint: ConstraintTransitional::Percentage(100), | |
| 371 | }], | |
| 372 | centered: false, | |
| 373 | height: ConstraintTransitional::Min(6), | |
| 374 | }, | |
| 375 | RowTransitional { | |
| 376 | items: vec![RowItemTransitional { | |
| 377 | item: ItemTransitional::Global(GlobalItem::MessageBar), | |
| 378 | constraint: ConstraintTransitional::Percentage(100), | |
| 379 | }], | |
| 380 | centered: false, | |
| 381 | height: ConstraintTransitional::Length(3), | |
| 382 | }, | |
| 383 | ], | |
| 384 | min: (45, 12), | |
| 385 | message: String::from("Loading search results..."), | |
| 386 | } | |
| 392 | 387 | } |
| 393 | 388 | } |
src/main.rs +3 −3
| @@ -48,7 +48,7 @@ fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<( | ||
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | if app.load { |
| 51 | *app.message.lock().unwrap() = Some(app.page.message()); | |
| 51 | app.message = Some(app.page.message(&app.config)); | |
| 52 | 52 | let mut watch_history = app.watch_history.clone(); |
| 53 | 53 | terminal.clear()?; |
| 54 | 54 | let hold = ui(&mut terminal, app); |
| @@ -70,7 +70,7 @@ fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<( | ||
| 70 | 70 | item: row_item.item.clone(), |
| 71 | 71 | ..*row_item |
| 72 | 72 | }); |
| 73 | *app.message.lock().unwrap() = Some(e.to_string()); | |
| 73 | app.message = Some(e.to_string()); | |
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | } |
| @@ -143,7 +143,7 @@ fn ui<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> (App, Result<(), | ||
| 143 | 143 | |
| 144 | 144 | app = recv.recv().unwrap(); |
| 145 | 145 | |
| 146 | *app.message.lock().unwrap() = None; | |
| 146 | app.message = None; | |
| 147 | 147 | app.render = false; |
| 148 | 148 | |
| 149 | 149 | match res { |
src/structs/apphistory.rs +2 −2
| @@ -9,7 +9,7 @@ use crate::{ | ||
| 9 | 9 | |
| 10 | 10 | use super::SearchSettings; |
| 11 | 11 | |
| 12 | #[derive(Debug, Clone)] | |
| 12 | #[derive(Clone)] | |
| 13 | 13 | pub struct AppHistory { |
| 14 | 14 | pub page: Page, |
| 15 | 15 | pub state: Vec<Row>, // Item |
| @@ -17,7 +17,7 @@ pub struct AppHistory { | ||
| 17 | 17 | pub hover: Option<(usize, usize)>, // x, y |
| 18 | 18 | pub selected: Option<(usize, usize)>, |
| 19 | 19 | pub client: Client, |
| 20 | pub message: Arc<Mutex<Option<String>>>, | |
| 20 | pub message: Option<String>, | |
| 21 | 21 | pub load: bool, |
| 22 | 22 | pub render: bool, |
| 23 | 23 | pub popup_focus: bool, |
src/structs/page.rs +22 −10
| @@ -1,9 +1,12 @@ | ||
| 1 | 1 | use crate::{ |
| 2 | app::pages::{ | |
| 3 | channel::{Channel, ChannelPage}, | |
| 4 | item_info::{DisplayItem, ItemInfo}, | |
| 5 | main_menu::{MainMenu, MainMenuSelector}, | |
| 6 | search::Search, | |
| 2 | app::{ | |
| 3 | config::Config, | |
| 4 | pages::{ | |
| 5 | channel::{Channel, ChannelPage}, | |
| 6 | item_info::{DisplayItem, ItemInfo}, | |
| 7 | main_menu::{MainMenu, MainMenuSelector}, | |
| 8 | search::Search, | |
| 9 | }, | |
| 7 | 10 | }, |
| 8 | 11 | traits::PageTrait, |
| 9 | 12 | }; |
| @@ -23,12 +26,21 @@ impl Default for Page { | ||
| 23 | 26 | } |
| 24 | 27 | |
| 25 | 28 | impl Page { |
| 26 | pub fn message(&self) -> String { | |
| 29 | pub fn message(&self, config: &Config) -> String { | |
| 27 | 30 | match self { |
| 28 | Self::MainMenu(_) => MainMenu::message(), | |
| 29 | Self::ItemDisplay(_) => ItemInfo::message(), | |
| 30 | Self::Channel(_, _) => Channel::message(), | |
| 31 | Self::Search => Search::message(), | |
| 31 | Self::MainMenu(_) => config.layouts.main_menu.message.clone(), | |
| 32 | Self::ItemDisplay(_) => config.layouts.item_info.message.clone(), | |
| 33 | Self::Channel(_, _) => config.layouts.channel.message.clone(), | |
| 34 | Self::Search => config.layouts.search.message.clone(), | |
| 35 | } | |
| 36 | } | |
| 37 | ||
| 38 | pub fn min(&self, config: &Config) -> (u16, u16) { | |
| 39 | match self { | |
| 40 | Self::MainMenu(_) => config.layouts.main_menu.min, | |
| 41 | Self::ItemDisplay(_) => config.layouts.item_info.min, | |
| 42 | Self::Channel(_, _) => config.layouts.channel.min, | |
| 43 | Self::Search => config.layouts.search.min, | |
| 32 | 44 | } |
| 33 | 45 | } |
| 34 | 46 | } |
src/structs/states.rs +8 −8
| @@ -1,6 +1,6 @@ | ||
| 1 | use std::error::Error; | |
| 2 | ||
| 3 | 1 | use crossterm::event::KeyCode; |
| 2 | use serde::{Deserialize, Serialize}; | |
| 3 | use std::error::Error; | |
| 4 | 4 | use tui::{ |
| 5 | 5 | backend::Backend, |
| 6 | 6 | layout::{Constraint, Rect}, |
| @@ -9,7 +9,7 @@ use tui::{ | ||
| 9 | 9 | |
| 10 | 10 | use crate::{ |
| 11 | 11 | app::{ |
| 12 | app::App, | |
| 12 | app::{App, AppNoState}, | |
| 13 | 13 | pages::{ |
| 14 | 14 | channel::ChannelItem, global::GlobalItem, item_info::ItemInfoItem, |
| 15 | 15 | main_menu::MainMenuItem, search::SearchItem, |
| @@ -20,7 +20,7 @@ use crate::{ | ||
| 20 | 20 | |
| 21 | 21 | use super::WatchHistory; |
| 22 | 22 | |
| 23 | #[derive(Debug, Clone)] | |
| 23 | #[derive(Clone)] | |
| 24 | 24 | pub enum Item { |
| 25 | 25 | Global(GlobalItem), |
| 26 | 26 | MainMenu(MainMenuItem), |
| @@ -44,12 +44,12 @@ impl Item { | ||
| 44 | 44 | &mut self, |
| 45 | 45 | frame: &mut Frame<B>, |
| 46 | 46 | rect: Rect, |
| 47 | app: App, | |
| 47 | app: AppNoState, | |
| 48 | 48 | selected: bool, |
| 49 | 49 | hover: bool, |
| 50 | 50 | popup_focus: bool, |
| 51 | 51 | popup_render: bool, |
| 52 | ) -> (bool, App) { | |
| 52 | ) -> (bool, AppNoState) { | |
| 53 | 53 | match self { |
| 54 | 54 | Item::Global(item) => { |
| 55 | 55 | item.render_item(frame, rect, app, selected, hover, popup_focus, popup_render) |
| @@ -94,14 +94,14 @@ impl Item { | ||
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | #[derive(Debug, Clone)] | |
| 97 | #[derive(Clone)] | |
| 98 | 98 | pub struct Row { |
| 99 | 99 | pub items: Vec<RowItem>, |
| 100 | 100 | pub centered: bool, |
| 101 | 101 | pub height: Constraint, |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | #[derive(Debug, Clone)] | |
| 104 | #[derive(Clone)] | |
| 105 | 105 | pub struct RowItem { |
| 106 | 106 | pub item: Item, |
| 107 | 107 | pub constraint: Constraint, |
src/traits/config.rs +1 −2
| @@ -1,13 +1,12 @@ | ||
| 1 | 1 | use serde::{de::DeserializeOwned, Serialize}; |
| 2 | 2 | use std::{ |
| 3 | 3 | error::Error, |
| 4 | fmt::Debug, | |
| 5 | 4 | fs::{self, rename}, |
| 6 | 5 | io::Write, |
| 7 | 6 | }; |
| 8 | 7 | |
| 9 | 8 | pub trait ConfigItem<'a> { |
| 10 | type Struct: Serialize + DeserializeOwned + Debug + Clone + Default; | |
| 9 | type Struct: Serialize + DeserializeOwned + Clone + Default; | |
| 11 | 10 | const FILE_NAME: &'static str; |
| 12 | 11 | |
| 13 | 12 | fn load() -> Result<Self::Struct, Box<dyn Error>> |
src/traits/item.rs +3 −3
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | use std::error::Error; |
| 2 | 2 | |
| 3 | 3 | use crate::{ |
| 4 | app::app::App, | |
| 4 | app::app::{App, AppNoState}, | |
| 5 | 5 | structs::{Item, WatchHistory}, |
| 6 | 6 | }; |
| 7 | 7 | use crossterm::event::KeyCode; |
| @@ -13,12 +13,12 @@ pub trait ItemTrait { | ||
| 13 | 13 | &mut self, |
| 14 | 14 | frame: &mut Frame<B>, |
| 15 | 15 | rect: Rect, |
| 16 | app: App, | |
| 16 | app: AppNoState, | |
| 17 | 17 | selected: bool, |
| 18 | 18 | hover: bool, |
| 19 | 19 | popup_focus: bool, |
| 20 | 20 | popup_render: bool, |
| 21 | ) -> (bool, App); | |
| 21 | ) -> (bool, AppNoState); | |
| 22 | 22 | fn select(&mut self, app: App) -> (App, bool); |
| 23 | 23 | fn selectable(&self) -> bool; |
| 24 | 24 | fn load_item( |
src/traits/page.rs +2 −8
| @@ -1,11 +1,5 @@ | ||
| 1 | use crate::structs::Row; | |
| 1 | use crate::app::config::LayoutConfig; | |
| 2 | 2 | |
| 3 | 3 | pub trait PageTrait { |
| 4 | fn message() -> String { | |
| 5 | String::from("Loading page...") | |
| 6 | } | |
| 7 | ||
| 8 | fn min() -> (u16, u16); | |
| 9 | ||
| 10 | fn default() -> Vec<Row>; | |
| 4 | fn default() -> LayoutConfig; | |
| 11 | 5 | } |
src/widgets/text_list.rs +1
| @@ -1,3 +1,4 @@ | ||
| 1 | use serde::{Deserialize, Serialize}; | |
| 1 | 2 | use tui::{ |
| 2 | 3 | buffer::Buffer, |
| 3 | 4 | layout::Rect, |