Commit a49e41106a

a49e41106a6254f3104d38762198ecba4539d857

parent: 6221eb407a

Unsigned

Siriusmart <71584876+Siriusmart@users.noreply.github.com> · 2022-11-19 17:01 UTC

image lazy loading v0.5.1

Layout: unified · split

Cargo.lock +20 −21
@@ -235,9 +235,9 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
235235
236236[[package]]
237237name = "cxx"
238version = "1.0.81"
238version = "1.0.82"
239239source = "registry+https://github.com/rust-lang/crates.io-index"
240checksum = "97abf9f0eca9e52b7f81b945524e76710e6cb2366aead23b7d4fbf72e281f888"
240checksum = "d4a41a86530d0fe7f5d9ea779916b7cadd2d4f9add748b99c2c029cbbdfaf453"
241241dependencies = [
242242 "cc",
243243 "cxxbridge-flags",
@@ -247,9 +247,9 @@ dependencies = [
247247
248248[[package]]
249249name = "cxx-build"
250version = "1.0.81"
250version = "1.0.82"
251251source = "registry+https://github.com/rust-lang/crates.io-index"
252checksum = "7cc32cc5fea1d894b77d269ddb9f192110069a8a9c1f1d441195fba90553dea3"
252checksum = "06416d667ff3e3ad2df1cd8cd8afae5da26cf9cec4d0825040f88b5ca659a2f0"
253253dependencies = [
254254 "cc",
255255 "codespan-reporting",
@@ -262,15 +262,15 @@ dependencies = [
262262
263263[[package]]
264264name = "cxxbridge-flags"
265version = "1.0.81"
265version = "1.0.82"
266266source = "registry+https://github.com/rust-lang/crates.io-index"
267checksum = "8ca220e4794c934dc6b1207c3b42856ad4c302f2df1712e9f8d2eec5afaacf1f"
267checksum = "820a9a2af1669deeef27cb271f476ffd196a2c4b6731336011e0ba63e2c7cf71"
268268
269269[[package]]
270270name = "cxxbridge-macro"
271version = "1.0.81"
271version = "1.0.82"
272272source = "registry+https://github.com/rust-lang/crates.io-index"
273checksum = "b846f081361125bfc8dc9d3940c84e1fd83ba54bbca7b17cd29483c828be0704"
273checksum = "a08a6e2fcc370a089ad3b4aaf54db3b1b4cee38ddabce5896b33eb693275f470"
274274dependencies = [
275275 "proc-macro2",
276276 "quote",
@@ -693,9 +693,9 @@ dependencies = [
693693
694694[[package]]
695695name = "indexmap"
696version = "1.9.1"
696version = "1.9.2"
697697source = "registry+https://github.com/rust-lang/crates.io-index"
698checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e"
698checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399"
699699dependencies = [
700700 "autocfg",
701701 "hashbrown",
@@ -1071,11 +1071,10 @@ dependencies = [
10711071
10721072[[package]]
10731073name = "rayon"
1074version = "1.5.3"
1074version = "1.6.0"
10751075source = "registry+https://github.com/rust-lang/crates.io-index"
1076checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d"
1076checksum = "1e060280438193c554f654141c9ea9417886713b7acd75974c85b18a69a88e0b"
10771077dependencies = [
1078 "autocfg",
10791078 "crossbeam-deque",
10801079 "either",
10811080 "rayon-core",
@@ -1083,9 +1082,9 @@ dependencies = [
10831082
10841083[[package]]
10851084name = "rayon-core"
1086version = "1.9.3"
1085version = "1.10.1"
10871086source = "registry+https://github.com/rust-lang/crates.io-index"
1088checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f"
1087checksum = "cac410af5d00ab6884528b4ab69d1e8e146e8d471201800fa1b4524126de6ad3"
10891088dependencies = [
10901089 "crossbeam-channel",
10911090 "crossbeam-deque",
@@ -1113,9 +1112,9 @@ dependencies = [
11131112
11141113[[package]]
11151114name = "reqwest"
1116version = "0.11.12"
1115version = "0.11.13"
11171116source = "registry+https://github.com/rust-lang/crates.io-index"
1118checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc"
1117checksum = "68cc60575865c7831548863cc02356512e3f1dc2f3f82cb837d7fc4cc8f3c97c"
11191118dependencies = [
11201119 "base64",
11211120 "bytes",
@@ -1236,9 +1235,9 @@ dependencies = [
12361235
12371236[[package]]
12381237name = "serde_json"
1239version = "1.0.87"
1238version = "1.0.88"
12401239source = "registry+https://github.com/rust-lang/crates.io-index"
1241checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45"
1240checksum = "8e8b3801309262e8184d9687fb697586833e939767aea0dda89f5a8e650e8bd7"
12421241dependencies = [
12431242 "itoa",
12441243 "ryu",
@@ -1433,9 +1432,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
14331432
14341433[[package]]
14351434name = "tokio"
1436version = "1.21.2"
1435version = "1.22.0"
14371436source = "registry+https://github.com/rust-lang/crates.io-index"
1438checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099"
1437checksum = "d76ce4a75fb488c605c54bf610f221cea8b0dafb53333c1a67e8ee199dcd2ae3"
14391438dependencies = [
14401439 "autocfg",
14411440 "bytes",
docs/src/README.md +3 −1
@@ -48,7 +48,9 @@ The YouTube TUI allows you to browse YouTube with (almost) all of it's features,
4848
4949### What it doesn't have
5050
51- Vim-like commands (first priority)
51- Next page button in pages (first priority)
52- Lazy image loading (first priority)
53- Vim-like commands (will implement)
5254- Channel search (will implement)
5355- Channel videos sorting (will implement)
5456- Subscriptions (will implement)
docs/src/changelogs.md +8 −1
@@ -1,6 +1,13 @@
11# Changelogs
22
3## v0.5.0
3## v0.5.1
4
5#### Added
6
7- Image lazy loading (will not rerender image if already rendered)
8- Optional features that can be disabled
9
10### v0.5.0
411
512#### Added
613
docs/src/installation.md +7 −1
@@ -2,6 +2,8 @@
22
33It's about download (or building) the binary and putting them in an easily accessible location (like `/bin/`).
44
5The YouTube TUI is not tested for Windows.
6
57## Install from Crates.io (recommended)
68
79Crates.io is a repository for programs written in Rust, and the YouTube TUI is avaliable <a href="https://crates.io/crates/youtube-tui" target=_blank>*there*</a>.
@@ -62,10 +64,14 @@ cargo install youtube-tui --all-features # install with all features (even if no
6264
6365### `halfblock` (default)
6466
65Display images through HalfBlocks, work best in terminals with TrueColour support (so would not recommend for Windows users).
67Display images through HalfBlocks, work best in terminals with TrueColour support.
6668
6769### `sixel` (default)
6870
6971Display images with Sixels, allows the display of images at full definition. Not present on windows.
7072
7173Enabling this will also enable `halfblock`.
74
75Requires <a href="https://github.com/saitoha/libsixel" target=_blank>`libsixel`</a>.
76
77> `sixel` and `halfblock` does not compile on Windows.
src/global/structs/status.rs +3
@@ -4,6 +4,8 @@ use typemap::Key;
44#[derive(Clone)]
55pub struct Status {
66 pub popup_opened: bool,
7 /// to prevent rerendering the same image
8 pub render_image: bool,
79}
810
911impl Key for Status {
@@ -14,6 +16,7 @@ impl Default for Status {
1416 fn default() -> Self {
1517 Self {
1618 popup_opened: false,
19 render_image: true,
1720 }
1821 }
1922}
src/global/structs/tasks.rs +14 −1
@@ -16,6 +16,7 @@ pub enum Task {
1616 RenderOnly(usize, usize),
1717 LoadPage(Page),
1818 ClearPage,
19 LazyRendered,
1920}
2021
2122/// multiple tasks joined together, with duplicates removed
@@ -25,6 +26,7 @@ pub struct TaskQueue {
2526 pub reload: bool,
2627 pub load_page: Option<Page>,
2728 pub clear_all: bool,
29 pub lazy_rendered: bool,
2830}
2931
3032impl Default for TaskQueue {
@@ -34,6 +36,7 @@ impl Default for TaskQueue {
3436 reload: false,
3537 load_page: None,
3638 clear_all: false,
39 lazy_rendered: false,
3740 }
3841 }
3942}
@@ -56,6 +59,7 @@ impl TaskQueue {
5659 },
5760 Task::LoadPage(page) => self.load_page = Some(page),
5861 Task::ClearPage => self.clear_all = true,
62 Task::LazyRendered => self.lazy_rendered = true,
5963 // _ => {}
6064 }
6165 }
@@ -74,6 +78,15 @@ impl TaskQueue {
7478 terminal.clear()?;
7579 }
7680
81 if self.lazy_rendered {
82 framework
83 .data
84 .global
85 .get_mut::<Status>()
86 .unwrap()
87 .render_image = false;
88 }
89
7790 // save state in history, then replace all items by whats in the new page and run `.load()` on them
7891 if let Some(page) = self.load_page {
7992 *framework.data.global.get_mut::<Message>().unwrap() =
@@ -87,7 +100,7 @@ impl TaskQueue {
87100
88101 let state = page_config.to_state(framework);
89102 framework.set_state(state);
90 framework.data.state.get_mut::<Status>().unwrap().reset();
103 framework.data.global.get_mut::<Status>().unwrap().reset();
91104 *framework.data.state.get_mut::<Page>().unwrap() = page;
92105 Self::render_force_clear(framework, terminal)?;
93106 *framework.data.global.get_mut::<Message>().unwrap() = Message::None;
src/init.rs +1 −1
@@ -69,6 +69,7 @@ pub fn init(framework: &mut Framework) -> Result<(), Box<dyn Error>> {
6969 .data
7070 .global
7171 .insert::<CommandsConfig>(CommandsConfig::from(*CommandsConfigSerde::load()?));
72 framework.data.global.insert::<Status>(Status::default());
7273
7374 framework.data.state.insert::<Tasks>(Tasks::default());
7475 framework.data.state.insert::<Page>(Page::default());
@@ -77,7 +78,6 @@ pub fn init(framework: &mut Framework) -> Result<(), Box<dyn Error>> {
7778 .data
7879 .state
7980 .insert::<MinDimentions>(MinDimentions::default());
80 framework.data.state.insert::<Status>(Status::default());
8181
8282 Ok(())
8383}
src/items/channeldisplay.rs +22 −13
@@ -5,7 +5,7 @@ use crate::{
55 functions::download_all_images,
66 structs::{
77 ChannelDisplayPageType, InvidiousClient, Item, KeyAction, Message, Page,
8 SingleItemPage, Task, Tasks,
8 SingleItemPage, Status, Task, Tasks,
99 },
1010 },
1111};
@@ -25,6 +25,7 @@ pub enum ChannelDisplay {
2525 None,
2626 Main {
2727 channel: Item,
28 iteminfo: ItemInfo,
2829 },
2930 Videos {
3031 videos: Vec<Item>,
@@ -133,7 +134,7 @@ impl FrameworkItem for ChannelDisplay {
133134 .border_style(border_style);
134135 frame.render_widget(block, area);
135136 }
136 Self::Main { channel } => {
137 Self::Main { iteminfo, .. } => {
137138 let block = Block::default()
138139 .border_type(appearance.borders)
139140 .borders(Borders::ALL)
@@ -141,10 +142,7 @@ impl FrameworkItem for ChannelDisplay {
141142 let inner = block.inner(area);
142143
143144 frame.render_widget(block, area);
144 ItemInfo {
145 item: Some(channel.clone()),
146 }
147 .render(frame, framework, inner, popup_render, info);
145 iteminfo.render(frame, framework, inner, popup_render, info);
148146 }
149147 Self::Videos {
150148 textlist,
@@ -237,6 +235,12 @@ impl FrameworkItem for ChannelDisplay {
237235 .unwrap()
238236 .priority
239237 .push(Task::RenderAll);
238 framework
239 .data
240 .global
241 .get_mut::<Status>()
242 .unwrap()
243 .render_image = true;
240244 iteminfo.item = Some(videos[textlist.selected].clone());
241245 }
242246 }
@@ -279,6 +283,12 @@ impl FrameworkItem for ChannelDisplay {
279283 .unwrap()
280284 .priority
281285 .push(Task::RenderAll);
286 framework
287 .data
288 .global
289 .get_mut::<Status>()
290 .unwrap()
291 .render_image = true;
282292 iteminfo.item = Some(playlists[textlist.selected].clone());
283293 }
284294 }
@@ -310,7 +320,10 @@ impl FrameworkItem for ChannelDisplay {
310320 mainconfig.image_index,
311321 );
312322 download_all_images(vec![(&channel).into()]);
313 *self = Self::Main { channel }
323 *self = Self::Main {
324 iteminfo: ItemInfo::new(Some(channel.clone())),
325 channel,
326 }
314327 }
315328 ChannelDisplayPageType::Videos => {
316329 let videos = framework
@@ -331,9 +344,7 @@ impl FrameworkItem for ChannelDisplay {
331344 .border_type(appearance.borders)
332345 .style(Style::default().fg(appearance.colors.text))
333346 .items(&videos)?,
334 iteminfo: ItemInfo {
335 item: videos.first().cloned(),
336 },
347 iteminfo: ItemInfo::new(videos.first().cloned()),
337348 grid: Grid::new(
338349 vec![Constraint::Percentage(60), Constraint::Percentage(40)],
339350 vec![Constraint::Percentage(100)],
@@ -361,9 +372,7 @@ impl FrameworkItem for ChannelDisplay {
361372 .border_type(appearance.borders)
362373 .style(Style::default().fg(appearance.colors.text))
363374 .items(&playlists)?,
364 iteminfo: ItemInfo {
365 item: playlists.first().cloned(),
366 },
375 iteminfo: ItemInfo::new(playlists.first().cloned()),
367376 grid: Grid::new(
368377 vec![Constraint::Percentage(60), Constraint::Percentage(40)],
369378 vec![Constraint::Percentage(100)],
src/items/iteminfo.rs +31 −5
@@ -9,13 +9,14 @@ use viuer::{print_from_file, Config};
99
1010use crate::{
1111 config::{AppearanceConfig, MainConfig},
12 global::structs::{Item, Status},
12 global::structs::{Item, Status, Task, Tasks},
1313};
1414
1515/// an item info displays info of any `Item`s
1616#[derive(Clone)]
1717pub struct ItemInfo {
1818 pub item: Option<Item>,
19 pub lazy_scroll: u16,
1920}
2021
2122impl FrameworkItem for ItemInfo {
@@ -38,12 +39,14 @@ impl FrameworkItem for ItemInfo {
3839 };
3940
4041 let main_config = framework.data.global.get::<MainConfig>().unwrap();
41 let appearance = framework.data.global.get::<AppearanceConfig>().unwrap();
42 let status = framework.data.global.get::<Status>().unwrap();
4243
4344 // The scroll (space above) text info will be the height of the image, but if the image fail to display, the scroll will be 0
44 let scroll = if cfg!(any(feature = "halfblock", feature = "sixel"))
45 let scroll = if !status.render_image {
46 self.lazy_scroll
47 } else if cfg!(any(feature = "halfblock", feature = "sixel"))
4548 && main_config.images.display()
46 && !framework.data.state.get::<Status>().unwrap().popup_opened
49 && !status.popup_opened
4750 {
4851 let mut scroll = 0;
4952
@@ -74,6 +77,13 @@ impl FrameworkItem for ItemInfo {
7477
7578 if let Ok((_, height)) = print_from_file(thumbnail_path, &config) {
7679 scroll = height as u16;
80 framework
81 .data
82 .state
83 .get_mut::<Tasks>()
84 .unwrap()
85 .priority
86 .push(Task::LazyRendered);
7787 } else {
7888 scroll = 0;
7989 }
@@ -84,6 +94,10 @@ impl FrameworkItem for ItemInfo {
8494 0
8595 };
8696
97 self.lazy_scroll = scroll;
98
99 let appearance = framework.data.global.get::<AppearanceConfig>().unwrap();
100
87101 // Each "span" contains a string and a Style, and they are one line max each
88102 // A "text" is used for descriptions in video/playlist and channels, and starts a new line if the old one runs out
89103 let (spans, text) = match item {
@@ -359,6 +373,18 @@ impl FrameworkItem for ItemInfo {
359373
360374impl Default for ItemInfo {
361375 fn default() -> Self {
362 Self { item: None }
376 Self {
377 item: None,
378 lazy_scroll: 0,
379 }
380 }
381}
382
383impl ItemInfo {
384 pub fn new(item: Option<Item>) -> Self {
385 Self {
386 item,
387 ..Default::default()
388 }
363389 }
364390}
src/items/itemlist.rs +7 −1
@@ -14,7 +14,7 @@ use crate::{
1414 structs::{
1515 ChannelDisplayPage, ChannelDisplayPageType, FullPlaylistItem, FullVideoItem,
1616 InvidiousClient, Item, KeyAction, MainMenuPage, MiniChannelItem, MiniPlaylistItem,
17 MiniVideoItem, Page, SingleItemPage, Task, Tasks, WatchHistory,
17 MiniVideoItem, Page, SingleItemPage, Status, Task, Tasks, WatchHistory,
1818 },
1919 },
2020};
@@ -264,6 +264,12 @@ impl FrameworkItem for ItemList {
264264
265265 // only create a render task if the key event actually changed something
266266 if updated {
267 framework
268 .data
269 .global
270 .get_mut::<Status>()
271 .unwrap()
272 .render_image = true;
267273 self.info.item = Some(self.items[self.textlist.selected].clone());
268274 framework
269275 .data
src/items/searchfilters.rs +5 −7
@@ -188,7 +188,7 @@ impl FrameworkItem for SearchFilter {
188188 fn select(&mut self, framework: &mut tui_additions::framework::FrameworkClean) -> bool {
189189 framework
190190 .data
191 .state
191 .global
192192 .get_mut::<Status>()
193193 .unwrap()
194194 .popup_opened = true;
@@ -220,12 +220,10 @@ impl FrameworkItem for SearchFilter {
220220 }
221221
222222 fn deselect(&mut self, framework: &mut tui_additions::framework::FrameworkClean) -> bool {
223 framework
224 .data
225 .state
226 .get_mut::<Status>()
227 .unwrap()
228 .popup_opened = false;
223 *framework.data.global.get_mut::<Status>().unwrap() = Status {
224 popup_opened: false,
225 render_image: true,
226 };
229227
230228 // refresh page only if changed and enabled in options
231229 let search_options = framework.data.state.get::<Search>().unwrap().clone();
src/items/singleitem.rs +12 −8
@@ -4,7 +4,7 @@ use crate::{
44 global::{
55 functions::download_all_images,
66 structs::{
7 InvidiousClient, Item, KeyAction, Message, Page, SingleItemPage, Task, Tasks,
7 InvidiousClient, Item, KeyAction, Message, Page, SingleItemPage, Status, Task, Tasks,
88 WatchHistory,
99 },
1010 },
@@ -168,13 +168,11 @@ impl SinglePlaylistItem {
168168 mainconfig: &MainConfig,
169169 playlist_items: &[Item],
170170 ) -> Self {
171 let hovered_video = ItemInfo {
172 item: if playlist_items.is_empty() {
173 None
174 } else {
175 Some(playlist_items[0].clone())
176 },
177 };
171 let hovered_video = ItemInfo::new(if playlist_items.is_empty() {
172 None
173 } else {
174 Some(playlist_items[0].clone())
175 });
178176 Self {
179177 commands_view: TextList::default()
180178 .items(&commands.playlist.iter().map(|command| &command.0).collect())
@@ -763,6 +761,12 @@ impl FrameworkItem for SingleItem {
763761 };
764762
765763 if updated {
764 framework
765 .data
766 .global
767 .get_mut::<Status>()
768 .unwrap()
769 .render_image = true;
766770 framework
767771 .data
768772 .state
src/run.rs +19 −1
@@ -5,7 +5,7 @@ use tui_additions::framework::{Framework, FrameworkDirection};
55
66use crate::{
77 config::KeyBindingsConfig,
8 global::structs::{KeyAction, MainMenuPage, Message, Page, Task, Tasks},
8 global::structs::{KeyAction, MainMenuPage, Message, Page, Status, Task, Tasks},
99};
1010
1111/// the main event loop of the program
@@ -91,6 +91,12 @@ pub fn run(
9191 "This is already the beginning of history",
9292 ))
9393 } else {
94 framework
95 .data
96 .global
97 .get_mut::<Status>()
98 .unwrap()
99 .render_image = true;
94100 framework
95101 .data
96102 .state
@@ -107,6 +113,12 @@ pub fn run(
107113 "This is already the beginning of history",
108114 ))
109115 } else {
116 framework
117 .data
118 .global
119 .get_mut::<Status>()
120 .unwrap()
121 .render_image = true;
110122 framework
111123 .data
112124 .state
@@ -153,6 +165,12 @@ pub fn run(
153165 .unwrap()
154166 .priority
155167 .push(Task::RenderAll);
168 framework
169 .data
170 .global
171 .get_mut::<Status>()
172 .unwrap()
173 .render_image = true;
156174 }
157175 _ => {}
158176 }