Commit ddb15ba639

ddb15ba639bedeb51a949e00019f20823aae8c6b

parent: 4cc2206d3e

Unsigned

Siriusmart <71584876+Siriusmart@users.noreply.github.com> · 2022-07-14 18:00 UTC

v0.4.4

Layout: unified · split

Cargo.lock +1 −1
@@ -1716,7 +1716,7 @@ dependencies = [
17161716
17171717[[package]]
17181718name = "youtube-tui"
1719version = "0.4.2"
1719version = "0.4.4"
17201720dependencies = [
17211721 "chrono",
17221722 "crossterm",
Cargo.toml +1 −1
@@ -1,6 +1,6 @@
11[package]
22name = "youtube-tui"
3version = "0.4.3"
3version = "0.4.4"
44edition = "2021"
55authors = ["Siriusmart <siriusmart@tuta.io>"]
66description = "An aesthetically pleasing YouTube TUI written in Rust"
README.md +11 −8
@@ -20,13 +20,17 @@ This program is being actively developed and there will be new features coming u
2020
2121[YouTube TUI user manual](https://siriusmart.github.io/youtube-tui)
2222
23> ### What's new in this commit
24>
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
23## Chnagelogs
24
25#### Added
26
27* Added default select item for each page (can be changed in `layouts.yml`)
28
29#### Fixes
2930
31* Video list view in playlists not working
32* Channel view scroll causes panic
33* Search options gray backgound + image covering popup
3034
3135## Installation
3236
@@ -91,10 +95,9 @@ Here's the [opened issue](https://github.com/iv-org/invidious/issues/3154)
9195
9296## Todo (First piority on top)
9397
94* Put hard coded options into config files
95* User manual + documentations
9698* Go directly to a page by URL
9799* Vim-like commands in status bar
100* Save as local playlist/video
98101* Command line launch options
99102* Channel search and channel video sort
100103* Recommended videos
src/app/app.rs +43 −7
@@ -1,7 +1,7 @@
11use std::collections::LinkedList;
22
33use crate::{
4 structs::{AppHistory, Item, Page, SearchSettings, State, WatchHistory},
4 structs::{AppHistory, Item, Page, SearchSettings, State, WatchHistory, MessageText},
55 traits::ItemTrait,
66};
77use crossterm::event::KeyEvent;
@@ -14,7 +14,7 @@ use tui::{
1414 Frame,
1515};
1616
17use super::config::{Action, Config};
17use super::config::{Action, Config, LayoutConfig};
1818
1919#[derive(Clone)]
2020pub struct App {
@@ -25,7 +25,7 @@ pub struct App {
2525 pub hover: Option<(usize, usize)>, // x, y
2626 pub selected: Option<(usize, usize)>,
2727 pub client: Client,
28 pub message: Option<String>,
28 pub message: MessageText,
2929 pub load: bool,
3030 pub render: bool,
3131 pub popup_focus: bool,
@@ -35,6 +35,7 @@ pub struct App {
3535 pub search_text: String,
3636 pub search_index: usize,
3737 pub page_no: usize,
38 pub term_clear: bool,
3839}
3940
4041pub struct AppNoState {
@@ -44,7 +45,7 @@ pub struct AppNoState {
4445 pub hover: Option<(usize, usize)>, // x, y
4546 pub selected: Option<(usize, usize)>,
4647 pub client: Client,
47 pub message: Option<String>,
48 pub message: MessageText,
4849 pub load: bool,
4950 pub render: bool,
5051 pub popup_focus: bool,
@@ -54,6 +55,7 @@ pub struct AppNoState {
5455 pub search_text: String,
5556 pub search_index: usize,
5657 pub page_no: usize,
58 pub term_clear: bool,
5759}
5860
5961impl AppNoState {
@@ -75,6 +77,7 @@ impl AppNoState {
7577 search_text: app.search_text,
7678 search_index: app.search_index,
7779 page_no: app.page_no,
80 term_clear: app.term_clear,
7881 };
7982 (out, app.state)
8083 }
@@ -98,6 +101,7 @@ impl AppNoState {
98101 search_index: app.search_index,
99102 page_no: app.page_no,
100103 state,
104 term_clear: app.term_clear,
101105 }
102106 }
103107}
@@ -114,7 +118,7 @@ impl Default for App {
114118 client: Client::new(config.main.server_url.clone()),
115119 selected: None,
116120 hover: None,
117 message: None,
121 message: MessageText::None,
118122 load: true,
119123 render: true,
120124 popup_focus: false,
@@ -125,6 +129,7 @@ impl Default for App {
125129 search_text: String::new(),
126130 search_index: 0,
127131 page_no: 1,
132 term_clear: false,
128133 }
129134 }
130135}
@@ -179,6 +184,7 @@ impl App {
179184 Action::Refresh => {
180185 self.state.reset();
181186 self.load = true;
187 self.render = true;
182188 }
183189 Action::Select => {
184190 if self.hover.is_some() && self.selected.is_none() {
@@ -199,6 +205,8 @@ impl App {
199205 self.selected = Some((x, y));
200206 }
201207
208 self.render = true;
209
202210 return self;
203211 }
204212 }
@@ -206,6 +214,7 @@ impl App {
206214 if self.selected.is_some() {
207215 self.selected = None;
208216 self.popup_focus = false;
217 self.render = true;
209218 return self;
210219 }
211220 }
@@ -217,6 +226,7 @@ impl App {
217226 Some((x, y)) => match action {
218227 Action::Up => {
219228 if *y > 0 {
229 self.render = true;
220230 let temp_y = *y - 1;
221231 if *x > self.selectable[temp_y].len() {
222232 let temp_x = self.selectable[temp_y].len();
@@ -232,6 +242,7 @@ impl App {
232242 }
233243 Action::Down => {
234244 if *y < self.selectable.len() - 1 {
245 self.render = true;
235246 *y += 1;
236247 if *x > self.selectable[*y].len() - 1 {
237248 *x = self.selectable[*y].len() - 1;
@@ -241,12 +252,14 @@ impl App {
241252
242253 Action::Left => {
243254 if *x > 0 {
255 self.render = true;
244256 *x -= 1;
245257 }
246258 }
247259
248260 Action::Right => {
249261 if *x < self.selectable[*y].len() - 1 {
262 self.render = true;
250263 *x += 1;
251264 }
252265 }
@@ -255,15 +268,19 @@ impl App {
255268 },
256269 None => match action {
257270 Action::Up => {
271 self.render = true;
258272 self.hover = Some((0, 0));
259273 }
260274 Action::Down => {
275 self.render = true;
261276 self.hover = Some((0, self.selectable.len() - 1));
262277 }
263278 Action::Left => {
279 self.render = true;
264280 self.hover = Some((0, 0));
265281 }
266282 Action::Right => {
283 self.render = true;
267284 self.hover = Some((0, self.selectable.len() - 1));
268285 }
269286 _ => {}
@@ -351,6 +368,7 @@ impl App {
351368
352369 frame.render_widget(Block::default(), chunks.next().unwrap());
353370
371 let popup_focus = app.popup_focus;
354372 for (x, (chunk, item)) in chunks
355373 .zip(row.items.iter_mut().map(|i| &mut i.item))
356374 .enumerate()
@@ -358,7 +376,6 @@ impl App {
358376 let selected = app.selected == Some((x, y));
359377
360378 let hover = hover_selected == Some((x, y));
361 let popup_focus = app.popup_focus;
362379
363380 let hold = item.render_item(frame, chunk, app, selected, hover, popup_focus, false);
364381
@@ -381,7 +398,7 @@ impl App {
381398
382399 pub fn pop(mut self) -> (App, bool) {
383400 if self.history.len() == 0 {
384 self.message = Some(String::from("This is the beginning of history"));
401 self.message = MessageText::Text(String::from("This is the beginning of history"));
385402 return (self, false);
386403 }
387404
@@ -405,6 +422,7 @@ impl App {
405422 search_text: app_history.search_text,
406423 search_index: app_history.search_index,
407424 page_no: app_history.page_no,
425 term_clear: false,
408426 };
409427
410428 (self, true)
@@ -413,4 +431,22 @@ impl App {
413431 pub fn home(&mut self) {
414432 *self = App::default();
415433 }
434
435 pub fn page_layout(&self) -> LayoutConfig {
436 match self.page {
437 Page::Search => self.config.layouts.search.clone(),
438 Page::MainMenu(_) => self.config.layouts.main_menu.clone(),
439 Page::ItemDisplay(_) => self.config.layouts.item_info.clone(),
440 Page::Channel(_, _) => self.config.layouts.channel.clone(),
441 }
442 }
443
444 pub fn page_default(&self) -> Option<(usize, usize)> {
445 match self.page {
446 Page::Search => self.config.layouts.search.def_selected,
447 Page::MainMenu(_) => self.config.layouts.main_menu.def_selected,
448 Page::ItemDisplay(_) => self.config.layouts.item_info.def_selected,
449 Page::Channel(_, _) => self.config.layouts.channel.def_selected,
450 }
451 }
416452}
src/app/config/layouts.rs +1
@@ -62,6 +62,7 @@ pub struct LayoutConfig {
6262 pub layout: Vec<RowTransitional>,
6363 pub min: (u16, u16),
6464 pub message: String,
65 pub def_selected: Option<(usize, usize)>,
6566}
6667
6768impl Into<State> for LayoutConfig {
src/app/config/main.rs +1 −1
@@ -8,7 +8,7 @@ fn max_watch_history_default() -> usize {
88}
99
1010fn server_url_default() -> String {
11 String::from("https://vid.puffyan.us")
11 String::from("https://invidious.flokinet.to")
1212}
1313
1414fn env_default() -> HashMap<String, String> {
src/app/pages/channel.rs +10 −3
@@ -133,7 +133,7 @@ impl ItemTrait for ChannelItem {
133133 selected: bool,
134134 hover: bool,
135135 popup_focus: bool,
136 _: bool,
136 popup_render: bool,
137137 ) -> (bool, AppNoState) {
138138 let mut out = (false, app);
139139
@@ -163,12 +163,15 @@ impl ItemTrait for ChannelItem {
163163
164164 let inner = block.inner(rect);
165165 frame.render_widget(block, rect);
166 if !popup_render {
166167 frame.render_widget(
167168 ItemDisplay {
168169 item: ListItem::FullChannel(channel.clone()),
170 render_image: !popup_focus,
169171 },
170172 inner,
171173 );
174 }
172175 }
173176 ChannelDisplayItem::Videos(videos, textlist) => {
174177 let split = HorizontalSplit::default()
@@ -209,10 +212,11 @@ impl ItemTrait for ChannelItem {
209212 }
210213
211214 if let Some(item) = videos.iter().nth(textlist.selected) {
212 if !popup_focus {
215 if !popup_render {
213216 frame.render_widget(
214217 ItemDisplay {
215218 item: ListItem::MiniVideo(item.clone()),
219 render_image: !popup_focus,
216220 },
217221 chunks[1],
218222 );
@@ -251,6 +255,7 @@ impl ItemTrait for ChannelItem {
251255 frame.render_widget(
252256 ItemDisplay {
253257 item: ListItem::MiniPlayList(item.clone()),
258 render_image: !popup_focus,
254259 },
255260 chunks[1],
256261 );
@@ -351,8 +356,9 @@ impl ItemTrait for ChannelItem {
351356 _ => {}
352357 },
353358
359 ChannelDisplayItem::Home(_) => {},
354360 _ => unreachable!(),
355 },
361 },
356362 _ => {
357363 unreachable!()
358364 }
@@ -460,6 +466,7 @@ impl PageTrait for Channel {
460466 ],
461467 min: (46, 15),
462468 message: String::from("Loading channel info..."),
469 def_selected: None,
463470 }
464471 }
465472}
src/app/pages/global.rs +17 −11
@@ -6,16 +6,16 @@ use tui::{
66 backend::Backend,
77 layout::{Alignment, Rect},
88 style::{Color, Style},
9 widgets::{Block, BorderType, Borders, Clear, Paragraph},
9 widgets::{Block, BorderType, Borders, Paragraph, Clear},
1010 Frame,
1111};
1212
1313use crate::{
1414 app::app::{App, AppNoState},
1515 functions::center_rect,
16 structs::{Item, Page, WatchHistory},
16 structs::{Item, Page, WatchHistory, MessageText},
1717 traits::ItemTrait,
18 widgets::{force_clear::ForceClear, horizontal_split::HorizontalSplit},
18 widgets::{ horizontal_split::HorizontalSplit},
1919};
2020
2121#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -55,9 +55,10 @@ impl ItemTrait for GlobalItem {
5555 GlobalItem::SearchBar => true,
5656 GlobalItem::SearchSettings => {
5757 app.popup_focus = true;
58 app.term_clear = true;
5859 true
5960 }
60 _ => false,
61 GlobalItem::MessageBar => unreachable!()
6162 };
6263
6364 (app, selected)
@@ -74,11 +75,13 @@ impl ItemTrait for GlobalItem {
7475 match self {
7576 GlobalItem::SearchBar => match key.code {
7677 KeyCode::Char(c) => {
78 app.render = true;
7779 app.search_text.insert(app.search_index, c);
7880 app.search_index += 1;
7981 }
8082 KeyCode::Backspace => {
8183 if app.search_index != 0 && app.search_text.len() != 0 {
84 app.render = true;
8285 app.search_text = format!(
8386 "{}{}",
8487 &app.search_text[0..app.search_index - 1],
@@ -89,17 +92,20 @@ impl ItemTrait for GlobalItem {
8992 }
9093 KeyCode::Left => {
9194 if app.search_index > 0 {
95 app.render = true;
9296 app.search_index -= 1;
9397 }
9498 }
9599 KeyCode::Right => {
96100 if app.search_index < app.search_text.len() {
101 app.render = true;
97102 app.search_index += 1;
98103 }
99104 }
100105 KeyCode::Enter => {
106 app.render = true;
101107 if app.search_text.len() == 0 {
102 app.message = Some(String::from("Search term cannot be empty"));
108 app.message = MessageText::Text(String::from("Search term cannot be empty"));
103109 } else {
104110 let state = app.config.layouts.search.clone().into();
105111 let mut history = app.history.clone();
@@ -181,7 +187,7 @@ impl ItemTrait for GlobalItem {
181187 Color::Reset
182188 }));
183189 let paragraph =
184 Paragraph::new(message.clone().unwrap_or(String::from("All good :)")))
190 Paragraph::new(message.clone().to_string())
185191 .block(block);
186192 frame.render_widget(paragraph, rect);
187193 }
@@ -240,6 +246,9 @@ impl ItemTrait for GlobalItem {
240246 .selected_style(Style::default().fg(Color::LightRed));
241247 }
242248
249 frame.render_widget(Clear, chunks[0]);
250 frame.render_widget(Clear, chunks[1]);
251
243252 frame.render_widget(
244253 out.1.search_settings.text_list.clone(),
245254 chunks[0],
@@ -252,12 +261,9 @@ impl ItemTrait for GlobalItem {
252261 chunks[1],
253262 );
254263
255 frame.render_widget(ForceClear, chunks[0]);
256
257 frame.render_widget(ForceClear, chunks[1]);
258264 }
259 Err(rect) => {
260 frame.render_widget(Clear, rect);
265 Err(_) => {
266 out.1.message = MessageText::Text(String::from("Screen too small"));
261267 }
262268 }
263269 //panic!("{:?}", rect);
src/app/pages/item_info.rs +14 −10
@@ -10,7 +10,7 @@ use crate::{
1010 pages::{channel::*, global::*},
1111 },
1212 functions::download_all_thumbnails,
13 structs::{FullPlayList, FullVideo, Item, ListItem, Page, WatchHistory},
13 structs::{FullPlayList, FullVideo, Item, ListItem, Page, WatchHistory, MessageText},
1414 traits::{ItemTrait, PageTrait},
1515 widgets::{horizontal_split::HorizontalSplit, item_display::ItemDisplay, text_list::TextList},
1616};
@@ -133,14 +133,14 @@ impl ItemTrait for ItemInfoItem {
133133
134134 match command.run_command(&env) {
135135 Some(e) => {
136 app.message = Some(format!("Unknown variable `{}`", e))
136 app.message = MessageText::Text(format!("Unknown variable `{}`", e))
137137 }
138 None => app.message = Some(command.message.clone()),
138 None => app.message = MessageText::Text(command.message.clone()),
139139 }
140140 }
141141 None => {
142142 app.message =
143 Some(format!("Unkown command `{}`", &command.command));
143 MessageText::Text(format!("Unkown command `{}`", &command.command));
144144 }
145145 };
146146 }
@@ -204,14 +204,14 @@ impl ItemTrait for ItemInfoItem {
204204 match command.run_command(&env) {
205205 Some(e) => {
206206 app.message =
207 Some(format!("Unknown variable `{}`", e))
207 MessageText::Text(format!("Unknown variable `{}`", e))
208208 }
209 None => app.message = Some(command.message.clone()),
209 None => app.message = MessageText::Text(command.message.clone()),
210210 }
211211 }
212212 None => {
213213 app.message =
214 Some(format!("Unkown command `{}`", &command.command));
214 MessageText::Text(format!("Unkown command `{}`", &command.command));
215215 }
216216 };
217217 }
@@ -231,7 +231,7 @@ impl ItemTrait for ItemInfoItem {
231231 }
232232
233233 x => {
234 let state = app.config.layouts.channel.clone().into();
234 let state = app.config.layouts.item_info.clone().into();
235235 let mut history = app.history.clone();
236236 history.push(app.into());
237237
@@ -270,6 +270,7 @@ impl ItemTrait for ItemInfoItem {
270270 match &app.page {
271271 Page::ItemDisplay(display_item) => match display_item {
272272 DisplayItem::Video(id) => {
273 // panic!("Got here");
273274 let mut list = TextList::default();
274275 let video: FullVideo = app.client.video(id, None)?.into();
275276 if app.config.main.display_thumbnails {
@@ -405,9 +406,10 @@ impl ItemTrait for ItemInfoItem {
405406
406407 frame.render_widget(split, rect);
407408
408 if !popup_focus {
409 if !popup_render {
409410 let item_display = ItemDisplay {
410411 item: ListItem::FullVideo(videoinfo.video.clone()),
412 render_image: !popup_focus,
411413 };
412414
413415 frame.render_widget(item_display, chunks[0]);
@@ -431,9 +433,10 @@ impl ItemTrait for ItemInfoItem {
431433
432434 frame.render_widget(split, rect);
433435
434 if !popup_focus {
436 if !popup_render {
435437 let item_display = ItemDisplay {
436438 item: ListItem::FullPlayList(playlistinfo.playlist.clone()),
439 render_image: !popup_focus,
437440 };
438441
439442 frame.render_widget(item_display, chunks[0]);
@@ -536,6 +539,7 @@ impl PageTrait for ItemInfo {
536539 ],
537540 min: (21, 12),
538541 message: String::from("Loading item info..."),
542 def_selected: Some((0,1)),
539543 }
540544 }
541545}
src/app/pages/main_menu.rs +3 −2
@@ -209,8 +209,8 @@ impl ItemTrait for MainMenuItem {
209209 }
210210
211211 if let Some(item) = videos.iter().nth(list.selected) {
212 if !popup_focus {
213 frame.render_widget(ItemDisplay { item: item.clone() }, chunks[1]);
212 if !popup_render {
213 frame.render_widget(ItemDisplay { item: item.clone(), render_image: !popup_focus }, chunks[1]);
214214 }
215215 }
216216
@@ -387,6 +387,7 @@ impl PageTrait for MainMenu {
387387 ],
388388 min: (45, 15),
389389 message: String::from("Loading home page..."),
390 def_selected: None,
390391 }
391392 }
392393}
src/app/pages/search.rs +3 −2
@@ -324,8 +324,8 @@ impl ItemTrait for SearchItem {
324324
325325 if let Some(result) = results {
326326 if let Some(item) = result.iter().nth(text_list.selected) {
327 if !popup_focus {
328 frame.render_widget(ItemDisplay { item: item.clone() }, chunks[1]);
327 if !popup_render {
328 frame.render_widget(ItemDisplay { item: item.clone(), render_image: !popup_focus }, chunks[1]);
329329 }
330330 }
331331 }
@@ -383,6 +383,7 @@ impl PageTrait for Search {
383383 ],
384384 min: (45, 12),
385385 message: String::from("Loading search results..."),
386 def_selected: Some((0,1)),
386387 }
387388 }
388389}
src/main.rs +15 −4
@@ -10,7 +10,7 @@ use tui::{
1010};
1111use youtube_tui::{
1212 app::{app::App, config::Action},
13 structs::{Row, RowItem, State},
13 structs::{Row, RowItem, State, MessageText},
1414};
1515
1616fn main() -> Result<(), Box<dyn Error>> {
@@ -42,13 +42,17 @@ fn main() -> Result<(), Box<dyn Error>> {
4242fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<(), Box<dyn Error>> {
4343 loop {
4444 if app.render {
45 if app.term_clear {
46 terminal.clear()?;
47 app.term_clear = false;
48 }
4549 let hold = ui(&mut terminal, app);
4650 app = hold.0;
4751 hold.1?;
4852 }
4953
5054 if app.load {
51 app.message = Some(app.page.message(&app.config));
55 app.message = MessageText::Text(app.page.message(&app.config));
5256 let mut watch_history = app.watch_history.clone();
5357 terminal.clear()?;
5458 let hold = ui(&mut terminal, app);
@@ -70,7 +74,7 @@ fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<(
7074 item: row_item.item.clone(),
7175 ..*row_item
7276 });
73 app.message = Some(e.to_string());
77 app.message = MessageText::Text(e.to_string());
7478 }
7579 }
7680 }
@@ -83,11 +87,18 @@ fn run_app<B: Backend>(mut terminal: &mut Terminal<B>, mut app: App) -> Result<(
8387
8488 app.watch_history = watch_history;
8589 app.state = State(new_state);
90 app.selectable = App::selectable(&app.state);
8691
8792 app.load = false;
8893 terminal.clear()?;
8994 let hold = ui(&mut terminal, app);
9095 app = hold.0;
96
97 let selected = app.page_default();
98
99 app.selected = selected;
100 app.hover = selected;
101 app.render = true;
91102 } else {
92103 match event::read()? {
93104 event::Event::Key(key) => {
@@ -143,7 +154,7 @@ fn ui<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> (App, Result<(),
143154
144155 app = recv.recv().unwrap();
145156
146 app.message = None;
157 app.message = MessageText::None;
147158 app.render = false;
148159
149160 match res {
src/structs/apphistory.rs +3 −3
@@ -2,7 +2,7 @@ use invidious::blocking::Client;
22
33use crate::{app::app::App, structs::Page};
44
5use super::{SearchSettings, State};
5use super::{SearchSettings, State, MessageText};
66
77#[derive(Clone)]
88pub struct AppHistory {
@@ -12,7 +12,7 @@ pub struct AppHistory {
1212 pub hover: Option<(usize, usize)>, // x, y
1313 pub selected: Option<(usize, usize)>,
1414 pub client: Client,
15 pub message: Option<String>,
15 pub message: MessageText,
1616 pub load: bool,
1717 pub render: bool,
1818 pub popup_focus: bool,
@@ -30,7 +30,7 @@ impl From<App> for AppHistory {
3030 selectable: original.selectable,
3131 hover: original.hover,
3232 // selected: original.selected,
33 selected: None,
33 selected: original.selected,
3434 client: original.client,
3535 message: original.message,
3636 load: original.load,
src/structs/messagetext.rs added +22
@@ -0,0 +1,22 @@
1#[derive(Clone, PartialEq, Eq)]
2pub enum MessageText {
3 Command(String),
4 Text(String),
5 None,
6}
7
8impl ToString for MessageText {
9 fn to_string(&self) -> String {
10 match self {
11 Self::Command(cmd) => format!(":{}", cmd),
12 Self::Text(s) => s.clone(),
13 Self::None => String::from("All good :)"),
14 }
15 }
16}
17
18impl MessageText {
19 pub fn is_some(&self) -> bool{
20 *self != Self::None
21 }
22}
src/structs/mod.rs +3
@@ -33,3 +33,6 @@ pub use minichannel::*;
3333
3434mod fullchannel;
3535pub use fullchannel::*;
36
37mod messagetext;
38pub use messagetext::*;
src/widgets/force_clear.rs deleted −20
@@ -1,20 +0,0 @@
1use tui::{
2 buffer::Buffer,
3 layout::Rect,
4 style::{Color, Style},
5 widgets::Widget,
6};
7
8pub struct ForceClear;
9
10impl Widget for ForceClear {
11 fn render(self, rect: Rect, buffer: &mut Buffer) {
12 for y in rect.y..rect.y + rect.height {
13 for x in rect.x..rect.x + rect.width {
14 buffer
15 .get_mut(x, y)
16 .set_style(Style::default().bg(Color::DarkGray));
17 }
18 }
19 }
20}
src/widgets/item_display.rs +20 −9
@@ -11,6 +11,7 @@ use crate::structs::ListItem;
1111#[derive(Clone)]
1212pub struct ItemDisplay {
1313 pub item: ListItem,
14 pub render_image: bool,
1415}
1516
1617impl Widget for ItemDisplay {
@@ -40,7 +41,9 @@ impl Widget for ItemDisplay {
4041 ..Default::default()
4142 };
4243
43 let _ = print_from_file(path.as_os_str(), &conf);
44 if self.render_image {
45 let _ = print_from_file(path.as_os_str(), &conf);
46 }
4447 }
4548
4649 let mut y = if exists {
@@ -81,7 +84,7 @@ impl Widget for ItemDisplay {
8184 if y < area.height + area.y {
8285 let rect = Rect {
8386 x: area.x,
84 y: y,
87 y,
8588 width: area.width,
8689 height: area.height + area.y - y,
8790 };
@@ -114,8 +117,9 @@ impl Widget for ItemDisplay {
114117 y: image_transform.y as i16,
115118 ..Default::default()
116119 };
117
120 if self.render_image {
118121 let _ = print_from_file(path.as_os_str(), &conf);
122 }
119123 }
120124
121125 let mut y = if exists {
@@ -162,7 +166,7 @@ impl Widget for ItemDisplay {
162166 if y < area.height + area.y {
163167 let rect = Rect {
164168 x: area.x,
165 y: y,
169 y,
166170 width: area.width,
167171 height: area.height + area.y - y,
168172 };
@@ -197,8 +201,9 @@ impl Widget for ItemDisplay {
197201 y: image_transform.y as i16,
198202 ..Default::default()
199203 };
200
201 let _ = print_from_file(path.as_os_str(), &conf);
204 if self.render_image{
205 let _ = print_from_file(path.as_os_str(), &conf);
206 }
202207 }
203208
204209 let mut y = if exists {
@@ -272,8 +277,9 @@ impl Widget for ItemDisplay {
272277 y: image_transform.y as i16,
273278 ..Default::default()
274279 };
275
280 if self.render_image {
276281 let _ = print_from_file(path.as_os_str(), &conf);
282 }
277283 }
278284
279285 let mut y = if exists {
@@ -339,7 +345,8 @@ impl Widget for ItemDisplay {
339345 }
340346
341347 if item.len() > area.width as usize {
342 item = format!("{}...", &item[..area.width as usize - 3]);
348 // item = format!("{}...", &item[..area.width as usize - 3]);
349 item = format!("{}...", &item.get(..area.width as usize - 3).unwrap_or_default());
343350 }
344351 buf.set_string(area.x, y, item, style);
345352 y += 1;
@@ -348,7 +355,7 @@ impl Widget for ItemDisplay {
348355 if y < area.height + area.y {
349356 let rect = Rect {
350357 x: area.x,
351 y: y,
358 y,
352359 width: area.width,
353360 height: area.height + area.y - y,
354361 };
@@ -385,7 +392,9 @@ impl Widget for ItemDisplay {
385392 ..Default::default()
386393 };
387394
395 if self.render_image{
388396 let _ = print_from_file(path.as_os_str(), &conf);
397 }
389398 }
390399
391400 let mut y = if exists {
@@ -448,7 +457,9 @@ impl Widget for ItemDisplay {
448457 ..Default::default()
449458 };
450459
460 if self.render_image{
451461 let _ = print_from_file(path.as_os_str(), &conf);
462 }
452463 }
453464
454465 let mut y = if exists {
src/widgets/mod.rs −1
@@ -1,4 +1,3 @@
1pub mod force_clear;
21pub mod horizontal_split;
32pub mod item_display;
43pub mod text_list;
src/widgets/text_list.rs +7
@@ -136,6 +136,10 @@ impl TextList {
136136 }
137137
138138 pub fn down(&mut self) {
139 if self.items.len() == 0 {
140 return;
141 }
142
139143 if self.selected < self.items.len() - 1 {
140144 self.selected += 1;
141145 }
@@ -143,6 +147,9 @@ impl TextList {
143147 }
144148
145149 pub fn up(&mut self) {
150 if self.items.len() == 0 {
151 return;
152 }
146153 if self.selected > 0 {
147154 self.selected -= 1;
148155 }