Commit 9aedf4a98d

9aedf4a98dfbe60cee47b4e673a37437e309f462

parent: be4224817b

Unsigned

Siriusmart <71584876+Siriusmart@users.noreply.github.com> · 2022-07-02 10:11 UTC

layouts.yml

Layout: unified · split

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