Commit be4224817b

be4224817b612a60266af4f70f7e6836e60d0e9c

parent: 2512b334b4

Unsigned

Siriusmart <71584876+Siriusmart@users.noreply.github.com> · 2022-06-29 19:54 UTC

Cursor out of screen fixed

Layout: unified · split

Cargo.lock +1 −1
@@ -1716,7 +1716,7 @@ dependencies = [
17161716
17171717[[package]]
17181718name = "youtube-tui"
1719version = "0.4.0"
1719version = "0.4.1"
17201720dependencies = [
17211721 "chrono",
17221722 "crossterm",
Cargo.toml +1 −1
@@ -1,6 +1,6 @@
11[package]
22name = "youtube-tui"
3version = "0.4.0"
3version = "0.4.1"
44edition = "2021"
55authors = ["Siriusmart <siriusmart@tuta.io>"]
66description = "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
1818
1919> ### What's new in this commit
2020>
21> * More code cleanup
22> * Commands to be ran in Item Info page can be changed, items can be add/removed (in `page_commands.yml`)
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)
21> * Fixed text list not scrolling with cursor bug (where the cursor just goes out of the screen)
22> * Improvements to the `render()` method
2523
2624## Installation
2725
@@ -73,10 +71,23 @@ youtube-tui # or path to the binary
7371
7472All config files are loacted at `~/.config/youtube-tui/`, will write documentations for that later
7573
74## Known issues
75
76### Missing hash key: "selected"
77
78When 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
80You should also see an error when visiting [this URL](https://vid.puffyan.us/api/v1/channels/UCAkuTH35kk3W1EL9vq6dj6A/playlists)
81
82Here's the [opened issue](https://github.com/iv-org/invidious/issues/3154)
83
7684## Todo (First piority on top)
7785
7886* Put hard coded options into config files
7987* User manual + documentations
88* Go directly to a page by URL
89* Vim-like commands in status bar
90* Command line launch options
8091* Channel search and channel video sort
8192* Recommended videos
8293
src/app/app.rs +14 −20
@@ -212,7 +212,6 @@ impl App {
212212 pub fn render<B: Backend>(mut self, frame: &mut Frame<B>) -> Self {
213213 let size = frame.size();
214214 let mut popups = Vec::new();
215 let mut modified = Vec::new();
216215
217216 let min = match self.page {
218217 Page::MainMenu(_) => MainMenu::min(),
@@ -249,11 +248,11 @@ impl App {
249248 )
250249 .split(size);
251250
252 let state = self.state.clone();
251 let mut state = self.state.clone();
253252
254253 for (y, (row, row_chunk)) in state
255 .iter()
256 .zip(vertical_chunks.clone().into_iter())
254 .iter_mut()
255 .zip(vertical_chunks.clone().iter_mut())
257256 .enumerate()
258257 {
259258 let mut constraints = LinkedList::new();
@@ -286,12 +285,15 @@ impl App {
286285 let mut chunks = Layout::default()
287286 .direction(Direction::Horizontal)
288287 .constraints(constraints.into_iter().collect::<Vec<Constraint>>())
289 .split(row_chunk)
288 .split(*row_chunk)
290289 .into_iter();
291290
292291 frame.render_widget(Block::default(), chunks.next().unwrap());
293292
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 {
295297 let selected = self.selected == Some((x, y));
296298
297299 let hover = hover_selected == Some((x, y));
@@ -300,30 +302,22 @@ impl App {
300302 let hold =
301303 item.render_item(frame, chunk, self, selected, hover, popup_focus, false);
302304
303 self = hold.2;
304
305 if let Some(item) = hold.1 {
306 modified.push((x, y, item));
307 }
305 self = hold.1;
308306
309307 if hold.0 {
310 popups.push((item, selected, hover, chunk, x, y));
308 popups.push((item, selected, hover, chunk));
311309 }
312310 }
313311 }
314312
315 for (item, selected, hover, chunk, x, y) in popups {
313 for (item, selected, hover, chunk) in popups {
316314 let hold = item.render_item(frame, chunk, self, selected, hover, true, true);
317 self = hold.2;
315 self = hold.1;
318316
319 if let Some(item) = hold.1 {
320 modified.push((x, y, item));
321 }
322317 }
323318
324 for (x, y, item) in modified {
325 self.state[y].items[x].item = item;
326 }
319 self.state = state;
320
327321 self
328322 }
329323
src/app/pages/channel.rs +22 −41
@@ -125,7 +125,7 @@ impl ItemTrait for ChannelItem {
125125 // hover: bool,
126126 // popup_focus: bool,
127127 // page: &Page,
128 &self,
128 &mut self,
129129 frame: &mut Frame<B>,
130130 rect: Rect,
131131 app: App,
@@ -133,8 +133,8 @@ impl ItemTrait for ChannelItem {
133133 hover: bool,
134134 popup_focus: bool,
135135 _: bool,
136 ) -> (bool, Option<Item>, App) {
137 let mut out = (false, None, app);
136 ) -> (bool, App) {
137 let mut out = (false, app);
138138
139139 let mut style = Style::default().fg(if selected {
140140 Color::LightBlue
@@ -184,15 +184,22 @@ impl ItemTrait for ChannelItem {
184184
185185 frame.render_widget(split, rect);
186186
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 };
188199
189200 textlist.area(chunks[0]);
190201
191 let hold_textlist = if textlist.area == textlist.prev_area {
192 None
193 } else {
194 Some(textlist.clone())
195 };
202 let mut textlist = textlist.clone();
196203
197204 if selected {
198205 textlist.selected_style(Style::default().fg(Color::LightRed));
@@ -212,12 +219,6 @@ impl ItemTrait for ChannelItem {
212219 }
213220
214221 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 }
221222 }
222223 ChannelDisplayItem::Playlists(playlists, textlist) => {
223224 let split = HorizontalSplit::default()
@@ -234,15 +235,9 @@ impl ItemTrait for ChannelItem {
234235
235236 frame.render_widget(split, rect);
236237
237 let mut textlist = textlist.clone();
238
239238 textlist.area(chunks[0]);
240239
241 let hold_textlist = if textlist.area == textlist.prev_area {
242 None
243 } else {
244 Some(textlist.clone())
245 };
240 let mut textlist = textlist.clone();
246241
247242 if selected {
248243 textlist.selected_style(Style::default().fg(Color::LightRed));
@@ -262,17 +257,11 @@ impl ItemTrait for ChannelItem {
262257 }
263258
264259 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 }
271260 }
272261 },
273262 ChannelItem::SelectItems(selected_page) => {
274263 if !hover {
275 if let Page::Channel(channel_page, _) = &out.2.page {
264 if let Page::Channel(channel_page, _) = &out.1.page {
276265 if *selected_page == *channel_page {
277266 style = style.fg(Color::LightYellow);
278267 }
@@ -308,12 +297,8 @@ impl ItemTrait for ChannelItem {
308297 Action::Down => {
309298 textlist.down();
310299 }
311 Action::FirstItem => {
312 textlist.selected = 0;
313 }
314 Action::LastItem => {
315 textlist.selected = textlist.items.len() - 1;
316 }
300 Action::FirstItem => textlist.first(),
301 Action::LastItem => textlist.last(),
317302 Action::Select => {
318303 let state = ItemInfo::default();
319304 let mut history = app.history.clone();
@@ -342,12 +327,8 @@ impl ItemTrait for ChannelItem {
342327 Action::Down => {
343328 textlist.down();
344329 }
345 Action::FirstItem => {
346 textlist.selected = 0;
347 }
348 Action::LastItem => {
349 textlist.selected = textlist.items.len() - 1;
350 }
330 Action::FirstItem => textlist.first(),
331 Action::LastItem => textlist.last(),
351332 Action::Select => {
352333 let state = ItemInfo::default();
353334 let mut history = app.history.clone();
src/app/pages/global.rs +14 −14
@@ -118,7 +118,7 @@ impl ItemTrait for GlobalItem {
118118 }
119119
120120 fn render_item<B: Backend>(
121 &self,
121 &mut self,
122122 frame: &mut Frame<B>,
123123 rect: Rect,
124124 app: App,
@@ -126,9 +126,9 @@ impl ItemTrait for GlobalItem {
126126 hover: bool,
127127 _: bool,
128128 popup_render: bool,
129 ) -> (bool, Option<Item>, App) {
129 ) -> (bool, App) {
130130 let area = frame.size();
131 let mut out = (false, None, app);
131 let mut out = (false, app);
132132 match self {
133133 GlobalItem::SearchBar => {
134134 let block = Block::default()
@@ -143,7 +143,7 @@ impl ItemTrait for GlobalItem {
143143 }))
144144 .title("Search YouTube")
145145 .title_alignment(Alignment::Center);
146 let mut text = out.2.search_text.clone();
146 let mut text = out.1.search_text.clone();
147147 if selected {
148148 text.push('█');
149149 }
@@ -151,7 +151,7 @@ impl ItemTrait for GlobalItem {
151151 frame.render_widget(paragraph, rect);
152152 }
153153 GlobalItem::MessageBar => {
154 let message = out.2.message.lock().unwrap();
154 let message = out.1.message.lock().unwrap();
155155 // let color = Color::LightYellow;
156156 let block = Block::default()
157157 .border_type(BorderType::Rounded)
@@ -197,39 +197,39 @@ impl ItemTrait for GlobalItem {
197197
198198 frame.render_widget(split, rect);
199199
200 out.2.search_settings.text_list.area(chunks[0]);
200 out.1.search_settings.text_list.area(chunks[0]);
201201
202 if out.2.search_settings.row {
203 out.2
202 if out.1.search_settings.row {
203 out.1
204204 .search_settings
205205 .text_list
206206 .selected_style(Style::default().fg(Color::LightRed));
207207
208 out.2
208 out.1
209209 .search_settings
210210 .select_text_list
211211 .selected_style(Style::default().fg(Color::LightYellow));
212212 } else {
213 out.2
213 out.1
214214 .search_settings
215215 .text_list
216216 .selected_style(Style::default().fg(Color::LightYellow));
217217
218 out.2
218 out.1
219219 .search_settings
220220 .select_text_list
221221 .selected_style(Style::default().fg(Color::LightRed));
222222 }
223223
224224 frame.render_widget(
225 out.2.search_settings.text_list.clone(),
225 out.1.search_settings.text_list.clone(),
226226 chunks[0],
227227 );
228228
229 out.2.search_settings.select_text_list.area(chunks[1]);
229 out.1.search_settings.select_text_list.area(chunks[1]);
230230
231231 frame.render_widget(
232 out.2.search_settings.select_text_list.clone(),
232 out.1.search_settings.select_text_list.clone(),
233233 chunks[1],
234234 );
235235
src/app/pages/item_info.rs +27 −28
@@ -1,7 +1,4 @@
1use std::{
2 collections::LinkedList,
3 error::Error,
4};
1use std::{collections::LinkedList, error::Error};
52
63use crate::{
74 app::{
@@ -84,8 +81,8 @@ impl ItemTrait for ItemInfoItem {
8481 ItemInfoItem::Video(videoinfo) => match action {
8582 Action::Up => videoinfo.list.up(),
8683 Action::Down => videoinfo.list.down(),
87 Action::FirstItem => videoinfo.list.selected = 0,
88 Action::LastItem => videoinfo.list.selected = videoinfo.list.items.len() - 1,
84 Action::FirstItem => videoinfo.list.first(),
85 Action::LastItem => videoinfo.list.last(),
8986 Action::Select => {
9087 let command = &videoinfo.commands[videoinfo.list.selected];
9188
@@ -153,11 +150,8 @@ impl ItemTrait for ItemInfoItem {
153150 PlayListDisplayView::PlayListView => match action {
154151 Action::Up => playlistinfo.playlist_view_list.up(),
155152 Action::Down => playlistinfo.playlist_view_list.down(),
156 Action::FirstItem => playlistinfo.playlist_view_list.selected = 0,
157 Action::LastItem => {
158 playlistinfo.playlist_view_list.selected =
159 playlistinfo.playlist_view_list.items.len() - 1
160 }
153 Action::FirstItem => playlistinfo.playlist_view_list.first(),
154 Action::LastItem => playlistinfo.playlist_view_list.last(),
161155 Action::Select => {
162156 let command =
163157 &playlistinfo.commands[playlistinfo.playlist_view_list.selected];
@@ -229,11 +223,8 @@ impl ItemTrait for ItemInfoItem {
229223 PlayListDisplayView::VideoList => match action {
230224 Action::Up => playlistinfo.video_view_list.up(),
231225 Action::Down => playlistinfo.video_view_list.down(),
232 Action::FirstItem => playlistinfo.video_view_list.selected = 0,
233 Action::LastItem => {
234 playlistinfo.video_view_list.selected =
235 playlistinfo.video_view_list.items.len() - 1
236 }
226 Action::FirstItem => playlistinfo.video_view_list.first(),
227 Action::LastItem => playlistinfo.video_view_list.last(),
237228 Action::Select => match playlistinfo.video_view_list.selected {
238229 0 => {
239230 playlistinfo.display_view = playlistinfo.display_view.toggle();
@@ -363,24 +354,23 @@ impl ItemTrait for ItemInfoItem {
363354 }
364355
365356 fn render_item<B: Backend>(
366 &self,
357 &mut self,
367358 frame: &mut Frame<B>,
368359 rect: Rect,
369360 app: App,
370361 selected: bool,
371362 hover: bool,
372363 popup_focus: bool,
373 _: bool,
374 ) -> (bool, Option<Item>, App) {
375 let out = (false, None, app);
364 popup_render: bool,
365 ) -> (bool, App) {
366 let out = (false, app);
367
368 if popup_render {
369 return out;
370 }
371
376372 match self {
377373 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 });
384374 // list.items[videoinfo.list.items.len() - 1] = format!("Mode: {}", videoinfo.mode);
385375
386376 let split = HorizontalSplit::default()
@@ -395,7 +385,14 @@ impl ItemTrait for ItemInfoItem {
395385
396386 let chunks = split.inner(rect);
397387
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 });
399396 if selected {
400397 list.selected_style(Style::default().fg(Color::LightRed));
401398 } else {
@@ -440,6 +437,7 @@ impl ItemTrait for ItemInfoItem {
440437
441438 match playlistinfo.display_view {
442439 PlayListDisplayView::VideoList => {
440 playlistinfo.video_view_list.area(chunks[1]);
443441 let mut list = playlistinfo.video_view_list.clone();
444442 list.area(chunks[1]);
445443 if selected {
@@ -451,6 +449,7 @@ impl ItemTrait for ItemInfoItem {
451449 frame.render_widget(list, chunks[1]);
452450 }
453451 PlayListDisplayView::PlayListView => {
452 playlistinfo.playlist_view_list.area(chunks[1]);
454453 let mut list = playlistinfo.playlist_view_list.clone();
455454
456455 list.items.iter_mut().for_each(|item| match item.as_str() {
@@ -542,4 +541,4 @@ impl PageTrait for ItemInfo {
542541 }
543542}
544543
545impl ItemInfoItem {}
\ No newline at end of file
544impl ItemInfoItem {}
src/app/pages/main_menu.rs +17 −33
@@ -134,23 +134,21 @@ impl ItemTrait for MainMenuItem {
134134 }
135135
136136 fn render_item<B: Backend>(
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,
137 &mut self,
145138 frame: &mut Frame<B>,
146139 rect: Rect,
147140 app: App,
148141 selected: bool,
149142 hover: bool,
150143 popup_focus: bool,
151 _: bool,
152 ) -> (bool, Option<Item>, App) {
153 let mut out = (false, None, app);
144 popup_render: bool,
145 ) -> (bool, App) {
146 let out = (false, app);
147
148 if popup_render {
149 return out;
150 }
151
154152 let mut style = Style::default().fg(if selected {
155153 Color::LightBlue
156154 } else if hover {
@@ -161,7 +159,7 @@ impl ItemTrait for MainMenuItem {
161159
162160 match self {
163161 MainMenuItem::SeletorTab(selector) => {
164 if !hover && &out.2.page == &(Page::MainMenu(*selector)) {
162 if !hover && &out.1.page == &(Page::MainMenu(*selector)) {
165163 style = style.fg(Color::LightYellow);
166164 }
167165 let text = match selector {
@@ -195,17 +193,7 @@ impl ItemTrait for MainMenuItem {
195193
196194 frame.render_widget(split, rect);
197195
198 if let Some((videos, list, index)) = 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
196 if let Some((videos, list, _)) = data {
209197 if selected {
210198 list.selected_style(Style::default().fg(Color::LightRed));
211199 } else {
@@ -218,15 +206,11 @@ impl ItemTrait for MainMenuItem {
218206 }
219207 }
220208
221 frame.render_widget(list, chunks[0]);
209 list.area(chunks[0]);
222210
223 if let Some(textlist) = hold_textlist {
224 out.1 = Some(Item::MainMenu(MainMenuItem::VideoList(Some((
225 videos.clone(),
226 textlist,
227 *index,
228 )))));
229 }
211 let list = list.clone();
212
213 frame.render_widget(list, chunks[0]);
230214 }
231215 }
232216 }
@@ -263,8 +247,8 @@ impl ItemTrait for MainMenuItem {
263247 match action {
264248 Action::Up => textlist.up(),
265249 Action::Down => textlist.down(),
266 Action::FirstItem => textlist.selected = 0,
267 Action::LastItem => textlist.selected = textlist.items.len() - 1,
250 Action::FirstItem => textlist.first(),
251 Action::LastItem => textlist.last(),
268252 Action::Select => {
269253 let state = ItemInfo::default();
270254 let mut history = app.history.clone();
src/app/pages/search.rs +13 −8
@@ -49,12 +49,11 @@ impl ItemTrait for SearchItem {
4949 None => return (false, app),
5050 };
5151 match self {
52
5352 SearchItem::Search { results, text_list } => match action {
5453 Action::Up => text_list.up(),
5554 Action::Down => text_list.down(),
56 Action::FirstItem => text_list.selected = 0,
57 Action::LastItem => text_list.selected = text_list.items.len() - 1,
55 Action::FirstItem => text_list.first(),
56 Action::LastItem => text_list.last(),
5857 Action::Select => {
5958 if let Some(results_unwrapped) = results {
6059 match results_unwrapped.iter().nth(text_list.selected).unwrap() {
@@ -286,16 +285,21 @@ impl ItemTrait for SearchItem {
286285 }
287286
288287 fn render_item<B: Backend>(
289 &self,
288 &mut self,
290289 frame: &mut Frame<B>,
291290 rect: Rect,
292291 app: App,
293292 selected: bool,
294293 hover: bool,
295294 popup_focus: bool,
296 _: bool,
297 ) -> (bool, Option<Item>, App) {
298 let out = (false, None, app);
295 popup_render: bool,
296 ) -> (bool, App) {
297 let out = (false, app);
298
299 if popup_render {
300 return out;
301 }
302
299303 match self {
300304 SearchItem::Search { results, text_list } => {
301305 let split = HorizontalSplit::default()
@@ -312,9 +316,10 @@ impl ItemTrait for SearchItem {
312316
313317 frame.render_widget(split, rect);
314318
315 let mut text_list = text_list.clone();
316319 text_list.area(chunks[0]);
317320
321 let mut text_list = text_list.clone();
322
318323 if let Some(result) = results {
319324 if let Some(item) = result.iter().nth(text_list.selected) {
320325 if !popup_focus {
src/structs/states.rs +2 −2
@@ -41,7 +41,7 @@ impl Item {
4141 }
4242
4343 pub fn render_item<B: Backend>(
44 &self,
44 &mut self,
4545 frame: &mut Frame<B>,
4646 rect: Rect,
4747 app: App,
@@ -49,7 +49,7 @@ impl Item {
4949 hover: bool,
5050 popup_focus: bool,
5151 popup_render: bool,
52 ) -> (bool, Option<Item>, App) {
52 ) -> (bool, App) {
5353 match self {
5454 Item::Global(item) => {
5555 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};
1010pub trait ItemTrait {
1111 fn key_input(&mut self, key: KeyCode, app: App) -> (bool, App);
1212 fn render_item<B: Backend>(
13 &self,
13 &mut self,
1414 frame: &mut Frame<B>,
1515 rect: Rect,
1616 app: App,
@@ -18,7 +18,7 @@ pub trait ItemTrait {
1818 hover: bool,
1919 popup_focus: bool,
2020 popup_render: bool,
21 ) -> (bool, Option<Item>, App);
21 ) -> (bool, App);
2222 fn select(&mut self, app: App) -> (App, bool);
2323 fn selectable(&self) -> bool;
2424 fn load_item(
src/widgets/text_list.rs +24 −12
@@ -15,7 +15,6 @@ pub struct TextList {
1515 pub selected: usize,
1616 pub scroll: usize,
1717 pub area: Option<Rect>,
18 pub prev_area: Option<Rect>,
1918 pub style: Style,
2019 pub selected_style: Style,
2120}
@@ -120,7 +119,6 @@ impl Default for TextList {
120119 selected: 0,
121120 scroll: 0,
122121 area: None,
123 prev_area: None,
124122 style: Style::default(),
125123 selected_style: Style::default().fg(Color::Yellow),
126124 }
@@ -129,8 +127,8 @@ impl Default for TextList {
129127
130128impl TextList {
131129 pub fn area(&mut self, area: Rect) {
132 self.prev_area = self.area;
133130 self.area = Some(area);
131 self.update_scroll();
134132 }
135133
136134 pub fn items(&mut self, items: Vec<String>) {
@@ -140,21 +138,35 @@ impl TextList {
140138 pub fn down(&mut self) {
141139 if self.selected < self.items.len() - 1 {
142140 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 }
150141 }
142 self.update_scroll()
151143 }
152144
153145 pub fn up(&mut self) {
154146 if self.selected > 0 {
155147 self.selected -= 1;
156 if self.selected < self.scroll {
157 self.scroll = self.selected;
148 }
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;
158170 }
159171 }
160172 }