Commit be4224817b
Unsigned
Layout: unified · split
Cargo.lock +1 −1
| @@ -1716,7 +1716,7 @@ dependencies = [ | |||
| 1716 | 1716 | ||
| 1717 | [[package]] | 1717 | [[package]] |
| 1718 | name = "youtube-tui" | 1718 | name = "youtube-tui" |
| 1719 | version = "0.4.0" | 1719 | version = "0.4.1" |
| 1720 | dependencies = [ | 1720 | dependencies = [ |
| 1721 | "chrono", | 1721 | "chrono", |
| 1722 | "crossterm", | 1722 | "crossterm", |
Cargo.toml +1 −1
| @@ -1,6 +1,6 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | name = "youtube-tui" | 2 | name = "youtube-tui" |
| 3 | version = "0.4.0" | 3 | version = "0.4.1" |
| 4 | edition = "2021" | 4 | edition = "2021" |
| 5 | authors = ["Siriusmart <siriusmart@tuta.io>"] | 5 | authors = ["Siriusmart <siriusmart@tuta.io>"] |
| 6 | description = "An aesthetically pleasing YouTube TUI written in Rust" | 6 | description = "An aesthetically pleasing YouTube TUI written in Rust" |
README.md +15 −4
| @@ -18,10 +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 | > * More code cleanup | 21 | > * Fixed text list not scrolling with cursor bug (where the cursor just goes out of the screen) |
| 22 | > * Commands to be ran in Item Info page can be changed, items can be add/removed (in `page_commands.yml`) | 22 | > * Improvements to the `render()` method |
| 23 | > * Keybindings can be created (VIM keybindings are included in default config) | ||
| 24 | > * Config soft update (tries to add new options to the config, and if parsing config failed the config will be backed up and a new one will be generated) | ||
| 25 | 23 | ||
| 26 | ## Installation | 24 | ## Installation |
| 27 | 25 | ||
| @@ -73,10 +71,23 @@ youtube-tui # or path to the binary | |||
| 73 | 71 | ||
| 74 | All config files are loacted at `~/.config/youtube-tui/`, will write documentations for that later | 72 | All config files are loacted at `~/.config/youtube-tui/`, will write documentations for that later |
| 75 | 73 | ||
| 74 | ## Known issues | ||
| 75 | |||
| 76 | ### Missing hash key: "selected" | ||
| 77 | |||
| 78 | When viewing the playlists page in a channel, it gives you `Missing hash key: "selected"`. This is because Invidious was not able to fetch the requested playlists. | ||
| 79 | |||
| 80 | You should also see an error when visiting [this URL](https://vid.puffyan.us/api/v1/channels/UCAkuTH35kk3W1EL9vq6dj6A/playlists) | ||
| 81 | |||
| 82 | Here's the [opened issue](https://github.com/iv-org/invidious/issues/3154) | ||
| 83 | |||
| 76 | ## Todo (First piority on top) | 84 | ## Todo (First piority on top) |
| 77 | 85 | ||
| 78 | * Put hard coded options into config files | 86 | * Put hard coded options into config files |
| 79 | * User manual + documentations | 87 | * User manual + documentations |
| 88 | * Go directly to a page by URL | ||
| 89 | * Vim-like commands in status bar | ||
| 90 | * Command line launch options | ||
| 80 | * Channel search and channel video sort | 91 | * Channel search and channel video sort |
| 81 | * Recommended videos | 92 | * Recommended videos |
| 82 | 93 | ||
src/app/app.rs +14 −20
| @@ -212,7 +212,6 @@ impl App { | |||
| 212 | pub fn render<B: Backend>(mut self, frame: &mut Frame<B>) -> Self { | 212 | pub fn render<B: Backend>(mut self, frame: &mut Frame<B>) -> Self { |
| 213 | let size = frame.size(); | 213 | let size = frame.size(); |
| 214 | let mut popups = Vec::new(); | 214 | let mut popups = Vec::new(); |
| 215 | let mut modified = Vec::new(); | ||
| 216 | 215 | ||
| 217 | let min = match self.page { | 216 | let min = match self.page { |
| 218 | Page::MainMenu(_) => MainMenu::min(), | 217 | Page::MainMenu(_) => MainMenu::min(), |
| @@ -249,11 +248,11 @@ impl App { | |||
| 249 | ) | 248 | ) |
| 250 | .split(size); | 249 | .split(size); |
| 251 | 250 | ||
| 252 | let state = self.state.clone(); | 251 | let mut state = self.state.clone(); |
| 253 | 252 | ||
| 254 | for (y, (row, row_chunk)) in state | 253 | for (y, (row, row_chunk)) in state |
| 255 | .iter() | 254 | .iter_mut() |
| 256 | .zip(vertical_chunks.clone().into_iter()) | 255 | .zip(vertical_chunks.clone().iter_mut()) |
| 257 | .enumerate() | 256 | .enumerate() |
| 258 | { | 257 | { |
| 259 | let mut constraints = LinkedList::new(); | 258 | let mut constraints = LinkedList::new(); |
| @@ -286,12 +285,15 @@ impl App { | |||
| 286 | let mut chunks = Layout::default() | 285 | let mut chunks = Layout::default() |
| 287 | .direction(Direction::Horizontal) | 286 | .direction(Direction::Horizontal) |
| 288 | .constraints(constraints.into_iter().collect::<Vec<Constraint>>()) | 287 | .constraints(constraints.into_iter().collect::<Vec<Constraint>>()) |
| 289 | .split(row_chunk) | 288 | .split(*row_chunk) |
| 290 | .into_iter(); | 289 | .into_iter(); |
| 291 | 290 | ||
| 292 | frame.render_widget(Block::default(), chunks.next().unwrap()); | 291 | frame.render_widget(Block::default(), chunks.next().unwrap()); |
| 293 | 292 | ||
| 294 | for (x, (chunk, item)) in chunks.zip(row.items.iter().map(|i| &i.item)).enumerate() { | 293 | for (x, (chunk, item)) in chunks |
| 294 | .zip(row.items.iter_mut().map(|i| &mut i.item)) | ||
| 295 | .enumerate() | ||
| 296 | { | ||
| 295 | let selected = self.selected == Some((x, y)); | 297 | let selected = self.selected == Some((x, y)); |
| 296 | 298 | ||
| 297 | let hover = hover_selected == Some((x, y)); | 299 | let hover = hover_selected == Some((x, y)); |
| @@ -300,30 +302,22 @@ impl App { | |||
| 300 | let hold = | 302 | let hold = |
| 301 | item.render_item(frame, chunk, self, selected, hover, popup_focus, false); | 303 | item.render_item(frame, chunk, self, selected, hover, popup_focus, false); |
| 302 | 304 | ||
| 303 | self = hold.2; | 305 | self = hold.1; |
| 304 | |||
| 305 | if let Some(item) = hold.1 { | ||
| 306 | modified.push((x, y, item)); | ||
| 307 | } | ||
| 308 | 306 | ||
| 309 | if hold.0 { | 307 | if hold.0 { |
| 310 | popups.push((item, selected, hover, chunk, x, y)); | 308 | popups.push((item, selected, hover, chunk)); |
| 311 | } | 309 | } |
| 312 | } | 310 | } |
| 313 | } | 311 | } |
| 314 | 312 | ||
| 315 | for (item, selected, hover, chunk, x, y) in popups { | 313 | for (item, selected, hover, chunk) in popups { |
| 316 | let hold = item.render_item(frame, chunk, self, selected, hover, true, true); | 314 | let hold = item.render_item(frame, chunk, self, selected, hover, true, true); |
| 317 | self = hold.2; | 315 | self = hold.1; |
| 318 | 316 | ||
| 319 | if let Some(item) = hold.1 { | ||
| 320 | modified.push((x, y, item)); | ||
| 321 | } | ||
| 322 | } | 317 | } |
| 323 | 318 | ||
| 324 | for (x, y, item) in modified { | 319 | self.state = state; |
| 325 | self.state[y].items[x].item = item; | 320 | |
| 326 | } | ||
| 327 | self | 321 | self |
| 328 | } | 322 | } |
| 329 | 323 | ||
src/app/pages/channel.rs +22 −41
| @@ -125,7 +125,7 @@ impl ItemTrait for ChannelItem { | |||
| 125 | // hover: bool, | 125 | // hover: bool, |
| 126 | // popup_focus: bool, | 126 | // popup_focus: bool, |
| 127 | // page: &Page, | 127 | // page: &Page, |
| 128 | &self, | 128 | &mut self, |
| 129 | frame: &mut Frame<B>, | 129 | frame: &mut Frame<B>, |
| 130 | rect: Rect, | 130 | rect: Rect, |
| 131 | app: App, | 131 | app: App, |
| @@ -133,8 +133,8 @@ impl ItemTrait for ChannelItem { | |||
| 133 | hover: bool, | 133 | hover: bool, |
| 134 | popup_focus: bool, | 134 | popup_focus: bool, |
| 135 | _: bool, | 135 | _: bool, |
| 136 | ) -> (bool, Option<Item>, App) { | 136 | ) -> (bool, App) { |
| 137 | let mut out = (false, None, app); | 137 | let mut out = (false, app); |
| 138 | 138 | ||
| 139 | let mut style = Style::default().fg(if selected { | 139 | let mut style = Style::default().fg(if selected { |
| 140 | Color::LightBlue | 140 | Color::LightBlue |
| @@ -184,15 +184,22 @@ impl ItemTrait for ChannelItem { | |||
| 184 | 184 | ||
| 185 | frame.render_widget(split, rect); | 185 | frame.render_widget(split, rect); |
| 186 | 186 | ||
| 187 | let mut textlist = textlist.clone(); | 187 | match &mut textlist.area { |
| 188 | Some(area) if *area != chunks[0] => { | ||
| 189 | *area = chunks[0]; | ||
| 190 | out.0 = true; | ||
| 191 | } | ||
| 192 | None => { | ||
| 193 | textlist.area = Some(chunks[0]); | ||
| 194 | out.0 = true; | ||
| 195 | } | ||
| 196 | |||
| 197 | _ => {} | ||
| 198 | }; | ||
| 188 | 199 | ||
| 189 | textlist.area(chunks[0]); | 200 | textlist.area(chunks[0]); |
| 190 | 201 | ||
| 191 | let hold_textlist = if textlist.area == textlist.prev_area { | 202 | let mut textlist = textlist.clone(); |
| 192 | None | ||
| 193 | } else { | ||
| 194 | Some(textlist.clone()) | ||
| 195 | }; | ||
| 196 | 203 | ||
| 197 | if selected { | 204 | if selected { |
| 198 | textlist.selected_style(Style::default().fg(Color::LightRed)); | 205 | textlist.selected_style(Style::default().fg(Color::LightRed)); |
| @@ -212,12 +219,6 @@ impl ItemTrait for ChannelItem { | |||
| 212 | } | 219 | } |
| 213 | 220 | ||
| 214 | frame.render_widget(textlist, chunks[0]); | 221 | frame.render_widget(textlist, chunks[0]); |
| 215 | |||
| 216 | if let Some(textlist) = hold_textlist { | ||
| 217 | out.1 = Some(Item::Channel(ChannelItem::InfoDisplay( | ||
| 218 | ChannelDisplayItem::Videos(videos.clone(), textlist), | ||
| 219 | ))); | ||
| 220 | } | ||
| 221 | } | 222 | } |
| 222 | ChannelDisplayItem::Playlists(playlists, textlist) => { | 223 | ChannelDisplayItem::Playlists(playlists, textlist) => { |
| 223 | let split = HorizontalSplit::default() | 224 | let split = HorizontalSplit::default() |
| @@ -234,15 +235,9 @@ impl ItemTrait for ChannelItem { | |||
| 234 | 235 | ||
| 235 | frame.render_widget(split, rect); | 236 | frame.render_widget(split, rect); |
| 236 | 237 | ||
| 237 | let mut textlist = textlist.clone(); | ||
| 238 | |||
| 239 | textlist.area(chunks[0]); | 238 | textlist.area(chunks[0]); |
| 240 | 239 | ||
| 241 | let hold_textlist = if textlist.area == textlist.prev_area { | 240 | let mut textlist = textlist.clone(); |
| 242 | None | ||
| 243 | } else { | ||
| 244 | Some(textlist.clone()) | ||
| 245 | }; | ||
| 246 | 241 | ||
| 247 | if selected { | 242 | if selected { |
| 248 | textlist.selected_style(Style::default().fg(Color::LightRed)); | 243 | textlist.selected_style(Style::default().fg(Color::LightRed)); |
| @@ -262,17 +257,11 @@ impl ItemTrait for ChannelItem { | |||
| 262 | } | 257 | } |
| 263 | 258 | ||
| 264 | frame.render_widget(textlist, chunks[0]); | 259 | frame.render_widget(textlist, chunks[0]); |
| 265 | |||
| 266 | if let Some(textlist) = hold_textlist { | ||
| 267 | out.1 = Some(Item::Channel(ChannelItem::InfoDisplay( | ||
| 268 | ChannelDisplayItem::Playlists(playlists.clone(), textlist), | ||
| 269 | ))); | ||
| 270 | } | ||
| 271 | } | 260 | } |
| 272 | }, | 261 | }, |
| 273 | ChannelItem::SelectItems(selected_page) => { | 262 | ChannelItem::SelectItems(selected_page) => { |
| 274 | if !hover { | 263 | if !hover { |
| 275 | if let Page::Channel(channel_page, _) = &out.2.page { | 264 | if let Page::Channel(channel_page, _) = &out.1.page { |
| 276 | if *selected_page == *channel_page { | 265 | if *selected_page == *channel_page { |
| 277 | style = style.fg(Color::LightYellow); | 266 | style = style.fg(Color::LightYellow); |
| 278 | } | 267 | } |
| @@ -308,12 +297,8 @@ impl ItemTrait for ChannelItem { | |||
| 308 | Action::Down => { | 297 | Action::Down => { |
| 309 | textlist.down(); | 298 | textlist.down(); |
| 310 | } | 299 | } |
| 311 | Action::FirstItem => { | 300 | Action::FirstItem => textlist.first(), |
| 312 | textlist.selected = 0; | 301 | Action::LastItem => textlist.last(), |
| 313 | } | ||
| 314 | Action::LastItem => { | ||
| 315 | textlist.selected = textlist.items.len() - 1; | ||
| 316 | } | ||
| 317 | Action::Select => { | 302 | Action::Select => { |
| 318 | let state = ItemInfo::default(); | 303 | let state = ItemInfo::default(); |
| 319 | let mut history = app.history.clone(); | 304 | let mut history = app.history.clone(); |
| @@ -342,12 +327,8 @@ impl ItemTrait for ChannelItem { | |||
| 342 | Action::Down => { | 327 | Action::Down => { |
| 343 | textlist.down(); | 328 | textlist.down(); |
| 344 | } | 329 | } |
| 345 | Action::FirstItem => { | 330 | Action::FirstItem => textlist.first(), |
| 346 | textlist.selected = 0; | 331 | Action::LastItem => textlist.last(), |
| 347 | } | ||
| 348 | Action::LastItem => { | ||
| 349 | textlist.selected = textlist.items.len() - 1; | ||
| 350 | } | ||
| 351 | Action::Select => { | 332 | Action::Select => { |
| 352 | let state = ItemInfo::default(); | 333 | let state = ItemInfo::default(); |
| 353 | let mut history = app.history.clone(); | 334 | let mut history = app.history.clone(); |
src/app/pages/global.rs +14 −14
| @@ -118,7 +118,7 @@ impl ItemTrait for GlobalItem { | |||
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | fn render_item<B: Backend>( | 120 | fn render_item<B: Backend>( |
| 121 | &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: App, |
| @@ -126,9 +126,9 @@ impl ItemTrait for GlobalItem { | |||
| 126 | hover: bool, | 126 | hover: bool, |
| 127 | _: bool, | 127 | _: bool, |
| 128 | popup_render: bool, | 128 | popup_render: bool, |
| 129 | ) -> (bool, Option<Item>, App) { | 129 | ) -> (bool, App) { |
| 130 | let area = frame.size(); | 130 | let area = frame.size(); |
| 131 | let mut out = (false, None, app); | 131 | let mut out = (false, app); |
| 132 | match self { | 132 | match self { |
| 133 | GlobalItem::SearchBar => { | 133 | GlobalItem::SearchBar => { |
| 134 | let block = Block::default() | 134 | let block = Block::default() |
| @@ -143,7 +143,7 @@ impl ItemTrait for GlobalItem { | |||
| 143 | })) | 143 | })) |
| 144 | .title("Search YouTube") | 144 | .title("Search YouTube") |
| 145 | .title_alignment(Alignment::Center); | 145 | .title_alignment(Alignment::Center); |
| 146 | let mut text = out.2.search_text.clone(); | 146 | let mut text = out.1.search_text.clone(); |
| 147 | if selected { | 147 | if selected { |
| 148 | text.push('█'); | 148 | text.push('█'); |
| 149 | } | 149 | } |
| @@ -151,7 +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.2.message.lock().unwrap(); | 154 | let message = out.1.message.lock().unwrap(); |
| 155 | // let color = Color::LightYellow; | 155 | // let color = Color::LightYellow; |
| 156 | let block = Block::default() | 156 | let block = Block::default() |
| 157 | .border_type(BorderType::Rounded) | 157 | .border_type(BorderType::Rounded) |
| @@ -197,39 +197,39 @@ impl ItemTrait for GlobalItem { | |||
| 197 | 197 | ||
| 198 | frame.render_widget(split, rect); | 198 | frame.render_widget(split, rect); |
| 199 | 199 | ||
| 200 | out.2.search_settings.text_list.area(chunks[0]); | 200 | out.1.search_settings.text_list.area(chunks[0]); |
| 201 | 201 | ||
| 202 | if out.2.search_settings.row { | 202 | if out.1.search_settings.row { |
| 203 | out.2 | 203 | out.1 |
| 204 | .search_settings | 204 | .search_settings |
| 205 | .text_list | 205 | .text_list |
| 206 | .selected_style(Style::default().fg(Color::LightRed)); | 206 | .selected_style(Style::default().fg(Color::LightRed)); |
| 207 | 207 | ||
| 208 | out.2 | 208 | out.1 |
| 209 | .search_settings | 209 | .search_settings |
| 210 | .select_text_list | 210 | .select_text_list |
| 211 | .selected_style(Style::default().fg(Color::LightYellow)); | 211 | .selected_style(Style::default().fg(Color::LightYellow)); |
| 212 | } else { | 212 | } else { |
| 213 | out.2 | 213 | out.1 |
| 214 | .search_settings | 214 | .search_settings |
| 215 | .text_list | 215 | .text_list |
| 216 | .selected_style(Style::default().fg(Color::LightYellow)); | 216 | .selected_style(Style::default().fg(Color::LightYellow)); |
| 217 | 217 | ||
| 218 | out.2 | 218 | out.1 |
| 219 | .search_settings | 219 | .search_settings |
| 220 | .select_text_list | 220 | .select_text_list |
| 221 | .selected_style(Style::default().fg(Color::LightRed)); | 221 | .selected_style(Style::default().fg(Color::LightRed)); |
| 222 | } | 222 | } |
| 223 | 223 | ||
| 224 | frame.render_widget( | 224 | frame.render_widget( |
| 225 | out.2.search_settings.text_list.clone(), | 225 | out.1.search_settings.text_list.clone(), |
| 226 | chunks[0], | 226 | chunks[0], |
| 227 | ); | 227 | ); |
| 228 | 228 | ||
| 229 | out.2.search_settings.select_text_list.area(chunks[1]); | 229 | out.1.search_settings.select_text_list.area(chunks[1]); |
| 230 | 230 | ||
| 231 | frame.render_widget( | 231 | frame.render_widget( |
| 232 | out.2.search_settings.select_text_list.clone(), | 232 | out.1.search_settings.select_text_list.clone(), |
| 233 | chunks[1], | 233 | chunks[1], |
| 234 | ); | 234 | ); |
| 235 | 235 | ||
src/app/pages/item_info.rs +27 −28
| @@ -1,7 +1,4 @@ | |||
| 1 | use std::{ | 1 | use std::{collections::LinkedList, error::Error}; |
| 2 | collections::LinkedList, | ||
| 3 | error::Error, | ||
| 4 | }; | ||
| 5 | 2 | ||
| 6 | use crate::{ | 3 | use crate::{ |
| 7 | app::{ | 4 | app::{ |
| @@ -84,8 +81,8 @@ impl ItemTrait for ItemInfoItem { | |||
| 84 | ItemInfoItem::Video(videoinfo) => match action { | 81 | ItemInfoItem::Video(videoinfo) => match action { |
| 85 | Action::Up => videoinfo.list.up(), | 82 | Action::Up => videoinfo.list.up(), |
| 86 | Action::Down => videoinfo.list.down(), | 83 | Action::Down => videoinfo.list.down(), |
| 87 | Action::FirstItem => videoinfo.list.selected = 0, | 84 | Action::FirstItem => videoinfo.list.first(), |
| 88 | Action::LastItem => videoinfo.list.selected = videoinfo.list.items.len() - 1, | 85 | Action::LastItem => videoinfo.list.last(), |
| 89 | Action::Select => { | 86 | Action::Select => { |
| 90 | let command = &videoinfo.commands[videoinfo.list.selected]; | 87 | let command = &videoinfo.commands[videoinfo.list.selected]; |
| 91 | 88 | ||
| @@ -153,11 +150,8 @@ impl ItemTrait for ItemInfoItem { | |||
| 153 | PlayListDisplayView::PlayListView => match action { | 150 | PlayListDisplayView::PlayListView => match action { |
| 154 | Action::Up => playlistinfo.playlist_view_list.up(), | 151 | Action::Up => playlistinfo.playlist_view_list.up(), |
| 155 | Action::Down => playlistinfo.playlist_view_list.down(), | 152 | Action::Down => playlistinfo.playlist_view_list.down(), |
| 156 | Action::FirstItem => playlistinfo.playlist_view_list.selected = 0, | 153 | Action::FirstItem => playlistinfo.playlist_view_list.first(), |
| 157 | Action::LastItem => { | 154 | Action::LastItem => playlistinfo.playlist_view_list.last(), |
| 158 | playlistinfo.playlist_view_list.selected = | ||
| 159 | playlistinfo.playlist_view_list.items.len() - 1 | ||
| 160 | } | ||
| 161 | Action::Select => { | 155 | Action::Select => { |
| 162 | let command = | 156 | let command = |
| 163 | &playlistinfo.commands[playlistinfo.playlist_view_list.selected]; | 157 | &playlistinfo.commands[playlistinfo.playlist_view_list.selected]; |
| @@ -229,11 +223,8 @@ impl ItemTrait for ItemInfoItem { | |||
| 229 | PlayListDisplayView::VideoList => match action { | 223 | PlayListDisplayView::VideoList => match action { |
| 230 | Action::Up => playlistinfo.video_view_list.up(), | 224 | Action::Up => playlistinfo.video_view_list.up(), |
| 231 | Action::Down => playlistinfo.video_view_list.down(), | 225 | Action::Down => playlistinfo.video_view_list.down(), |
| 232 | Action::FirstItem => playlistinfo.video_view_list.selected = 0, | 226 | Action::FirstItem => playlistinfo.video_view_list.first(), |
| 233 | Action::LastItem => { | 227 | Action::LastItem => playlistinfo.video_view_list.last(), |
| 234 | playlistinfo.video_view_list.selected = | ||
| 235 | playlistinfo.video_view_list.items.len() - 1 | ||
| 236 | } | ||
| 237 | Action::Select => match playlistinfo.video_view_list.selected { | 228 | Action::Select => match playlistinfo.video_view_list.selected { |
| 238 | 0 => { | 229 | 0 => { |
| 239 | playlistinfo.display_view = playlistinfo.display_view.toggle(); | 230 | playlistinfo.display_view = playlistinfo.display_view.toggle(); |
| @@ -363,24 +354,23 @@ impl ItemTrait for ItemInfoItem { | |||
| 363 | } | 354 | } |
| 364 | 355 | ||
| 365 | fn render_item<B: Backend>( | 356 | fn render_item<B: Backend>( |
| 366 | &self, | 357 | &mut self, |
| 367 | frame: &mut Frame<B>, | 358 | frame: &mut Frame<B>, |
| 368 | rect: Rect, | 359 | rect: Rect, |
| 369 | app: App, | 360 | app: App, |
| 370 | selected: bool, | 361 | selected: bool, |
| 371 | hover: bool, | 362 | hover: bool, |
| 372 | popup_focus: bool, | 363 | popup_focus: bool, |
| 373 | _: bool, | 364 | popup_render: bool, |
| 374 | ) -> (bool, Option<Item>, App) { | 365 | ) -> (bool, App) { |
| 375 | let out = (false, None, app); | 366 | let out = (false, app); |
| 367 | |||
| 368 | if popup_render { | ||
| 369 | return out; | ||
| 370 | } | ||
| 371 | |||
| 376 | match self { | 372 | match self { |
| 377 | ItemInfoItem::Video(videoinfo) => { | 373 | ItemInfoItem::Video(videoinfo) => { |
| 378 | let mut list = videoinfo.list.clone(); | ||
| 379 | |||
| 380 | list.items.iter_mut().for_each(|item| match item.as_str() { | ||
| 381 | "{mode}" => *item = format!("Mode: {}", videoinfo.mode), | ||
| 382 | _ => {} | ||
| 383 | }); | ||
| 384 | // list.items[videoinfo.list.items.len() - 1] = format!("Mode: {}", videoinfo.mode); | 374 | // list.items[videoinfo.list.items.len() - 1] = format!("Mode: {}", videoinfo.mode); |
| 385 | 375 | ||
| 386 | let split = HorizontalSplit::default() | 376 | let split = HorizontalSplit::default() |
| @@ -395,7 +385,14 @@ impl ItemTrait for ItemInfoItem { | |||
| 395 | 385 | ||
| 396 | let chunks = split.inner(rect); | 386 | let chunks = split.inner(rect); |
| 397 | 387 | ||
| 398 | list.area(chunks[1]); | 388 | videoinfo.list.area(chunks[1]); |
| 389 | |||
| 390 | let mut list = videoinfo.list.clone(); | ||
| 391 | |||
| 392 | list.items.iter_mut().for_each(|item| match item.as_str() { | ||
| 393 | "{mode}" => *item = format!("Mode: {}", videoinfo.mode), | ||
| 394 | _ => {} | ||
| 395 | }); | ||
| 399 | if selected { | 396 | if selected { |
| 400 | list.selected_style(Style::default().fg(Color::LightRed)); | 397 | list.selected_style(Style::default().fg(Color::LightRed)); |
| 401 | } else { | 398 | } else { |
| @@ -440,6 +437,7 @@ impl ItemTrait for ItemInfoItem { | |||
| 440 | 437 | ||
| 441 | match playlistinfo.display_view { | 438 | match playlistinfo.display_view { |
| 442 | PlayListDisplayView::VideoList => { | 439 | PlayListDisplayView::VideoList => { |
| 440 | playlistinfo.video_view_list.area(chunks[1]); | ||
| 443 | let mut list = playlistinfo.video_view_list.clone(); | 441 | let mut list = playlistinfo.video_view_list.clone(); |
| 444 | list.area(chunks[1]); | 442 | list.area(chunks[1]); |
| 445 | if selected { | 443 | if selected { |
| @@ -451,6 +449,7 @@ impl ItemTrait for ItemInfoItem { | |||
| 451 | frame.render_widget(list, chunks[1]); | 449 | frame.render_widget(list, chunks[1]); |
| 452 | } | 450 | } |
| 453 | PlayListDisplayView::PlayListView => { | 451 | PlayListDisplayView::PlayListView => { |
| 452 | playlistinfo.playlist_view_list.area(chunks[1]); | ||
| 454 | let mut list = playlistinfo.playlist_view_list.clone(); | 453 | let mut list = playlistinfo.playlist_view_list.clone(); |
| 455 | 454 | ||
| 456 | list.items.iter_mut().for_each(|item| match item.as_str() { | 455 | list.items.iter_mut().for_each(|item| match item.as_str() { |
| @@ -542,4 +541,4 @@ impl PageTrait for ItemInfo { | |||
| 542 | } | 541 | } |
| 543 | } | 542 | } |
| 544 | 543 | ||
| 545 | impl ItemInfoItem {}\ No newline at end of file | 544 | impl ItemInfoItem {} |
src/app/pages/main_menu.rs +17 −33
| @@ -134,23 +134,21 @@ impl ItemTrait for MainMenuItem { | |||
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | fn render_item<B: Backend>( | 136 | fn render_item<B: Backend>( |
| 137 | // &mut self, | 137 | &mut self, |
| 138 | // frame: &mut Frame<B>, | ||
| 139 | // rect: Rect, | ||
| 140 | // selected: bool, | ||
| 141 | // hover: bool, | ||
| 142 | // popup_focus: bool, | ||
| 143 | // page: &Page, | ||
| 144 | &self, | ||
| 145 | frame: &mut Frame<B>, | 138 | frame: &mut Frame<B>, |
| 146 | rect: Rect, | 139 | rect: Rect, |
| 147 | app: App, | 140 | app: App, |
| 148 | selected: bool, | 141 | selected: bool, |
| 149 | hover: bool, | 142 | hover: bool, |
| 150 | popup_focus: bool, | 143 | popup_focus: bool, |
| 151 | _: bool, | 144 | popup_render: bool, |
| 152 | ) -> (bool, Option<Item>, App) { | 145 | ) -> (bool, App) { |
| 153 | let mut out = (false, None, app); | 146 | let out = (false, app); |
| 147 | |||
| 148 | if popup_render { | ||
| 149 | return out; | ||
| 150 | } | ||
| 151 | |||
| 154 | let mut style = Style::default().fg(if selected { | 152 | let mut style = Style::default().fg(if selected { |
| 155 | Color::LightBlue | 153 | Color::LightBlue |
| 156 | } else if hover { | 154 | } else if hover { |
| @@ -161,7 +159,7 @@ impl ItemTrait for MainMenuItem { | |||
| 161 | 159 | ||
| 162 | match self { | 160 | match self { |
| 163 | MainMenuItem::SeletorTab(selector) => { | 161 | MainMenuItem::SeletorTab(selector) => { |
| 164 | if !hover && &out.2.page == &(Page::MainMenu(*selector)) { | 162 | if !hover && &out.1.page == &(Page::MainMenu(*selector)) { |
| 165 | style = style.fg(Color::LightYellow); | 163 | style = style.fg(Color::LightYellow); |
| 166 | } | 164 | } |
| 167 | let text = match selector { | 165 | let text = match selector { |
| @@ -195,17 +193,7 @@ impl ItemTrait for MainMenuItem { | |||
| 195 | 193 | ||
| 196 | frame.render_widget(split, rect); | 194 | frame.render_widget(split, rect); |
| 197 | 195 | ||
| 198 | if let Some((videos, list, index)) = data { | 196 | if let Some((videos, list, _)) = data { |
| 199 | let mut list = list.clone(); | ||
| 200 | |||
| 201 | list.area(chunks[0]); | ||
| 202 | |||
| 203 | let hold_textlist = if list.area == list.prev_area { | ||
| 204 | None | ||
| 205 | } else { | ||
| 206 | Some(list.clone()) | ||
| 207 | }; | ||
| 208 | |||
| 209 | if selected { | 197 | if selected { |
| 210 | list.selected_style(Style::default().fg(Color::LightRed)); | 198 | list.selected_style(Style::default().fg(Color::LightRed)); |
| 211 | } else { | 199 | } else { |
| @@ -218,15 +206,11 @@ impl ItemTrait for MainMenuItem { | |||
| 218 | } | 206 | } |
| 219 | } | 207 | } |
| 220 | 208 | ||
| 221 | frame.render_widget(list, chunks[0]); | 209 | list.area(chunks[0]); |
| 222 | 210 | ||
| 223 | if let Some(textlist) = hold_textlist { | 211 | let list = list.clone(); |
| 224 | out.1 = Some(Item::MainMenu(MainMenuItem::VideoList(Some(( | 212 | |
| 225 | videos.clone(), | 213 | frame.render_widget(list, chunks[0]); |
| 226 | textlist, | ||
| 227 | *index, | ||
| 228 | ))))); | ||
| 229 | } | ||
| 230 | } | 214 | } |
| 231 | } | 215 | } |
| 232 | } | 216 | } |
| @@ -263,8 +247,8 @@ impl ItemTrait for MainMenuItem { | |||
| 263 | match action { | 247 | match action { |
| 264 | Action::Up => textlist.up(), | 248 | Action::Up => textlist.up(), |
| 265 | Action::Down => textlist.down(), | 249 | Action::Down => textlist.down(), |
| 266 | Action::FirstItem => textlist.selected = 0, | 250 | Action::FirstItem => textlist.first(), |
| 267 | Action::LastItem => textlist.selected = textlist.items.len() - 1, | 251 | Action::LastItem => textlist.last(), |
| 268 | Action::Select => { | 252 | Action::Select => { |
| 269 | let state = ItemInfo::default(); | 253 | let state = ItemInfo::default(); |
| 270 | let mut history = app.history.clone(); | 254 | let mut history = app.history.clone(); |
src/app/pages/search.rs +13 −8
| @@ -49,12 +49,11 @@ impl ItemTrait for SearchItem { | |||
| 49 | None => return (false, app), | 49 | None => return (false, app), |
| 50 | }; | 50 | }; |
| 51 | match self { | 51 | match self { |
| 52 | |||
| 53 | SearchItem::Search { results, text_list } => match action { | 52 | SearchItem::Search { results, text_list } => match action { |
| 54 | Action::Up => text_list.up(), | 53 | Action::Up => text_list.up(), |
| 55 | Action::Down => text_list.down(), | 54 | Action::Down => text_list.down(), |
| 56 | Action::FirstItem => text_list.selected = 0, | 55 | Action::FirstItem => text_list.first(), |
| 57 | Action::LastItem => text_list.selected = text_list.items.len() - 1, | 56 | Action::LastItem => text_list.last(), |
| 58 | Action::Select => { | 57 | Action::Select => { |
| 59 | if let Some(results_unwrapped) = results { | 58 | if let Some(results_unwrapped) = results { |
| 60 | match results_unwrapped.iter().nth(text_list.selected).unwrap() { | 59 | match results_unwrapped.iter().nth(text_list.selected).unwrap() { |
| @@ -286,16 +285,21 @@ impl ItemTrait for SearchItem { | |||
| 286 | } | 285 | } |
| 287 | 286 | ||
| 288 | fn render_item<B: Backend>( | 287 | fn render_item<B: Backend>( |
| 289 | &self, | 288 | &mut self, |
| 290 | frame: &mut Frame<B>, | 289 | frame: &mut Frame<B>, |
| 291 | rect: Rect, | 290 | rect: Rect, |
| 292 | app: App, | 291 | app: App, |
| 293 | selected: bool, | 292 | selected: bool, |
| 294 | hover: bool, | 293 | hover: bool, |
| 295 | popup_focus: bool, | 294 | popup_focus: bool, |
| 296 | _: bool, | 295 | popup_render: bool, |
| 297 | ) -> (bool, Option<Item>, App) { | 296 | ) -> (bool, App) { |
| 298 | let out = (false, None, app); | 297 | let out = (false, app); |
| 298 | |||
| 299 | if popup_render { | ||
| 300 | return out; | ||
| 301 | } | ||
| 302 | |||
| 299 | match self { | 303 | match self { |
| 300 | SearchItem::Search { results, text_list } => { | 304 | SearchItem::Search { results, text_list } => { |
| 301 | let split = HorizontalSplit::default() | 305 | let split = HorizontalSplit::default() |
| @@ -312,9 +316,10 @@ impl ItemTrait for SearchItem { | |||
| 312 | 316 | ||
| 313 | frame.render_widget(split, rect); | 317 | frame.render_widget(split, rect); |
| 314 | 318 | ||
| 315 | let mut text_list = text_list.clone(); | ||
| 316 | text_list.area(chunks[0]); | 319 | text_list.area(chunks[0]); |
| 317 | 320 | ||
| 321 | let mut text_list = text_list.clone(); | ||
| 322 | |||
| 318 | if let Some(result) = results { | 323 | if let Some(result) = results { |
| 319 | if let Some(item) = result.iter().nth(text_list.selected) { | 324 | if let Some(item) = result.iter().nth(text_list.selected) { |
| 320 | if !popup_focus { | 325 | if !popup_focus { |
src/structs/states.rs +2 −2
| @@ -41,7 +41,7 @@ impl Item { | |||
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | pub fn render_item<B: Backend>( | 43 | pub fn render_item<B: Backend>( |
| 44 | &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: App, |
| @@ -49,7 +49,7 @@ impl Item { | |||
| 49 | hover: bool, | 49 | hover: bool, |
| 50 | popup_focus: bool, | 50 | popup_focus: bool, |
| 51 | popup_render: bool, | 51 | popup_render: bool, |
| 52 | ) -> (bool, Option<Item>, App) { | 52 | ) -> (bool, App) { |
| 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) |
src/traits/item.rs +2 −2
| @@ -10,7 +10,7 @@ use tui::{backend::Backend, layout::Rect, Frame}; | |||
| 10 | pub trait ItemTrait { | 10 | pub trait ItemTrait { |
| 11 | fn key_input(&mut self, key: KeyCode, app: App) -> (bool, App); | 11 | fn key_input(&mut self, key: KeyCode, app: App) -> (bool, App); |
| 12 | fn render_item<B: Backend>( | 12 | fn render_item<B: Backend>( |
| 13 | &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: App, |
| @@ -18,7 +18,7 @@ pub trait ItemTrait { | |||
| 18 | hover: bool, | 18 | hover: bool, |
| 19 | popup_focus: bool, | 19 | popup_focus: bool, |
| 20 | popup_render: bool, | 20 | popup_render: bool, |
| 21 | ) -> (bool, Option<Item>, App); | 21 | ) -> (bool, App); |
| 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/widgets/text_list.rs +24 −12
| @@ -15,7 +15,6 @@ pub struct TextList { | |||
| 15 | pub selected: usize, | 15 | pub selected: usize, |
| 16 | pub scroll: usize, | 16 | pub scroll: usize, |
| 17 | pub area: Option<Rect>, | 17 | pub area: Option<Rect>, |
| 18 | pub prev_area: Option<Rect>, | ||
| 19 | pub style: Style, | 18 | pub style: Style, |
| 20 | pub selected_style: Style, | 19 | pub selected_style: Style, |
| 21 | } | 20 | } |
| @@ -120,7 +119,6 @@ impl Default for TextList { | |||
| 120 | selected: 0, | 119 | selected: 0, |
| 121 | scroll: 0, | 120 | scroll: 0, |
| 122 | area: None, | 121 | area: None, |
| 123 | prev_area: None, | ||
| 124 | style: Style::default(), | 122 | style: Style::default(), |
| 125 | selected_style: Style::default().fg(Color::Yellow), | 123 | selected_style: Style::default().fg(Color::Yellow), |
| 126 | } | 124 | } |
| @@ -129,8 +127,8 @@ impl Default for TextList { | |||
| 129 | 127 | ||
| 130 | impl TextList { | 128 | impl TextList { |
| 131 | pub fn area(&mut self, area: Rect) { | 129 | pub fn area(&mut self, area: Rect) { |
| 132 | self.prev_area = self.area; | ||
| 133 | self.area = Some(area); | 130 | self.area = Some(area); |
| 131 | self.update_scroll(); | ||
| 134 | } | 132 | } |
| 135 | 133 | ||
| 136 | pub fn items(&mut self, items: Vec<String>) { | 134 | pub fn items(&mut self, items: Vec<String>) { |
| @@ -140,21 +138,35 @@ impl TextList { | |||
| 140 | pub fn down(&mut self) { | 138 | pub fn down(&mut self) { |
| 141 | if self.selected < self.items.len() - 1 { | 139 | if self.selected < self.items.len() - 1 { |
| 142 | self.selected += 1; | 140 | self.selected += 1; |
| 143 | |||
| 144 | if let Some(area) = self.area { | ||
| 145 | if self.selected > self.scroll + area.height as usize - 3 { | ||
| 146 | //panic!("Selected"); | ||
| 147 | self.scroll = self.selected + 3 - area.height as usize; | ||
| 148 | } | ||
| 149 | } | ||
| 150 | } | 141 | } |
| 142 | self.update_scroll() | ||
| 151 | } | 143 | } |
| 152 | 144 | ||
| 153 | pub fn up(&mut self) { | 145 | pub fn up(&mut self) { |
| 154 | if self.selected > 0 { | 146 | if self.selected > 0 { |
| 155 | self.selected -= 1; | 147 | self.selected -= 1; |
| 156 | if self.selected < self.scroll { | 148 | } |
| 157 | self.scroll = self.selected; | 149 | self.update_scroll(); |
| 150 | } | ||
| 151 | |||
| 152 | pub fn first(&mut self) { | ||
| 153 | self.selected = 0; | ||
| 154 | self.update_scroll(); | ||
| 155 | } | ||
| 156 | |||
| 157 | pub fn last(&mut self) { | ||
| 158 | self.selected = self.items.len() - 1; | ||
| 159 | self.update_scroll(); | ||
| 160 | } | ||
| 161 | |||
| 162 | pub fn update_scroll(&mut self) { | ||
| 163 | if self.selected < self.scroll { | ||
| 164 | self.scroll = self.selected; | ||
| 165 | } | ||
| 166 | |||
| 167 | if let Some(area) = self.area { | ||
| 168 | if self.selected > self.scroll + area.height as usize - 3 { | ||
| 169 | self.scroll = self.selected + 3 - area.height as usize; | ||
| 158 | } | 170 | } |
| 159 | } | 171 | } |
| 160 | } | 172 | } |