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 = [
17161716
17171717[[package]]
17181718name = "youtube-tui"
1719version = "0.4.1"
1719version = "0.4.2"
17201720dependencies = [
17211721 "chrono",
17221722 "crossterm",
Cargo.toml +1 −1
@@ -1,6 +1,6 @@
11[package]
22name = "youtube-tui"
3version = "0.4.1"
3version = "0.4.2"
44edition = "2021"
55authors = ["Siriusmart <siriusmart@tuta.io>"]
66description = "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
1818
1919> ### What's new in this commit
2020>
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)
2323
2424## Installation
2525
@@ -40,7 +40,7 @@ The binary is located at `./target/release/youtube-tui`, go move it to other loc
4040>
4141> This program does not requires any dependencies, but it is suggested these three things on your system that can be launched via command:
4242>
43> 1. A video player (Default to `mpv`)
43> 1. A video player (Defaults to `mpv`)
4444> 2. A terminal emulator (Defaults to `konsole`)
4545> 3. A YouTube downloader (Defaults to `yt-dlp`, strongly suggest NOT to use `youtube-dl` because it is now very slow)
4646>
@@ -59,7 +59,6 @@ youtube-tui # or path to the binary
5959|Key|What does it do|
6060|---|---|
6161|Arrow/Vim keys|Move in corresponding direction|
62|Right arrow|Move cursor right
6362|Enter|Select/Launch|
6463|Q|Quit the program|
6564
src/app/app.rs +76 −22
@@ -23,7 +23,7 @@ use super::{
2323 pages::{channel::Channel, item_info::ItemInfo, search::Search},
2424};
2525
26#[derive(Debug, Clone)]
26#[derive(Clone)]
2727pub struct App {
2828 pub config: Config,
2929 pub page: Page,
@@ -32,7 +32,7 @@ pub struct App {
3232 pub hover: Option<(usize, usize)>, // x, y
3333 pub selected: Option<(usize, usize)>,
3434 pub client: Client,
35 pub message: Arc<Mutex<Option<String>>>,
35 pub message: Option<String>,
3636 pub load: bool,
3737 pub render: bool,
3838 pub popup_focus: bool,
@@ -43,10 +43,72 @@ pub struct App {
4343 pub page_no: usize,
4444}
4545
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
46108impl Default for App {
47109 fn default() -> Self {
48110 let config = Config::load().unwrap();
49 let state = MainMenu::default();
111 let state = config.layouts.main_menu.clone().into();
50112 let selectable = App::selectable(&state);
51113 Self {
52114 page: Page::default(),
@@ -55,7 +117,7 @@ impl Default for App {
55117 client: Client::new(config.main.server_url.clone()),
56118 selected: None,
57119 hover: None,
58 message: Arc::new(Mutex::new(None)),
120 message: None,
59121 load: true,
60122 render: true,
61123 popup_focus: false,
@@ -213,12 +275,7 @@ impl App {
213275 let size = frame.size();
214276 let mut popups = Vec::new();
215277
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);
222279
223280 if size.width < min.0 || size.height < min.1 {
224281 let paragraph = Paragraph::new(format!(
@@ -248,7 +305,7 @@ impl App {
248305 )
249306 .split(size);
250307
251 let mut state = self.state.clone();
308 let (mut app, mut state) = AppNoState::split(self);
252309
253310 for (y, (row, row_chunk)) in state
254311 .iter_mut()
@@ -294,15 +351,14 @@ impl App {
294351 .zip(row.items.iter_mut().map(|i| &mut i.item))
295352 .enumerate()
296353 {
297 let selected = self.selected == Some((x, y));
354 let selected = app.selected == Some((x, y));
298355
299356 let hover = hover_selected == Some((x, y));
300 let popup_focus = self.popup_focus;
357 let popup_focus = app.popup_focus;
301358
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);
304360
305 self = hold.1;
361 app = hold.1;
306362
307363 if hold.0 {
308364 popups.push((item, selected, hover, chunk));
@@ -311,19 +367,17 @@ impl App {
311367 }
312368
313369 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;
317372 }
318373
319 self.state = state;
320
374 self = AppNoState::join(app, state);
321375 self
322376 }
323377
324378 pub fn pop(mut self) -> (App, bool) {
325379 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"));
327381 return (self, false);
328382 }
329383
src/app/config/commands.rs +14 −2
@@ -3,13 +3,13 @@ use std::{collections::HashMap, thread};
33
44use crate::traits::ConfigItem;
55
6#[derive(Serialize, Deserialize, Clone, Debug)]
6#[derive(Serialize, Deserialize, Clone)]
77pub struct Command {
88 pub args: Vec<String>,
99 pub message: String,
1010}
1111
12#[derive(Serialize, Deserialize, Clone, Debug)]
12#[derive(Serialize, Deserialize, Clone)]
1313pub struct CommandsConfig(pub HashMap<String, Command>);
1414
1515impl Command {
@@ -99,6 +99,18 @@ impl Default for CommandsConfig {
9999 ],
100100 "Opened mpv in new konsole window",
101101 );
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 );
102114 out.insert(
103115 "video_downloader",
104116 vec![
src/app/config/config.rs +7 −2
@@ -1,14 +1,17 @@
11use std::error::Error;
22
3use super::{commands::CommandsConfig, MainConfig, PageCommandsConfig, KeybindingsConfig};
3use super::{
4 commands::CommandsConfig, KeybindingsConfig, LayoutsConfigs, MainConfig, PageCommandsConfig,
5};
46use crate::traits::ConfigItem;
57
6#[derive(Clone, Debug)]
8#[derive(Clone)]
79pub struct Config {
810 pub commands: CommandsConfig,
911 pub main: MainConfig,
1012 pub page_commands: PageCommandsConfig,
1113 pub keybindings: KeybindingsConfig,
14 pub layouts: LayoutsConfigs,
1215}
1316
1417impl Default for Config {
@@ -18,6 +21,7 @@ impl Default for Config {
1821 main: MainConfig::default(),
1922 page_commands: PageCommandsConfig::default(),
2023 keybindings: KeybindingsConfig::default(),
24 layouts: LayoutsConfigs::default(),
2125 }
2226 }
2327}
@@ -29,6 +33,7 @@ impl Config {
2933 commands: CommandsConfig::load()?,
3034 page_commands: PageCommandsConfig::load()?,
3135 keybindings: KeybindingsConfig::load()?.into(),
36 layouts: LayoutsConfigs::load()?,
3237 })
3338 }
3439}
src/app/config/keybindings.rs +10 −11
@@ -1,11 +1,11 @@
11use std::collections::HashMap;
22
33use crossterm::event::KeyCode;
4use serde::{Serialize, Deserialize};
4use serde::{Deserialize, Serialize};
55
66use crate::traits::ConfigItem;
77
8#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
8#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
99pub enum Action {
1010 Up,
1111 Down,
@@ -21,7 +21,7 @@ pub enum Action {
2121 ClearHistory,
2222}
2323
24#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
24#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]
2525pub enum KeyCodeTransitional {
2626 Backspace,
2727 Enter,
@@ -64,7 +64,7 @@ impl Into<KeyCode> for KeyCodeTransitional {
6464 Self::Char(c) => KeyCode::Char(c),
6565 Self::Null => KeyCode::Null,
6666 Self::Esc => KeyCode::Esc,
67 }
67 }
6868 }
6969}
7070
@@ -80,8 +80,8 @@ impl Into<KeybindingsConfig> for KeybindingsConfigTransitional {
8080 }
8181}
8282
83#[derive(Serialize, Deserialize, Debug, Clone)]
84pub struct KeybindingsConfigTransitional (pub HashMap<KeyCodeTransitional, Action>);
83#[derive(Serialize, Deserialize, Clone)]
84pub struct KeybindingsConfigTransitional(pub HashMap<KeyCodeTransitional, Action>);
8585
8686impl Default for KeybindingsConfigTransitional {
8787 fn default() -> Self {
@@ -103,7 +103,7 @@ impl Default for KeybindingsConfigTransitional {
103103 out.insert(KeyCodeTransitional::Enter, Action::Select);
104104 out.insert(KeyCodeTransitional::Esc, Action::Deselect);
105105 out.insert(KeyCodeTransitional::Char('q'), Action::Exit);
106
106
107107 out.insert(KeyCodeTransitional::Home, Action::Home);
108108 out.insert(KeyCodeTransitional::Backspace, Action::Back);
109109 out.insert(KeyCodeTransitional::End, Action::ClearHistory);
@@ -118,11 +118,10 @@ impl Default for KeybindingsConfig {
118118 }
119119}
120120
121#[derive(Debug, Clone)]
122pub struct KeybindingsConfig (pub HashMap<KeyCode, Action>);
123
121#[derive(Clone)]
122pub struct KeybindingsConfig(pub HashMap<KeyCode, Action>);
124123
125impl ConfigItem<'_> for KeybindingsConfig {
124impl ConfigItem<'_> for KeybindingsConfig {
126125 type Struct = KeybindingsConfigTransitional;
127126 const FILE_NAME: &'static str = "keybindings.yml";
128127}
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> {
2222 out
2323}
2424
25#[derive(Clone, Debug, Serialize, Deserialize)]
25#[derive(Clone, Serialize, Deserialize)]
2626pub struct MainConfig {
2727 #[serde(default = "max_watch_history_default")]
2828 pub max_watch_history: usize,
src/app/config/mod.rs +3
@@ -11,3 +11,6 @@ pub use page_commands::*;
1111
1212mod keybindings;
1313pub use keybindings::*;
14
15mod layouts;
16pub use layouts::*;
src/app/config/page_commands.rs +3 −2
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
44
55use crate::traits::ConfigItem;
66
7#[derive(Debug, Clone, Serialize, Deserialize)]
7#[derive(Clone, Serialize, Deserialize)]
88pub struct PageCommandsConfig(pub HashMap<String, Vec<PageCommand>>);
99
1010impl PageCommandsConfig {
@@ -22,6 +22,7 @@ impl Default for PageCommandsConfig {
2222 vec![
2323 PageCommand::from("Watch video", "video_player"),
2424 PageCommand::from("Play audio", "audio_player"),
25 PageCommand::from("Play audio (loop)", "audio_loop"),
2526 PageCommand::from("Download video", "video_downloader"),
2627 PageCommand::from("Download audio", "audio_downloader"),
2728 PageCommand::from("Visit channel", "{goto_channel}"),
@@ -51,7 +52,7 @@ impl Default for PageCommandsConfig {
5152 }
5253}
5354
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[derive(Clone, Serialize, Deserialize)]
5556pub struct PageCommand {
5657 pub label: String,
5758 pub command: String,
src/app/pages/channel.rs +77 −77
@@ -1,20 +1,25 @@
11use std::{collections::LinkedList, error::Error};
22
33use crossterm::event::KeyCode;
4use serde::{Deserialize, Serialize};
45use tui::{
56 backend::Backend,
6 layout::{Alignment, Constraint, Rect},
7 layout::{Alignment, Rect},
78 style::{Color, Style},
89 widgets::{Block, BorderType, Borders, Paragraph},
910 Frame,
1011};
1112
1213use 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 },
1720 },
21 functions::download_all_thumbnails,
22 structs::{FullChannel, Item, ListItem, MiniPlayList, MiniVideo, Page, WatchHistory},
1823 traits::{ItemTrait, PageTrait},
1924 widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList},
2025};
@@ -24,7 +29,7 @@ use super::{
2429 item_info::{DisplayItem, ItemInfo},
2530};
2631
27#[derive(Debug, Clone, Copy, PartialEq)]
32#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
2833pub enum ChannelPage {
2934 Home,
3035 Playlists,
@@ -118,22 +123,15 @@ impl ItemTrait for ChannelItem {
118123 }
119124
120125 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,
128126 &mut self,
129127 frame: &mut Frame<B>,
130128 rect: Rect,
131 app: App,
129 app: AppNoState,
132130 selected: bool,
133131 hover: bool,
134132 popup_focus: bool,
135133 _: bool,
136 ) -> (bool, App) {
134 ) -> (bool, AppNoState) {
137135 let mut out = (false, app);
138136
139137 let mut style = Style::default().fg(if selected {
@@ -300,7 +298,7 @@ impl ItemTrait for ChannelItem {
300298 Action::FirstItem => textlist.first(),
301299 Action::LastItem => textlist.last(),
302300 Action::Select => {
303 let state = ItemInfo::default();
301 let state = app.config.layouts.item_info.clone().into();
304302 let mut history = app.history.clone();
305303 history.push(app.into());
306304
@@ -330,7 +328,7 @@ impl ItemTrait for ChannelItem {
330328 Action::FirstItem => textlist.first(),
331329 Action::LastItem => textlist.last(),
332330 Action::Select => {
333 let state = ItemInfo::default();
331 let state = app.config.layouts.item_info.clone().into();
334332 let mut history = app.history.clone();
335333 history.push(app.into());
336334
@@ -370,7 +368,7 @@ impl ItemTrait for ChannelItem {
370368 return (app, false);
371369 }
372370
373 let state = Channel::default();
371 let state = app.config.layouts.channel.clone().into();
374372 let mut history = app.history.clone();
375373 history.push(app.into());
376374
@@ -399,64 +397,66 @@ impl ItemTrait for ChannelItem {
399397pub struct Channel;
400398
401399impl 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 }
461461 }
462462}
src/app/pages/global.rs +8 −9
@@ -1,6 +1,7 @@
11use std::fmt;
22
33use crossterm::event::KeyCode;
4use serde::{Deserialize, Serialize};
45use tui::{
56 backend::Backend,
67 layout::{Alignment, Rect},
@@ -10,7 +11,7 @@ use tui::{
1011};
1112
1213use crate::{
13 app::app::App,
14 app::app::{App, AppNoState},
1415 functions::center_rect,
1516 structs::{Item, Page, WatchHistory},
1617 traits::{ItemTrait, PageTrait},
@@ -19,7 +20,7 @@ use crate::{
1920
2021use super::search::Search;
2122
22#[derive(Debug, Clone)]
23#[derive(Debug, Clone, Serialize, Deserialize)]
2324pub enum GlobalItem {
2425 SearchBar,
2526 SearchSettings,
@@ -82,10 +83,9 @@ impl ItemTrait for GlobalItem {
8283 }
8384 KeyCode::Enter => {
8485 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"));
8787 } else {
88 let state = Search::default();
88 let state = app.config.layouts.search.clone().into();
8989 let mut history = app.history.clone();
9090 let search_text = app.search_text.clone();
9191 let search_settings = app.search_settings.clone();
@@ -121,12 +121,12 @@ impl ItemTrait for GlobalItem {
121121 &mut self,
122122 frame: &mut Frame<B>,
123123 rect: Rect,
124 app: App,
124 app: AppNoState,
125125 selected: bool,
126126 hover: bool,
127127 _: bool,
128128 popup_render: bool,
129 ) -> (bool, App) {
129 ) -> (bool, AppNoState) {
130130 let area = frame.size();
131131 let mut out = (false, app);
132132 match self {
@@ -151,8 +151,7 @@ impl ItemTrait for GlobalItem {
151151 frame.render_widget(paragraph, rect);
152152 }
153153 GlobalItem::MessageBar => {
154 let message = out.1.message.lock().unwrap();
155 // let color = Color::LightYellow;
154 let message = out.1.message.clone();
156155 let block = Block::default()
157156 .border_type(BorderType::Rounded)
158157 .borders(Borders::ALL)
src/app/pages/item_info.rs +60 −71
@@ -2,33 +2,36 @@ use std::{collections::LinkedList, error::Error};
22
33use crate::{
44 app::{
5 app::App,
6 config::{Action, PageCommand},
5 app::{App, AppNoState},
6 config::{
7 Action, ConstraintTransitional, ItemTransitional, LayoutConfig, PageCommand,
8 RowItemTransitional, RowTransitional,
9 },
710 pages::{channel::*, global::*},
811 },
912 functions::download_all_thumbnails,
10 structs::{FullPlayList, FullVideo, Item, ListItem, Page, Row, RowItem, WatchHistory},
13 structs::{FullPlayList, FullVideo, Item, ListItem, Page, WatchHistory},
1114 traits::{ItemTrait, PageTrait},
1215 widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList},
1316};
1417use crossterm::event::KeyCode;
1518use tui::{
1619 backend::Backend,
17 layout::{Constraint, Rect},
20 layout::Rect,
1821 style::{Color, Style},
1922 Frame,
2023};
2124
2225use super::global::GlobalItem;
2326
24#[derive(Debug, Clone)]
27#[derive(Clone)]
2528pub enum ItemInfoItem {
2629 Unknown,
2730 Video(VideoItemInfo),
2831 PlayList(PlayListItemInfo),
2932}
3033
31#[derive(Debug, Clone)]
34#[derive(Clone)]
3235pub struct VideoItemInfo {
3336 video: FullVideo,
3437 list: TextList,
@@ -36,7 +39,7 @@ pub struct VideoItemInfo {
3639 commands: Vec<PageCommand>,
3740}
3841
39#[derive(Debug, Clone)]
42#[derive(Clone)]
4043pub struct PlayListItemInfo {
4144 playlist: FullPlayList,
4245 video_view_list: TextList,
@@ -46,7 +49,7 @@ pub struct PlayListItemInfo {
4649 commands: Vec<PageCommand>,
4750}
4851
49#[derive(Debug, Clone, Copy)]
52#[derive(Clone, Copy)]
5053pub enum PlayListDisplayView {
5154 VideoList,
5255 PlayListView,
@@ -72,7 +75,7 @@ impl ItemTrait for ItemInfoItem {
7275 true
7376 }
7477
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) {
7679 let action = match app.config.keybindings.0.get(&key) {
7780 Some(action) => *action,
7881 None => return (false, app),
@@ -89,7 +92,7 @@ impl ItemTrait for ItemInfoItem {
8992 match command.command.as_str() {
9093 "{toggle_mode}" => videoinfo.mode.toggle(),
9194 "{goto_channel}" => {
92 let state = Channel::default();
95 let state = app.config.layouts.channel.clone().into();
9396 let mut history = app.history.clone();
9497 history.push(app.into());
9598
@@ -126,17 +129,13 @@ impl ItemTrait for ItemInfoItem {
126129
127130 match command.run_command(&env) {
128131 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))
135133 }
134 None => app.message = Some(command.message.clone()),
136135 }
137136 }
138137 None => {
139 *app.message.lock().unwrap() =
138 app.message =
140139 Some(format!("Unkown command `{}`", &command.command));
141140 }
142141 };
@@ -159,7 +158,7 @@ impl ItemTrait for ItemInfoItem {
159158 match command.command.as_str() {
160159 "{toggle_mode}" => playlistinfo.mode.toggle(),
161160 "{goto_channel}" => {
162 let state = Channel::default();
161 let state = app.config.layouts.channel.clone().into();
163162 let mut history = app.history.clone();
164163 history.push(app.into());
165164
@@ -200,17 +199,14 @@ impl ItemTrait for ItemInfoItem {
200199
201200 match command.run_command(&env) {
202201 Some(e) => {
203 *app.message.lock().unwrap() =
202 app.message =
204203 Some(format!("Unknown variable `{}`", e))
205204 }
206 None => {
207 *app.message.lock().unwrap() =
208 Some(command.message.clone())
209 }
205 None => app.message = Some(command.message.clone()),
210206 }
211207 }
212208 None => {
213 *app.message.lock().unwrap() =
209 app.message =
214210 Some(format!("Unkown command `{}`", &command.command));
215211 }
216212 };
@@ -231,7 +227,7 @@ impl ItemTrait for ItemInfoItem {
231227 }
232228
233229 x => {
234 let state = ItemInfo::default();
230 let state = app.config.layouts.channel.clone().into();
235231 let mut history = app.history.clone();
236232 history.push(app.into());
237233
@@ -357,12 +353,12 @@ impl ItemTrait for ItemInfoItem {
357353 &mut self,
358354 frame: &mut Frame<B>,
359355 rect: Rect,
360 app: App,
356 app: AppNoState,
361357 selected: bool,
362358 hover: bool,
363359 popup_focus: bool,
364360 popup_render: bool,
365 ) -> (bool, App) {
361 ) -> (bool, AppNoState) {
366362 let out = (false, app);
367363
368364 if popup_render {
@@ -495,50 +491,43 @@ pub enum DisplayItem {
495491}
496492
497493pub struct ItemInfo;
498
499494impl 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 }
541532 }
542533}
543
544impl ItemInfoItem {}
src/app/pages/main_menu.rs +73 −68
@@ -2,19 +2,23 @@ use std::{collections::LinkedList, error::Error, fs};
22
33use crate::{
44 app::{
5 app::App,
6 config::Action,
5 app::{App, AppNoState},
6 config::{
7 Action, ConstraintTransitional, ItemTransitional, LayoutConfig,
8 MainMenuItemTransitional, RowItemTransitional, RowTransitional,
9 },
710 pages::{global::*, item_info::*},
811 },
912 functions::download_all_thumbnails,
10 structs::{Item, ListItem, Page, Row, RowItem, WatchHistory},
13 structs::{Item, ListItem, Page, WatchHistory},
1114 traits::{ItemTrait, PageTrait},
1215 widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList},
1316};
1417use crossterm::event::KeyCode;
18use serde::{Deserialize, Serialize};
1519use tui::{
1620 backend::Backend,
17 layout::{Alignment, Constraint, Rect},
21 layout::{Alignment, Rect},
1822 style::{Color, Style},
1923 widgets::{Block, BorderType, Borders, Paragraph},
2024 Frame,
@@ -137,12 +141,12 @@ impl ItemTrait for MainMenuItem {
137141 &mut self,
138142 frame: &mut Frame<B>,
139143 rect: Rect,
140 app: App,
144 app: AppNoState,
141145 selected: bool,
142146 hover: bool,
143147 popup_focus: bool,
144148 popup_render: bool,
145 ) -> (bool, App) {
149 ) -> (bool, AppNoState) {
146150 let out = (false, app);
147151
148152 if popup_render {
@@ -250,7 +254,7 @@ impl ItemTrait for MainMenuItem {
250254 Action::FirstItem => textlist.first(),
251255 Action::LastItem => textlist.last(),
252256 Action::Select => {
253 let state = ItemInfo::default();
257 let state = app.config.layouts.item_info.clone().into();
254258 let mut history = app.history.clone();
255259 history.push(app.into());
256260
@@ -297,7 +301,7 @@ pub fn textlist_from_video_list(original: &LinkedList<ListItem>) -> Vec<String>
297301 original.iter().map(|item| item.to_string()).collect()
298302}
299303
300#[derive(Debug, Clone, Copy, PartialEq)]
304#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
301305pub enum MainMenuSelector {
302306 Trending,
303307 Popular,
@@ -311,66 +315,67 @@ impl Default for MainMenuSelector {
311315}
312316
313317pub struct MainMenu;
314
315318impl 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 }
375380 }
376381}
src/app/pages/search.rs +53 −58
@@ -4,17 +4,21 @@ use crossterm::event::KeyCode;
44use invidious::structs::hidden::SearchItem as InvidiousSearchItem;
55use tui::{
66 backend::Backend,
7 layout::{Constraint, Rect},
7 layout::Rect,
88 style::{Color, Style},
99 Frame,
1010};
1111
1212use 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 },
1719 },
20 functions::download_all_thumbnails,
21 structs::{Item, ListItem, MiniChannel, MiniPlayList, MiniVideo, Page, WatchHistory},
1822 traits::{ItemTrait, PageTrait},
1923 widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList},
2024};
@@ -68,7 +72,7 @@ impl ItemTrait for SearchItem {
6872 *results = None;
6973 *text_list = TextList::default();
7074
71 let state = Search::default();
75 let state = app.config.layouts.search.clone().into();
7276 let mut history = app.history.clone();
7377 let search_text = app.search_text.clone();
7478 let search_settings = app.search_settings.clone();
@@ -91,7 +95,7 @@ impl ItemTrait for SearchItem {
9195 }
9296
9397 ListItem::MiniVideo(video) => {
94 let state = ItemInfo::default();
98 let state = app.config.layouts.item_info.clone().into();
9599 let mut history = app.history.clone();
96100 history.push(app.into());
97101
@@ -110,7 +114,7 @@ impl ItemTrait for SearchItem {
110114 }
111115
112116 ListItem::MiniPlayList(playlist) => {
113 let state = ItemInfo::default();
117 let state = app.config.layouts.item_info.clone().into();
114118 let mut history = app.history.clone();
115119 history.push(app.into());
116120
@@ -129,7 +133,7 @@ impl ItemTrait for SearchItem {
129133 }
130134
131135 ListItem::MiniChannel(channel) => {
132 let state = Channel::default();
136 let state = app.config.layouts.channel.clone().into();
133137 let mut history = app.history.clone();
134138 history.push(app.into());
135139
@@ -238,9 +242,7 @@ impl ItemTrait for SearchItem {
238242 items.push_front(ListItem::PageTurner(false));
239243 }
240244
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 {
244246 items.push_back(ListItem::PageTurner(true));
245247 }
246248
@@ -288,12 +290,12 @@ impl ItemTrait for SearchItem {
288290 &mut self,
289291 frame: &mut Frame<B>,
290292 rect: Rect,
291 app: App,
293 app: AppNoState,
292294 selected: bool,
293295 hover: bool,
294296 popup_focus: bool,
295297 popup_render: bool,
296 ) -> (bool, App) {
298 ) -> (bool, AppNoState) {
297299 let out = (false, app);
298300
299301 if popup_render {
@@ -345,49 +347,42 @@ impl ItemTrait for SearchItem {
345347pub struct Search;
346348
347349impl 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 }
392387 }
393388}
src/main.rs +3 −3
@@ -48,7 +48,7 @@ fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<(
4848 }
4949
5050 if app.load {
51 *app.message.lock().unwrap() = Some(app.page.message());
51 app.message = Some(app.page.message(&app.config));
5252 let mut watch_history = app.watch_history.clone();
5353 terminal.clear()?;
5454 let hold = ui(&mut terminal, app);
@@ -70,7 +70,7 @@ fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<(
7070 item: row_item.item.clone(),
7171 ..*row_item
7272 });
73 *app.message.lock().unwrap() = Some(e.to_string());
73 app.message = Some(e.to_string());
7474 }
7575 }
7676 }
@@ -143,7 +143,7 @@ fn ui<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> (App, Result<(),
143143
144144 app = recv.recv().unwrap();
145145
146 *app.message.lock().unwrap() = None;
146 app.message = None;
147147 app.render = false;
148148
149149 match res {
src/structs/apphistory.rs +2 −2
@@ -9,7 +9,7 @@ use crate::{
99
1010use super::SearchSettings;
1111
12#[derive(Debug, Clone)]
12#[derive(Clone)]
1313pub struct AppHistory {
1414 pub page: Page,
1515 pub state: Vec<Row>, // Item
@@ -17,7 +17,7 @@ pub struct AppHistory {
1717 pub hover: Option<(usize, usize)>, // x, y
1818 pub selected: Option<(usize, usize)>,
1919 pub client: Client,
20 pub message: Arc<Mutex<Option<String>>>,
20 pub message: Option<String>,
2121 pub load: bool,
2222 pub render: bool,
2323 pub popup_focus: bool,
src/structs/page.rs +22 −10
@@ -1,9 +1,12 @@
11use 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 },
710 },
811 traits::PageTrait,
912};
@@ -23,12 +26,21 @@ impl Default for Page {
2326}
2427
2528impl Page {
26 pub fn message(&self) -> String {
29 pub fn message(&self, config: &Config) -> String {
2730 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,
3244 }
3345 }
3446}
src/structs/states.rs +8 −8
@@ -1,6 +1,6 @@
1use std::error::Error;
2
31use crossterm::event::KeyCode;
2use serde::{Deserialize, Serialize};
3use std::error::Error;
44use tui::{
55 backend::Backend,
66 layout::{Constraint, Rect},
@@ -9,7 +9,7 @@ use tui::{
99
1010use crate::{
1111 app::{
12 app::App,
12 app::{App, AppNoState},
1313 pages::{
1414 channel::ChannelItem, global::GlobalItem, item_info::ItemInfoItem,
1515 main_menu::MainMenuItem, search::SearchItem,
@@ -20,7 +20,7 @@ use crate::{
2020
2121use super::WatchHistory;
2222
23#[derive(Debug, Clone)]
23#[derive(Clone)]
2424pub enum Item {
2525 Global(GlobalItem),
2626 MainMenu(MainMenuItem),
@@ -44,12 +44,12 @@ impl Item {
4444 &mut self,
4545 frame: &mut Frame<B>,
4646 rect: Rect,
47 app: App,
47 app: AppNoState,
4848 selected: bool,
4949 hover: bool,
5050 popup_focus: bool,
5151 popup_render: bool,
52 ) -> (bool, App) {
52 ) -> (bool, AppNoState) {
5353 match self {
5454 Item::Global(item) => {
5555 item.render_item(frame, rect, app, selected, hover, popup_focus, popup_render)
@@ -94,14 +94,14 @@ impl Item {
9494 }
9595}
9696
97#[derive(Debug, Clone)]
97#[derive(Clone)]
9898pub struct Row {
9999 pub items: Vec<RowItem>,
100100 pub centered: bool,
101101 pub height: Constraint,
102102}
103103
104#[derive(Debug, Clone)]
104#[derive(Clone)]
105105pub struct RowItem {
106106 pub item: Item,
107107 pub constraint: Constraint,
src/traits/config.rs +1 −2
@@ -1,13 +1,12 @@
11use serde::{de::DeserializeOwned, Serialize};
22use std::{
33 error::Error,
4 fmt::Debug,
54 fs::{self, rename},
65 io::Write,
76};
87
98pub trait ConfigItem<'a> {
10 type Struct: Serialize + DeserializeOwned + Debug + Clone + Default;
9 type Struct: Serialize + DeserializeOwned + Clone + Default;
1110 const FILE_NAME: &'static str;
1211
1312 fn load() -> Result<Self::Struct, Box<dyn Error>>
src/traits/item.rs +3 −3
@@ -1,7 +1,7 @@
11use std::error::Error;
22
33use crate::{
4 app::app::App,
4 app::app::{App, AppNoState},
55 structs::{Item, WatchHistory},
66};
77use crossterm::event::KeyCode;
@@ -13,12 +13,12 @@ pub trait ItemTrait {
1313 &mut self,
1414 frame: &mut Frame<B>,
1515 rect: Rect,
16 app: App,
16 app: AppNoState,
1717 selected: bool,
1818 hover: bool,
1919 popup_focus: bool,
2020 popup_render: bool,
21 ) -> (bool, App);
21 ) -> (bool, AppNoState);
2222 fn select(&mut self, app: App) -> (App, bool);
2323 fn selectable(&self) -> bool;
2424 fn load_item(
src/traits/page.rs +2 −8
@@ -1,11 +1,5 @@
1use crate::structs::Row;
1use crate::app::config::LayoutConfig;
22
33pub 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;
115}
src/widgets/text_list.rs +1
@@ -1,3 +1,4 @@
1use serde::{Deserialize, Serialize};
12use tui::{
23 buffer::Buffer,
34 layout::Rect,