Commit 01ca06be37
Unsigned
Layout: unified · split
Cargo.toml +1 −1
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | [package] |
| 2 | 2 | name = "youtube-tui" |
| 3 | version = "0.4.2" | |
| 3 | version = "0.4.3" | |
| 4 | 4 | edition = "2021" |
| 5 | 5 | authors = ["Siriusmart <siriusmart@tuta.io>"] |
| 6 | 6 | description = "An aesthetically pleasing YouTube TUI written in Rust" |
README.md +11 −2
| @@ -16,10 +16,17 @@ This program is being actively developed and there will be new features coming u | ||
| 16 | 16 | |
| 17 | 17 |  |
| 18 | 18 | |
| 19 | ## User manual | |
| 20 | ||
| 21 | [YouTube TUI user manual](https://siriusmart.github.io/youtube-tui) | |
| 22 | ||
| 19 | 23 | > ### What's new in this commit |
| 20 | 24 | > |
| 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) | |
| 25 | > * Refresh pages | |
| 26 | > * Fixed cache not being cleared after exit | |
| 27 | > * Key modifiers for key bindings | |
| 28 | > * Image loading can be disabled in main config | |
| 29 | ||
| 23 | 30 | |
| 24 | 31 | ## Installation |
| 25 | 32 | |
| @@ -62,6 +69,8 @@ youtube-tui # or path to the binary | ||
| 62 | 69 | |Enter|Select/Launch| |
| 63 | 70 | |Q|Quit the program| |
| 64 | 71 | |
| 72 | Check the user manual [here](https://siriusmart.github.io/youtube-tui) | |
| 73 | ||
| 65 | 74 | > ### Note |
| 66 | 75 | > |
| 67 | 76 | > These keys only work when nothing is selected. When something is selected, your key presses are passed directly to the "object" you've selected. Press escape (Esc) if you want to deselect. |
src/app/app.rs +24 −12
| @@ -1,10 +1,10 @@ | ||
| 1 | 1 | use std::collections::LinkedList; |
| 2 | 2 | |
| 3 | 3 | use crate::{ |
| 4 | structs::{AppHistory, Item, Page, Row, SearchSettings, WatchHistory}, | |
| 4 | structs::{AppHistory, Item, Page, SearchSettings, State, WatchHistory}, | |
| 5 | 5 | traits::ItemTrait, |
| 6 | 6 | }; |
| 7 | use crossterm::event::KeyCode; | |
| 7 | use crossterm::event::KeyEvent; | |
| 8 | 8 | use invidious::blocking::Client; |
| 9 | 9 | use tui::{ |
| 10 | 10 | backend::Backend, |
| @@ -20,7 +20,7 @@ use super::config::{Action, Config}; | ||
| 20 | 20 | pub struct App { |
| 21 | 21 | pub config: Config, |
| 22 | 22 | pub page: Page, |
| 23 | pub state: Vec<Row>, // Item | |
| 23 | pub state: State, // Item | |
| 24 | 24 | pub selectable: Vec<Vec<(usize, usize)>>, |
| 25 | 25 | pub hover: Option<(usize, usize)>, // x, y |
| 26 | 26 | pub selected: Option<(usize, usize)>, |
| @@ -33,6 +33,7 @@ pub struct App { | ||
| 33 | 33 | pub watch_history: WatchHistory, |
| 34 | 34 | pub search_settings: SearchSettings, |
| 35 | 35 | pub search_text: String, |
| 36 | pub search_index: usize, | |
| 36 | 37 | pub page_no: usize, |
| 37 | 38 | } |
| 38 | 39 | |
| @@ -51,11 +52,12 @@ pub struct AppNoState { | ||
| 51 | 52 | pub watch_history: WatchHistory, |
| 52 | 53 | pub search_settings: SearchSettings, |
| 53 | 54 | pub search_text: String, |
| 55 | pub search_index: usize, | |
| 54 | 56 | pub page_no: usize, |
| 55 | 57 | } |
| 56 | 58 | |
| 57 | 59 | impl AppNoState { |
| 58 | pub fn split(app: App) -> (Self, Vec<Row>) { | |
| 60 | pub fn split(app: App) -> (Self, State) { | |
| 59 | 61 | let out = Self { |
| 60 | 62 | config: app.config, |
| 61 | 63 | page: app.page, |
| @@ -71,12 +73,13 @@ impl AppNoState { | ||
| 71 | 73 | watch_history: app.watch_history, |
| 72 | 74 | search_settings: app.search_settings, |
| 73 | 75 | search_text: app.search_text, |
| 76 | search_index: app.search_index, | |
| 74 | 77 | page_no: app.page_no, |
| 75 | 78 | }; |
| 76 | 79 | (out, app.state) |
| 77 | 80 | } |
| 78 | 81 | |
| 79 | pub fn join(app: Self, state: Vec<Row>) -> App { | |
| 82 | pub fn join(app: Self, state: State) -> App { | |
| 80 | 83 | App { |
| 81 | 84 | config: app.config, |
| 82 | 85 | page: app.page, |
| @@ -92,6 +95,7 @@ impl AppNoState { | ||
| 92 | 95 | watch_history: app.watch_history, |
| 93 | 96 | search_settings: app.search_settings, |
| 94 | 97 | search_text: app.search_text, |
| 98 | search_index: app.search_index, | |
| 95 | 99 | page_no: app.page_no, |
| 96 | 100 | state, |
| 97 | 101 | } |
| @@ -101,7 +105,7 @@ impl AppNoState { | ||
| 101 | 105 | impl Default for App { |
| 102 | 106 | fn default() -> Self { |
| 103 | 107 | let config = Config::load().unwrap(); |
| 104 | let state = config.layouts.main_menu.clone().into(); | |
| 108 | let state: State = config.layouts.main_menu.clone().into(); | |
| 105 | 109 | let selectable = App::selectable(&state); |
| 106 | 110 | Self { |
| 107 | 111 | page: Page::default(), |
| @@ -119,16 +123,17 @@ impl Default for App { | ||
| 119 | 123 | watch_history: WatchHistory::load(), |
| 120 | 124 | search_settings: SearchSettings::default(), |
| 121 | 125 | search_text: String::new(), |
| 126 | search_index: 0, | |
| 122 | 127 | page_no: 1, |
| 123 | 128 | } |
| 124 | 129 | } |
| 125 | 130 | } |
| 126 | 131 | |
| 127 | 132 | impl App { |
| 128 | pub fn selectable(state: &Vec<Row>) -> Vec<Vec<(usize, usize)>> { | |
| 133 | pub fn selectable(state: &State) -> Vec<Vec<(usize, usize)>> { | |
| 129 | 134 | let mut selectable = Vec::new(); |
| 130 | 135 | |
| 131 | for (y, row) in state.iter().enumerate() { | |
| 136 | for (y, row) in state.0.iter().enumerate() { | |
| 132 | 137 | let mut row_vec = Vec::new(); |
| 133 | 138 | for (x, row_item) in row.items.iter().enumerate() { |
| 134 | 139 | if match &row_item.item { |
| @@ -149,16 +154,16 @@ impl App { | ||
| 149 | 154 | selectable |
| 150 | 155 | } |
| 151 | 156 | |
| 152 | pub fn key_input(mut self, key: KeyCode) -> App { | |
| 157 | pub fn key_input(mut self, key: KeyEvent) -> App { | |
| 153 | 158 | let action = self.config.keybindings.0.get(&key); |
| 154 | 159 | |
| 155 | 160 | if let Some((x, y)) = self.selected { |
| 156 | 161 | if action != Some(&Action::Deselect) { |
| 157 | let mut item = self.state[y].items[x].item.clone(); | |
| 162 | let mut item = self.state.0[y].items[x].item.clone(); | |
| 158 | 163 | let updated; |
| 159 | 164 | (updated, self) = item.key_input(key, self); |
| 160 | 165 | if updated { |
| 161 | self.state[y].items[x].item = item; | |
| 166 | self.state.0[y].items[x].item = item; | |
| 162 | 167 | } |
| 163 | 168 | |
| 164 | 169 | return self; |
| @@ -171,13 +176,17 @@ impl App { | ||
| 171 | 176 | }; |
| 172 | 177 | |
| 173 | 178 | match action { |
| 179 | Action::Refresh => { | |
| 180 | self.state.reset(); | |
| 181 | self.load = true; | |
| 182 | } | |
| 174 | 183 | Action::Select => { |
| 175 | 184 | if self.hover.is_some() && self.selected.is_none() { |
| 176 | 185 | let (mut x, mut y) = self.hover.unwrap(); |
| 177 | 186 | (x, y) = self.selectable[y][x]; |
| 178 | 187 | |
| 179 | 188 | let select; |
| 180 | (self, select) = self.state[y] | |
| 189 | (self, select) = self.state.0[y] | |
| 181 | 190 | .items |
| 182 | 191 | .iter() |
| 183 | 192 | .nth(x) |
| @@ -292,6 +301,7 @@ impl App { | ||
| 292 | 301 | .direction(Direction::Vertical) |
| 293 | 302 | .constraints( |
| 294 | 303 | self.state |
| 304 | .0 | |
| 295 | 305 | .iter() |
| 296 | 306 | .map(|row| row.height) |
| 297 | 307 | .collect::<Vec<Constraint>>(), |
| @@ -301,6 +311,7 @@ impl App { | ||
| 301 | 311 | let (mut app, mut state) = AppNoState::split(self); |
| 302 | 312 | |
| 303 | 313 | for (y, (row, row_chunk)) in state |
| 314 | .0 | |
| 304 | 315 | .iter_mut() |
| 305 | 316 | .zip(vertical_chunks.clone().iter_mut()) |
| 306 | 317 | .enumerate() |
| @@ -392,6 +403,7 @@ impl App { | ||
| 392 | 403 | search_settings: self.search_settings, |
| 393 | 404 | popup_focus: app_history.popup_focus, |
| 394 | 405 | search_text: app_history.search_text, |
| 406 | search_index: app_history.search_index, | |
| 395 | 407 | page_no: app_history.page_no, |
| 396 | 408 | }; |
| 397 | 409 | |
src/app/config/colors.rs added +1
| @@ -0,0 +1 @@ | ||
| 1 | // TODO | |
src/app/config/keybindings.rs +183 −21
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | use std::collections::HashMap; |
| 2 | 2 | |
| 3 | use crossterm::event::KeyCode; | |
| 3 | use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; | |
| 4 | 4 | use serde::{Deserialize, Serialize}; |
| 5 | 5 | |
| 6 | 6 | use crate::traits::ConfigItem; |
| @@ -19,6 +19,7 @@ pub enum Action { | ||
| 19 | 19 | Exit, |
| 20 | 20 | Back, |
| 21 | 21 | ClearHistory, |
| 22 | Refresh, | |
| 22 | 23 | } |
| 23 | 24 | |
| 24 | 25 | #[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] |
| @@ -72,41 +73,202 @@ impl Into<KeybindingsConfig> for KeybindingsConfigTransitional { | ||
| 72 | 73 | fn into(self) -> KeybindingsConfig { |
| 73 | 74 | let mut out = HashMap::default(); |
| 74 | 75 | |
| 75 | for (k, v) in self.0.into_iter() { | |
| 76 | out.insert(k.into(), v); | |
| 76 | for ((modifiers, code), v) in self.0.into_iter() { | |
| 77 | out.insert( | |
| 78 | KeyEvent { | |
| 79 | code: code.into(), | |
| 80 | modifiers: modifiers.into(), | |
| 81 | }, | |
| 82 | v, | |
| 83 | ); | |
| 77 | 84 | } |
| 78 | 85 | |
| 79 | 86 | KeybindingsConfig(out) |
| 80 | 87 | } |
| 81 | 88 | } |
| 82 | 89 | |
| 90 | #[derive(Clone, Copy, Hash, PartialEq, Eq, Serialize, Deserialize)] | |
| 91 | pub enum KeyModifierTransitional { | |
| 92 | Shift, | |
| 93 | Control, | |
| 94 | Alt, | |
| 95 | r#None, | |
| 96 | } | |
| 97 | ||
| 98 | impl Into<KeyModifiers> for KeyModifierTransitional { | |
| 99 | fn into(self) -> KeyModifiers { | |
| 100 | match self { | |
| 101 | Self::Shift => KeyModifiers::SHIFT, | |
| 102 | Self::Control => KeyModifiers::CONTROL, | |
| 103 | Self::Alt => KeyModifiers::ALT, | |
| 104 | Self::None => KeyModifiers::NONE, | |
| 105 | } | |
| 106 | } | |
| 107 | } | |
| 108 | ||
| 109 | impl Into<KeyModifiersTransitional> for KeyModifierTransitional { | |
| 110 | fn into(self) -> KeyModifiersTransitional { | |
| 111 | KeyModifiersTransitional(vec![self]) | |
| 112 | } | |
| 113 | } | |
| 114 | ||
| 115 | #[derive(Clone, Hash, PartialEq, Eq, Serialize, Deserialize)] | |
| 116 | pub struct KeyModifiersTransitional(Vec<KeyModifierTransitional>); | |
| 117 | ||
| 118 | impl Into<KeyModifiers> for KeyModifiersTransitional { | |
| 119 | fn into(self) -> KeyModifiers { | |
| 120 | KeyModifiers::from_bits( | |
| 121 | self.0 | |
| 122 | .into_iter() | |
| 123 | .map(|item| Into::<KeyModifiers>::into(item).bits()) | |
| 124 | .sum(), | |
| 125 | ) | |
| 126 | .unwrap() | |
| 127 | } | |
| 128 | } | |
| 129 | ||
| 130 | impl Default for KeyModifiersTransitional { | |
| 131 | fn default() -> Self { | |
| 132 | Self(vec![KeyModifierTransitional::None]) | |
| 133 | } | |
| 134 | } | |
| 135 | ||
| 83 | 136 | #[derive(Serialize, Deserialize, Clone)] |
| 84 | pub struct KeybindingsConfigTransitional(pub HashMap<KeyCodeTransitional, Action>); | |
| 137 | pub struct KeybindingsConfigTransitional( | |
| 138 | pub HashMap<(KeyModifiersTransitional, KeyCodeTransitional), Action>, | |
| 139 | ); | |
| 85 | 140 | |
| 86 | 141 | impl Default for KeybindingsConfigTransitional { |
| 87 | 142 | fn default() -> Self { |
| 88 | 143 | let mut out = HashMap::default(); |
| 89 | 144 | |
| 90 | out.insert(KeyCodeTransitional::Up, Action::Up); | |
| 91 | out.insert(KeyCodeTransitional::Down, Action::Down); | |
| 92 | out.insert(KeyCodeTransitional::Left, Action::Left); | |
| 93 | out.insert(KeyCodeTransitional::Right, Action::Right); | |
| 145 | out.insert( | |
| 146 | (KeyModifiersTransitional::default(), KeyCodeTransitional::Up), | |
| 147 | Action::Up, | |
| 148 | ); | |
| 149 | out.insert( | |
| 150 | ( | |
| 151 | KeyModifiersTransitional::default(), | |
| 152 | KeyCodeTransitional::Down, | |
| 153 | ), | |
| 154 | Action::Down, | |
| 155 | ); | |
| 156 | out.insert( | |
| 157 | ( | |
| 158 | KeyModifiersTransitional::default(), | |
| 159 | KeyCodeTransitional::Left, | |
| 160 | ), | |
| 161 | Action::Left, | |
| 162 | ); | |
| 163 | out.insert( | |
| 164 | ( | |
| 165 | KeyModifiersTransitional::default(), | |
| 166 | KeyCodeTransitional::Right, | |
| 167 | ), | |
| 168 | Action::Right, | |
| 169 | ); | |
| 94 | 170 | |
| 95 | out.insert(KeyCodeTransitional::Char('h'), Action::Left); | |
| 96 | out.insert(KeyCodeTransitional::Char('j'), Action::Down); | |
| 97 | out.insert(KeyCodeTransitional::Char('k'), Action::Up); | |
| 98 | out.insert(KeyCodeTransitional::Char('l'), Action::Right); | |
| 171 | out.insert( | |
| 172 | ( | |
| 173 | KeyModifiersTransitional::default(), | |
| 174 | KeyCodeTransitional::Char('h'), | |
| 175 | ), | |
| 176 | Action::Left, | |
| 177 | ); | |
| 178 | out.insert( | |
| 179 | ( | |
| 180 | KeyModifiersTransitional::default(), | |
| 181 | KeyCodeTransitional::Char('j'), | |
| 182 | ), | |
| 183 | Action::Down, | |
| 184 | ); | |
| 185 | out.insert( | |
| 186 | ( | |
| 187 | KeyModifiersTransitional::default(), | |
| 188 | KeyCodeTransitional::Char('k'), | |
| 189 | ), | |
| 190 | Action::Up, | |
| 191 | ); | |
| 192 | out.insert( | |
| 193 | ( | |
| 194 | KeyModifiersTransitional::default(), | |
| 195 | KeyCodeTransitional::Char('l'), | |
| 196 | ), | |
| 197 | Action::Right, | |
| 198 | ); | |
| 99 | 199 | |
| 100 | out.insert(KeyCodeTransitional::PageUp, Action::FirstItem); | |
| 101 | out.insert(KeyCodeTransitional::PageDown, Action::LastItem); | |
| 200 | out.insert( | |
| 201 | ( | |
| 202 | KeyModifiersTransitional::default(), | |
| 203 | KeyCodeTransitional::PageUp, | |
| 204 | ), | |
| 205 | Action::FirstItem, | |
| 206 | ); | |
| 207 | out.insert( | |
| 208 | ( | |
| 209 | KeyModifiersTransitional::default(), | |
| 210 | KeyCodeTransitional::PageDown, | |
| 211 | ), | |
| 212 | Action::LastItem, | |
| 213 | ); | |
| 102 | 214 | |
| 103 | out.insert(KeyCodeTransitional::Enter, Action::Select); | |
| 104 | out.insert(KeyCodeTransitional::Esc, Action::Deselect); | |
| 105 | out.insert(KeyCodeTransitional::Char('q'), Action::Exit); | |
| 215 | out.insert( | |
| 216 | ( | |
| 217 | KeyModifiersTransitional::default(), | |
| 218 | KeyCodeTransitional::Enter, | |
| 219 | ), | |
| 220 | Action::Select, | |
| 221 | ); | |
| 222 | out.insert( | |
| 223 | ( | |
| 224 | KeyModifiersTransitional::default(), | |
| 225 | KeyCodeTransitional::Esc, | |
| 226 | ), | |
| 227 | Action::Deselect, | |
| 228 | ); | |
| 229 | out.insert( | |
| 230 | ( | |
| 231 | KeyModifiersTransitional::default(), | |
| 232 | KeyCodeTransitional::Char('q'), | |
| 233 | ), | |
| 234 | Action::Exit, | |
| 235 | ); | |
| 106 | 236 | |
| 107 | out.insert(KeyCodeTransitional::Home, Action::Home); | |
| 108 | out.insert(KeyCodeTransitional::Backspace, Action::Back); | |
| 109 | out.insert(KeyCodeTransitional::End, Action::ClearHistory); | |
| 237 | out.insert( | |
| 238 | ( | |
| 239 | KeyModifiersTransitional::default(), | |
| 240 | KeyCodeTransitional::Home, | |
| 241 | ), | |
| 242 | Action::Home, | |
| 243 | ); | |
| 244 | out.insert( | |
| 245 | ( | |
| 246 | KeyModifiersTransitional::default(), | |
| 247 | KeyCodeTransitional::Backspace, | |
| 248 | ), | |
| 249 | Action::Back, | |
| 250 | ); | |
| 251 | out.insert( | |
| 252 | ( | |
| 253 | KeyModifierTransitional::Alt.into(), | |
| 254 | KeyCodeTransitional::Left, | |
| 255 | ), | |
| 256 | Action::Back, | |
| 257 | ); | |
| 258 | out.insert( | |
| 259 | ( | |
| 260 | KeyModifiersTransitional::default(), | |
| 261 | KeyCodeTransitional::End, | |
| 262 | ), | |
| 263 | Action::ClearHistory, | |
| 264 | ); | |
| 265 | out.insert( | |
| 266 | ( | |
| 267 | KeyModifierTransitional::Control.into(), | |
| 268 | KeyCodeTransitional::Char('r'), | |
| 269 | ), | |
| 270 | Action::Refresh, | |
| 271 | ); | |
| 110 | 272 | |
| 111 | 273 | Self(out) |
| 112 | 274 | } |
| @@ -119,7 +281,7 @@ impl Default for KeybindingsConfig { | ||
| 119 | 281 | } |
| 120 | 282 | |
| 121 | 283 | #[derive(Clone)] |
| 122 | pub struct KeybindingsConfig(pub HashMap<KeyCode, Action>); | |
| 284 | pub struct KeybindingsConfig(pub HashMap<KeyEvent, Action>); | |
| 123 | 285 | |
| 124 | 286 | impl ConfigItem<'_> for KeybindingsConfig { |
| 125 | 287 | type Struct = KeybindingsConfigTransitional; |
src/app/config/layouts.rs +4 −4
| @@ -6,7 +6,7 @@ use crate::{ | ||
| 6 | 6 | main_menu::{MainMenu, MainMenuItem, MainMenuSelector}, |
| 7 | 7 | search::{Search, SearchItem}, |
| 8 | 8 | }, |
| 9 | structs::{Item, Row, RowItem}, | |
| 9 | structs::{Item, Row, RowItem, State}, | |
| 10 | 10 | traits::{ConfigItem, PageTrait}, |
| 11 | 11 | widgets::text_list::TextList, |
| 12 | 12 | }; |
| @@ -64,9 +64,9 @@ pub struct LayoutConfig { | ||
| 64 | 64 | pub message: String, |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | impl Into<Vec<Row>> for LayoutConfig { | |
| 68 | fn into(self) -> Vec<Row> { | |
| 69 | self.layout.into_iter().map(|item| item.into()).collect() | |
| 67 | impl Into<State> for LayoutConfig { | |
| 68 | fn into(self) -> State { | |
| 69 | State(self.layout.into_iter().map(|item| item.into()).collect()) | |
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
src/app/config/main.rs +8
| @@ -22,6 +22,10 @@ fn env_default() -> HashMap<String, String> { | ||
| 22 | 22 | out |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | fn display_thumbnails_default() -> bool { | |
| 26 | true | |
| 27 | } | |
| 28 | ||
| 25 | 29 | #[derive(Clone, Serialize, Deserialize)] |
| 26 | 30 | pub struct MainConfig { |
| 27 | 31 | #[serde(default = "max_watch_history_default")] |
| @@ -30,6 +34,9 @@ pub struct MainConfig { | ||
| 30 | 34 | #[serde(default = "server_url_default")] |
| 31 | 35 | pub server_url: String, |
| 32 | 36 | |
| 37 | #[serde(default = "display_thumbnails_default")] | |
| 38 | pub display_thumbnails: bool, | |
| 39 | ||
| 33 | 40 | #[serde(default = "env_default")] |
| 34 | 41 | pub env: HashMap<String, String>, |
| 35 | 42 | } |
| @@ -39,6 +46,7 @@ impl Default for MainConfig { | ||
| 39 | 46 | Self { |
| 40 | 47 | max_watch_history: max_watch_history_default(), |
| 41 | 48 | server_url: server_url_default(), |
| 49 | display_thumbnails: display_thumbnails_default(), | |
| 42 | 50 | env: env_default(), |
| 43 | 51 | } |
| 44 | 52 | } |
src/app/config/mod.rs +3
| @@ -14,3 +14,6 @@ pub use keybindings::*; | ||
| 14 | 14 | |
| 15 | 15 | mod layouts; |
| 16 | 16 | pub use layouts::*; |
| 17 | ||
| 18 | mod colors; | |
| 19 | pub use colors::*; | |
src/app/pages/channel.rs +11 −5
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | use std::{collections::LinkedList, error::Error}; |
| 2 | 2 | |
| 3 | use crossterm::event::KeyCode; | |
| 3 | use crossterm::event::KeyEvent; | |
| 4 | 4 | use serde::{Deserialize, Serialize}; |
| 5 | 5 | use tui::{ |
| 6 | 6 | backend::Backend, |
| @@ -61,7 +61,9 @@ impl ItemTrait for ChannelItem { | ||
| 61 | 61 | channel.authorThumbnails[4].url.clone(), |
| 62 | 62 | channel.authorId.clone(), |
| 63 | 63 | )); |
| 64 | let _ = download_all_thumbnails(linked_list); | |
| 64 | if app.config.main.display_thumbnails { | |
| 65 | let _ = download_all_thumbnails(linked_list); | |
| 66 | } | |
| 65 | 67 | |
| 66 | 68 | *displayitem = ChannelDisplayItem::Home(channel.into()); |
| 67 | 69 | } |
| @@ -85,7 +87,9 @@ impl ItemTrait for ChannelItem { | ||
| 85 | 87 | .push_back((thumbnail.clone(), item.playlist_id.clone())); |
| 86 | 88 | } |
| 87 | 89 | } |
| 88 | let _ = download_all_thumbnails(linked_list); | |
| 90 | if app.config.main.display_thumbnails { | |
| 91 | let _ = download_all_thumbnails(linked_list); | |
| 92 | } | |
| 89 | 93 | |
| 90 | 94 | *displayitem = ChannelDisplayItem::Playlists(playlists, textlist); |
| 91 | 95 | } |
| @@ -108,8 +112,10 @@ impl ItemTrait for ChannelItem { | ||
| 108 | 112 | linked_list |
| 109 | 113 | .push_back((item.video_thumbnail.clone(), item.video_id.clone())); |
| 110 | 114 | } |
| 111 | let _ = download_all_thumbnails(linked_list); | |
| 112 | 115 | |
| 116 | if app.config.main.display_thumbnails { | |
| 117 | let _ = download_all_thumbnails(linked_list); | |
| 118 | } | |
| 113 | 119 | *displayitem = ChannelDisplayItem::Videos(videos, textlist); |
| 114 | 120 | } |
| 115 | 121 | } |
| @@ -277,7 +283,7 @@ impl ItemTrait for ChannelItem { | ||
| 277 | 283 | out |
| 278 | 284 | } |
| 279 | 285 | |
| 280 | fn key_input(&mut self, key: KeyCode, app: App) -> (bool, App) { | |
| 286 | fn key_input(&mut self, key: KeyEvent, app: App) -> (bool, App) { | |
| 281 | 287 | let action = match app.config.keybindings.0.get(&key) { |
| 282 | 288 | Some(action) => action, |
| 283 | 289 | None => return (false, app), |
src/app/pages/global.rs +28 −6
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | use std::fmt; |
| 2 | 2 | |
| 3 | use crossterm::event::KeyCode; | |
| 3 | use crossterm::event::{KeyCode, KeyEvent}; | |
| 4 | 4 | use serde::{Deserialize, Serialize}; |
| 5 | 5 | use tui::{ |
| 6 | 6 | backend::Backend, |
| @@ -70,14 +70,32 @@ impl ItemTrait for GlobalItem { | ||
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | fn key_input(&mut self, key: KeyCode, mut app: App) -> (bool, App) { | |
| 73 | fn key_input(&mut self, key: KeyEvent, mut app: App) -> (bool, App) { | |
| 74 | 74 | match self { |
| 75 | GlobalItem::SearchBar => match key { | |
| 75 | GlobalItem::SearchBar => match key.code { | |
| 76 | 76 | KeyCode::Char(c) => { |
| 77 | app.search_text.push(c); | |
| 77 | app.search_text.insert(app.search_index, c); | |
| 78 | app.search_index += 1; | |
| 78 | 79 | } |
| 79 | 80 | KeyCode::Backspace => { |
| 80 | app.search_text.pop(); | |
| 81 | if app.search_index != 0 && app.search_text.len() != 0 { | |
| 82 | app.search_text = format!( | |
| 83 | "{}{}", | |
| 84 | &app.search_text[0..app.search_index - 1], | |
| 85 | &app.search_text[app.search_index..app.search_text.len()] | |
| 86 | ); | |
| 87 | app.search_index -= 1; | |
| 88 | }; | |
| 89 | } | |
| 90 | KeyCode::Left => { | |
| 91 | if app.search_index > 0 { | |
| 92 | app.search_index -= 1; | |
| 93 | } | |
| 94 | } | |
| 95 | KeyCode::Right => { | |
| 96 | if app.search_index < app.search_text.len() { | |
| 97 | app.search_index += 1; | |
| 98 | } | |
| 81 | 99 | } |
| 82 | 100 | KeyCode::Enter => { |
| 83 | 101 | if app.search_text.len() == 0 { |
| @@ -86,6 +104,7 @@ impl ItemTrait for GlobalItem { | ||
| 86 | 104 | let state = app.config.layouts.search.clone().into(); |
| 87 | 105 | let mut history = app.history.clone(); |
| 88 | 106 | let search_text = app.search_text.clone(); |
| 107 | let search_index = app.search_index; | |
| 89 | 108 | let search_settings = app.search_settings.clone(); |
| 90 | 109 | history.push(app.into()); |
| 91 | 110 | |
| @@ -97,6 +116,7 @@ impl ItemTrait for GlobalItem { | ||
| 97 | 116 | selectable: App::selectable(&state), |
| 98 | 117 | state, |
| 99 | 118 | search_text, |
| 119 | search_index, | |
| 100 | 120 | search_settings, |
| 101 | 121 | load: true, |
| 102 | 122 | ..Default::default() |
| @@ -143,7 +163,9 @@ impl ItemTrait for GlobalItem { | ||
| 143 | 163 | .title_alignment(Alignment::Center); |
| 144 | 164 | let mut text = out.1.search_text.clone(); |
| 145 | 165 | if selected { |
| 146 | text.push('█'); | |
| 166 | text.push(' '); | |
| 167 | text.replace_range(out.1.search_index..out.1.search_index + 1, "█"); | |
| 168 | // text = format!("{}█{}", &text[0..out.1.search_index], &text[out.1.search_index+1..text.len()]); | |
| 147 | 169 | } |
| 148 | 170 | let paragraph = Paragraph::new(text).block(block); |
| 149 | 171 | frame.render_widget(paragraph, rect); |
src/app/pages/item_info.rs +21 −13
| @@ -14,7 +14,7 @@ use crate::{ | ||
| 14 | 14 | traits::{ItemTrait, PageTrait}, |
| 15 | 15 | widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList}, |
| 16 | 16 | }; |
| 17 | use crossterm::event::KeyCode; | |
| 17 | use crossterm::event::KeyEvent; | |
| 18 | 18 | use tui::{ |
| 19 | 19 | backend::Backend, |
| 20 | 20 | layout::Rect, |
| @@ -65,6 +65,10 @@ impl PlayListDisplayView { | ||
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | impl ItemTrait for ItemInfoItem { |
| 68 | fn reset(&mut self) { | |
| 69 | // panic!("Got here!"); | |
| 70 | *self = Self::Unknown; | |
| 71 | } | |
| 68 | 72 | fn select(&mut self, app: App) -> (App, bool) { |
| 69 | 73 | let selected = true; |
| 70 | 74 | |
| @@ -75,7 +79,7 @@ impl ItemTrait for ItemInfoItem { | ||
| 75 | 79 | true |
| 76 | 80 | } |
| 77 | 81 | |
| 78 | fn key_input(&mut self, key: KeyCode, mut app: App) -> (bool, App) { | |
| 82 | fn key_input(&mut self, key: KeyEvent, mut app: App) -> (bool, App) { | |
| 79 | 83 | let action = match app.config.keybindings.0.get(&key) { |
| 80 | 84 | Some(action) => *action, |
| 81 | 85 | None => return (false, app), |
| @@ -268,10 +272,12 @@ impl ItemTrait for ItemInfoItem { | ||
| 268 | 272 | DisplayItem::Video(id) => { |
| 269 | 273 | let mut list = TextList::default(); |
| 270 | 274 | let video: FullVideo = app.client.video(id, None)?.into(); |
| 271 | let _ = download_all_thumbnails(LinkedList::from([( | |
| 272 | video.video_thumbnail.clone(), | |
| 273 | video.video_id.clone(), | |
| 274 | )])); | |
| 275 | if app.config.main.display_thumbnails { | |
| 276 | let _ = download_all_thumbnails(LinkedList::from([( | |
| 277 | video.video_thumbnail.clone(), | |
| 278 | video.video_id.clone(), | |
| 279 | )])); | |
| 280 | } | |
| 275 | 281 | let commands = app |
| 276 | 282 | .config |
| 277 | 283 | .page_commands |
| @@ -301,13 +307,15 @@ impl ItemTrait for ItemInfoItem { | ||
| 301 | 307 | let mut videos_text_list = TextList::default(); |
| 302 | 308 | let mut playlist_text_list = TextList::default(); |
| 303 | 309 | let playlist: FullPlayList = app.client.playlist(id, None)?.into(); |
| 304 | let _ = download_all_thumbnails( | |
| 305 | playlist | |
| 306 | .videos | |
| 307 | .iter() | |
| 308 | .map(|v| (v.video_thumbnail.clone(), v.video_id.clone())) | |
| 309 | .collect(), | |
| 310 | ); | |
| 310 | if app.config.main.display_thumbnails { | |
| 311 | let _ = download_all_thumbnails( | |
| 312 | playlist | |
| 313 | .videos | |
| 314 | .iter() | |
| 315 | .map(|v| (v.video_thumbnail.clone(), v.video_id.clone())) | |
| 316 | .collect(), | |
| 317 | ); | |
| 318 | } | |
| 311 | 319 | |
| 312 | 320 | videos_text_list.items = vec![String::from("Swtich view")]; |
| 313 | 321 | videos_text_list |
src/app/pages/main_menu.rs +33 −22
| @@ -14,7 +14,7 @@ use crate::{ | ||
| 14 | 14 | traits::{ItemTrait, PageTrait}, |
| 15 | 15 | widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList}, |
| 16 | 16 | }; |
| 17 | use crossterm::event::KeyCode; | |
| 17 | use crossterm::event::KeyEvent; | |
| 18 | 18 | use serde::{Deserialize, Serialize}; |
| 19 | 19 | use tui::{ |
| 20 | 20 | backend::Backend, |
| @@ -47,16 +47,18 @@ impl ItemTrait for MainMenuItem { | ||
| 47 | 47 | .map(|t| ListItem::MiniVideo(t.into())) |
| 48 | 48 | .collect(); |
| 49 | 49 | |
| 50 | download_all_thumbnails( | |
| 51 | list.iter() | |
| 52 | .map(|t| match t { | |
| 53 | ListItem::MiniVideo(v) => { | |
| 54 | (v.video_thumbnail.clone(), v.video_id.clone()) | |
| 55 | } | |
| 56 | _ => unreachable!(), | |
| 57 | }) | |
| 58 | .collect(), | |
| 59 | )?; | |
| 50 | if app.config.main.display_thumbnails { | |
| 51 | let _ = download_all_thumbnails( | |
| 52 | list.iter() | |
| 53 | .map(|t| match t { | |
| 54 | ListItem::MiniVideo(v) => { | |
| 55 | (v.video_thumbnail.clone(), v.video_id.clone()) | |
| 56 | } | |
| 57 | _ => unreachable!(), | |
| 58 | }) | |
| 59 | .collect(), | |
| 60 | ); | |
| 61 | } | |
| 60 | 62 | |
| 61 | 63 | if let Some((video_list, text_list, _)) = enum_items { |
| 62 | 64 | *text_list = TextList::default(); |
| @@ -79,16 +81,18 @@ impl ItemTrait for MainMenuItem { | ||
| 79 | 81 | .map(|t| ListItem::MiniVideo(t.into())) |
| 80 | 82 | .collect(); |
| 81 | 83 | |
| 82 | let _ = download_all_thumbnails( | |
| 83 | list.iter() | |
| 84 | .map(|t| match t { | |
| 85 | ListItem::MiniVideo(v) => { | |
| 86 | (v.video_thumbnail.clone(), v.video_id.clone()) | |
| 87 | } | |
| 88 | _ => unreachable!(), | |
| 89 | }) | |
| 90 | .collect(), | |
| 91 | ); | |
| 84 | if app.config.main.display_thumbnails { | |
| 85 | let _ = download_all_thumbnails( | |
| 86 | list.iter() | |
| 87 | .map(|t| match t { | |
| 88 | ListItem::MiniVideo(v) => { | |
| 89 | (v.video_thumbnail.clone(), v.video_id.clone()) | |
| 90 | } | |
| 91 | _ => unreachable!(), | |
| 92 | }) | |
| 93 | .collect(), | |
| 94 | ); | |
| 95 | } | |
| 92 | 96 | |
| 93 | 97 | let mut text_list = TextList::default(); |
| 94 | 98 | |
| @@ -220,6 +224,13 @@ impl ItemTrait for MainMenuItem { | ||
| 220 | 224 | } |
| 221 | 225 | out |
| 222 | 226 | } |
| 227 | ||
| 228 | fn reset(&mut self) { | |
| 229 | if let Self::VideoList(something) = self { | |
| 230 | *something = None; | |
| 231 | } | |
| 232 | } | |
| 233 | ||
| 223 | 234 | fn select(&mut self, mut app: App) -> (App, bool) { |
| 224 | 235 | let selected = match self { |
| 225 | 236 | MainMenuItem::SeletorTab(selector) => { |
| @@ -241,7 +252,7 @@ impl ItemTrait for MainMenuItem { | ||
| 241 | 252 | true |
| 242 | 253 | } |
| 243 | 254 | |
| 244 | fn key_input(&mut self, key: KeyCode, app: App) -> (bool, App) { | |
| 255 | fn key_input(&mut self, key: KeyEvent, app: App) -> (bool, App) { | |
| 245 | 256 | match self { |
| 246 | 257 | MainMenuItem::VideoList(Some((list, textlist, _))) => { |
| 247 | 258 | let action = match app.config.keybindings.0.get(&key) { |
src/app/pages/search.rs +5 −3
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | use std::{collections::LinkedList, error::Error}; |
| 2 | 2 | |
| 3 | use crossterm::event::KeyCode; | |
| 3 | use crossterm::event::KeyEvent; | |
| 4 | 4 | use invidious::structs::hidden::SearchItem as InvidiousSearchItem; |
| 5 | 5 | use tui::{ |
| 6 | 6 | backend::Backend, |
| @@ -45,7 +45,7 @@ impl ItemTrait for SearchItem { | ||
| 45 | 45 | true |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | fn key_input(&mut self, key: KeyCode, app: App) -> (bool, App) { | |
| 48 | fn key_input(&mut self, key: KeyEvent, app: App) -> (bool, App) { | |
| 49 | 49 | let action = match app.config.keybindings.0.get(&key) { |
| 50 | 50 | Some(action) => action, |
| 51 | 51 | None => return (false, app), |
| @@ -275,7 +275,9 @@ impl ItemTrait for SearchItem { | ||
| 275 | 275 | } |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | let _ = download_all_thumbnails(thumbnails); | |
| 278 | if app.config.main.display_thumbnails { | |
| 279 | let _ = download_all_thumbnails(thumbnails); | |
| 280 | } | |
| 279 | 281 | |
| 280 | 282 | *results = Some(items); |
| 281 | 283 | } |
src/main.rs +8 −8
| @@ -10,7 +10,7 @@ use tui::{ | ||
| 10 | 10 | }; |
| 11 | 11 | use youtube_tui::{ |
| 12 | 12 | app::{app::App, config::Action}, |
| 13 | structs::{Row, RowItem}, | |
| 13 | structs::{Row, RowItem, State}, | |
| 14 | 14 | }; |
| 15 | 15 | |
| 16 | 16 | fn main() -> Result<(), Box<dyn Error>> { |
| @@ -55,7 +55,7 @@ fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<( | ||
| 55 | 55 | app = hold.0; |
| 56 | 56 | hold.1?; |
| 57 | 57 | let mut new_state = Vec::new(); |
| 58 | for row in app.state.iter() { | |
| 58 | for row in app.state.0.iter() { | |
| 59 | 59 | let mut row_vec = Vec::new(); |
| 60 | 60 | for row_item in row.items.iter() { |
| 61 | 61 | match row_item.item.load_item(&app, &mut watch_history) { |
| @@ -82,7 +82,7 @@ fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<( | ||
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | app.watch_history = watch_history; |
| 85 | app.state = new_state; | |
| 85 | app.state = State(new_state); | |
| 86 | 86 | |
| 87 | 87 | app.load = false; |
| 88 | 88 | terminal.clear()?; |
| @@ -92,7 +92,7 @@ fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<( | ||
| 92 | 92 | match event::read()? { |
| 93 | 93 | event::Event::Key(key) => { |
| 94 | 94 | if app.selected.is_none() { |
| 95 | let action = match app.config.keybindings.0.get(&key.code) { | |
| 95 | let action = match app.config.keybindings.0.get(&key) { | |
| 96 | 96 | Some(action) => *action, |
| 97 | 97 | None => continue, |
| 98 | 98 | }; |
| @@ -122,7 +122,7 @@ fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<( | ||
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | app = app.key_input(key.code); | |
| 125 | app = app.key_input(key); | |
| 126 | 126 | app.render = true; |
| 127 | 127 | } |
| 128 | 128 | event::Event::Resize(_, _) => { |
| @@ -158,9 +158,10 @@ fn init() -> Result<(), Box<dyn Error>> { | ||
| 158 | 158 | let mut dir = home_dir.clone(); |
| 159 | 159 | |
| 160 | 160 | dir.push(".cache"); |
| 161 | if !dir.exists() { | |
| 162 | fs::create_dir(&dir)?; | |
| 161 | if dir.exists() { | |
| 162 | fs::remove_dir_all(&dir)?; | |
| 163 | 163 | } |
| 164 | fs::create_dir(&dir)?; | |
| 164 | 165 | |
| 165 | 166 | dir.push("youtube-tui"); |
| 166 | 167 | if !dir.exists() { |
| @@ -235,7 +236,6 @@ fn exit() -> Result<(), Box<dyn Error>> { | ||
| 235 | 236 | |
| 236 | 237 | dir.push(".cache"); |
| 237 | 238 | dir.push("youtube-tui"); |
| 238 | dir.push("cache"); | |
| 239 | 239 | |
| 240 | 240 | if dir.exists() { |
| 241 | 241 | fs::remove_dir_all(&dir)?; |
src/structs/apphistory.rs +7 −7
| @@ -1,16 +1,13 @@ | ||
| 1 | 1 | use invidious::blocking::Client; |
| 2 | 2 | |
| 3 | use crate::{ | |
| 4 | app::app::App, | |
| 5 | structs::{Page, Row}, | |
| 6 | }; | |
| 3 | use crate::{app::app::App, structs::Page}; | |
| 7 | 4 | |
| 8 | use super::SearchSettings; | |
| 5 | use super::{SearchSettings, State}; | |
| 9 | 6 | |
| 10 | 7 | #[derive(Clone)] |
| 11 | 8 | pub struct AppHistory { |
| 12 | 9 | pub page: Page, |
| 13 | pub state: Vec<Row>, // Item | |
| 10 | pub state: State, // Item | |
| 14 | 11 | pub selectable: Vec<Vec<(usize, usize)>>, |
| 15 | 12 | pub hover: Option<(usize, usize)>, // x, y |
| 16 | 13 | pub selected: Option<(usize, usize)>, |
| @@ -21,6 +18,7 @@ pub struct AppHistory { | ||
| 21 | 18 | pub popup_focus: bool, |
| 22 | 19 | pub search_text: String, |
| 23 | 20 | pub search_settings: SearchSettings, |
| 21 | pub search_index: usize, | |
| 24 | 22 | pub page_no: usize, |
| 25 | 23 | } |
| 26 | 24 | |
| @@ -31,7 +29,8 @@ impl From<App> for AppHistory { | ||
| 31 | 29 | state: original.state, |
| 32 | 30 | selectable: original.selectable, |
| 33 | 31 | hover: original.hover, |
| 34 | selected: original.selected, | |
| 32 | // selected: original.selected, | |
| 33 | selected: None, | |
| 35 | 34 | client: original.client, |
| 36 | 35 | message: original.message, |
| 37 | 36 | load: original.load, |
| @@ -39,6 +38,7 @@ impl From<App> for AppHistory { | ||
| 39 | 38 | popup_focus: original.popup_focus, |
| 40 | 39 | search_text: original.search_text, |
| 41 | 40 | search_settings: original.search_settings, |
| 41 | search_index: original.search_index, | |
| 42 | 42 | page_no: original.page_no, |
| 43 | 43 | } |
| 44 | 44 | } |
src/structs/search_settings.rs +3 −3
| @@ -1,4 +1,4 @@ | ||
| 1 | use crossterm::event::KeyCode; | |
| 1 | use crossterm::event::KeyEvent; | |
| 2 | 2 | |
| 3 | 3 | use crate::{ |
| 4 | 4 | app::config::{Action, Config}, |
| @@ -66,8 +66,8 @@ impl SearchSettings { | ||
| 66 | 66 | vec |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | pub fn key_input(&mut self, keycode: KeyCode, config: &Config) { | |
| 70 | let action = match config.keybindings.0.get(&keycode) { | |
| 69 | pub fn key_input(&mut self, key: KeyEvent, config: &Config) { | |
| 70 | let action = match config.keybindings.0.get(&key) { | |
| 71 | 71 | Some(action) => *action, |
| 72 | 72 | None => return, |
| 73 | 73 | }; |
src/structs/states.rs +25 −2
| @@ -1,4 +1,4 @@ | ||
| 1 | use crossterm::event::KeyCode; | |
| 1 | use crossterm::event::KeyEvent; | |
| 2 | 2 | use std::error::Error; |
| 3 | 3 | use tui::{ |
| 4 | 4 | backend::Backend, |
| @@ -19,6 +19,19 @@ use crate::{ | ||
| 19 | 19 | |
| 20 | 20 | use super::WatchHistory; |
| 21 | 21 | |
| 22 | #[derive(Clone)] | |
| 23 | pub struct State(pub Vec<Row>); | |
| 24 | ||
| 25 | impl State { | |
| 26 | pub fn reset(&mut self) { | |
| 27 | for row in self.0.iter_mut() { | |
| 28 | for rowitem in row.items.iter_mut() { | |
| 29 | rowitem.item.reset(); | |
| 30 | } | |
| 31 | } | |
| 32 | } | |
| 33 | } | |
| 34 | ||
| 22 | 35 | #[derive(Clone)] |
| 23 | 36 | pub enum Item { |
| 24 | 37 | Global(GlobalItem), |
| @@ -29,7 +42,7 @@ pub enum Item { | ||
| 29 | 42 | } |
| 30 | 43 | |
| 31 | 44 | impl Item { |
| 32 | pub fn key_input(&mut self, key: KeyCode, app: App) -> (bool, App) { | |
| 45 | pub fn key_input(&mut self, key: KeyEvent, app: App) -> (bool, App) { | |
| 33 | 46 | match self { |
| 34 | 47 | Item::Global(item) => item.key_input(key, app), |
| 35 | 48 | Item::MainMenu(item) => item.key_input(key, app), |
| @@ -39,6 +52,16 @@ impl Item { | ||
| 39 | 52 | } |
| 40 | 53 | } |
| 41 | 54 | |
| 55 | pub fn reset(&mut self) { | |
| 56 | match self { | |
| 57 | Item::Global(item) => item.reset(), | |
| 58 | Item::MainMenu(item) => item.reset(), | |
| 59 | Item::ItemInfo(item) => item.reset(), | |
| 60 | Item::Search(item) => item.reset(), | |
| 61 | Item::Channel(item) => item.reset(), | |
| 62 | }; | |
| 63 | } | |
| 64 | ||
| 42 | 65 | pub fn render_item<B: Backend>( |
| 43 | 66 | &mut self, |
| 44 | 67 | frame: &mut Frame<B>, |
src/traits/item.rs +3 −2
| @@ -4,11 +4,11 @@ use crate::{ | ||
| 4 | 4 | app::app::{App, AppNoState}, |
| 5 | 5 | structs::{Item, WatchHistory}, |
| 6 | 6 | }; |
| 7 | use crossterm::event::KeyCode; | |
| 7 | use crossterm::event::KeyEvent; | |
| 8 | 8 | use tui::{backend::Backend, layout::Rect, Frame}; |
| 9 | 9 | |
| 10 | 10 | pub trait ItemTrait { |
| 11 | fn key_input(&mut self, key: KeyCode, app: App) -> (bool, App); | |
| 11 | fn key_input(&mut self, key: KeyEvent, app: App) -> (bool, App); | |
| 12 | 12 | fn render_item<B: Backend>( |
| 13 | 13 | &mut self, |
| 14 | 14 | frame: &mut Frame<B>, |
| @@ -26,4 +26,5 @@ pub trait ItemTrait { | ||
| 26 | 26 | app: &App, |
| 27 | 27 | watch_history: &mut WatchHistory, |
| 28 | 28 | ) -> Result<Item, Box<dyn Error>>; |
| 29 | fn reset(&mut self) {} | |
| 29 | 30 | } |