Commit 9846b1a18e

9846b1a18e4ba31bb8f7414888e699ac1219d19a

parent: dcb033702a

Unsigned

Siriusmart <71584876+Siriusmart@users.noreply.github.com> · 2023-07-15 10:35 UTC

#35 more fixes

Layout: unified · split

src/config/commands.rs +3 −1
@@ -83,7 +83,9 @@ impl Default for CommandsConfigSerde {
83// Different pages may contain different `env`s (for example `url` is different in each page) 83// Different pages may contain different `env`s (for example `url` is different in each page)
84 84
85fn launch_command_default() -> String { 85fn launch_command_default() -> String {
86 String::from("loadpage library ;; flush ;; history clear") 86 String::from(
87 "loadpage library ;; flush ;; history clear ;; key Esc 0 ;; key Up 0 ;; key Up 0 ;; key Left 0 ;; key Enter 0",
88 )
87} 89}
88 90
89fn video_default() -> Vec<HashMap<String, String>> { 91fn video_default() -> Vec<HashMap<String, String>> {
src/config/keybindings.rs +8
@@ -129,6 +129,14 @@ impl Default for KeyBindingsConfigSerde {
129 KeyCodeSerde::Char('u'), 129 KeyCodeSerde::Char('u'),
130 HashMap::from([(2, KeyAction::ClearLine)]), 130 HashMap::from([(2, KeyAction::ClearLine)]),
131 ), 131 ),
132 (
133 KeyCodeSerde::Char('a'),
134 HashMap::from([(2, KeyAction::First)]),
135 ),
136 (
137 KeyCodeSerde::Char('e'),
138 HashMap::from([(2, KeyAction::End)]),
139 ),
132 ])) 140 ]))
133 } 141 }
134} 142}
src/config/pages.rs +2 −2
@@ -291,7 +291,7 @@ fn main_menu_default() -> PageConfig {
291 PageRow::from_vec(vec![PageItems::MessageBar], false), 291 PageRow::from_vec(vec![PageItems::MessageBar], false),
292 ], 292 ],
293 message: String::from("Loading main menu..."), 293 message: String::from("Loading main menu..."),
294 command: String::from("key Esc 0 ;; key Up 0 ;; key Left 0 ;; key Enter 0"), 294 command: String::from("key Esc 0 ;; key Down 0 ;; key Down 0 ;; key Enter 0"),
295 } 295 }
296} 296}
297 297
@@ -335,7 +335,7 @@ fn channeldisplay_default() -> PageConfig {
335 PageRow::from_vec(vec![PageItems::MessageBar], false), 335 PageRow::from_vec(vec![PageItems::MessageBar], false),
336 ], 336 ],
337 message: String::from("Loading channel details..."), 337 message: String::from("Loading channel details..."),
338 command: String::from("key Esc 0 ;; key Down 0 ;; key Enter 0"), 338 command: String::from("key Esc 0 ;; key Down 0 ;; key Enter 0 ;; key Up 0"),
339 } 339 }
340} 340}
341 341
src/global/structs/keyaction.rs +4
@@ -38,4 +38,8 @@ pub enum KeyAction {
38 PreviousWord, 38 PreviousWord,
39 /// move cursor to next word in textfield 39 /// move cursor to next word in textfield
40 NextWord, 40 NextWord,
41 /// move cursor to the first position
42 First,
43 /// move cursor to the last position
44 End,
41} 45}
src/items/channeldisplay.rs +36 −24
@@ -51,32 +51,44 @@ impl ChannelDisplay {
51 match self { 51 match self {
52 ChannelDisplay::Videos { 52 ChannelDisplay::Videos {
53 videos, textlist, .. 53 videos, textlist, ..
54 } => vec![( 54 } => {
55 String::from("hover-url"), 55 if textlist.items.is_empty() {
56 format!( 56 vec![(String::from("hover-url"), "no-videos".to_string())]
57 "{}/watch?v={}", 57 } else {
58 match status.provider { 58 vec![(
59 Provider::YouTube => "https://youtube.com", 59 String::from("hover-url"),
60 Provider::Invidious => &mainconfig.invidious_instance, 60 format!(
61 }, 61 "{}/watch?v={}",
62 videos[textlist.selected].id().unwrap_or_default() 62 match status.provider {
63 ), 63 Provider::YouTube => "https://youtube.com",
64 )], 64 Provider::Invidious => &mainconfig.invidious_instance,
65 },
66 videos[textlist.selected].id().unwrap_or_default()
67 ),
68 )]
69 }
70 }
65 ChannelDisplay::Playlists { 71 ChannelDisplay::Playlists {
66 playlists, 72 playlists,
67 textlist, 73 textlist,
68 .. 74 ..
69 } => vec![( 75 } => {
70 String::from("hover-url"), 76 if textlist.items.is_empty() {
71 format!( 77 vec![(String::from("hover-url"), "no-videos".to_string())]
72 "{}/playlist?list={}", 78 } else {
73 match status.provider { 79 vec![(
74 Provider::YouTube => "https://youtube.com", 80 String::from("hover-url"),
75 Provider::Invidious => &mainconfig.invidious_instance, 81 format!(
76 }, 82 "{}/playlist?list={}",
77 playlists[textlist.selected].id().unwrap_or_default() 83 match status.provider {
78 ), 84 Provider::YouTube => "https://youtube.com",
79 )], 85 Provider::Invidious => &mainconfig.invidious_instance,
86 },
87 playlists[textlist.selected].id().unwrap_or_default()
88 ),
89 )]
90 }
91 }
80 _ => Vec::new(), 92 _ => Vec::new(),
81 } 93 }
82 } 94 }
@@ -308,8 +320,8 @@ impl FrameworkItem for ChannelDisplay {
308 let updated = match action { 320 let updated = match action {
309 KeyAction::MoveUp => textlist.up().is_ok(), 321 KeyAction::MoveUp => textlist.up().is_ok(),
310 KeyAction::MoveDown => textlist.down().is_ok(), 322 KeyAction::MoveDown => textlist.down().is_ok(),
311 KeyAction::MoveLeft => textlist.first().is_ok(), 323 KeyAction::MoveLeft | KeyAction::First => textlist.first().is_ok(),
312 KeyAction::MoveRight => textlist.last().is_ok(), 324 KeyAction::MoveRight | KeyAction::End => textlist.last().is_ok(),
313 KeyAction::Select => { 325 KeyAction::Select => {
314 self.select_at_cursor(framework); 326 self.select_at_cursor(framework);
315 return Ok(()); 327 return Ok(());
src/items/channellist.rs +30 −8
@@ -1,4 +1,4 @@
1use crossterm::event::KeyCode; 1
2use ratatui::{ 2use ratatui::{
3 layout::{Constraint, Rect}, 3 layout::{Constraint, Rect},
4 style::Style, 4 style::Style,
@@ -11,7 +11,7 @@ use tui_additions::{
11use typemap::Key; 11use typemap::Key;
12 12
13use crate::{ 13use crate::{
14 config::{AppearanceConfig, MainConfig, Provider}, 14 config::{AppearanceConfig, KeyBindingsConfig, MainConfig, Provider},
15 global::{functions::set_envs, structs::*}, 15 global::{functions::set_envs, structs::*},
16}; 16};
17 17
@@ -218,12 +218,34 @@ impl FrameworkItem for ChannelList {
218 ) -> Result<(), Box<dyn std::error::Error>> { 218 ) -> Result<(), Box<dyn std::error::Error>> {
219 let tasks = framework.data.state.get_mut::<Tasks>().unwrap(); 219 let tasks = framework.data.state.get_mut::<Tasks>().unwrap();
220 let previously_selected = self.selector.selected; 220 let previously_selected = self.selector.selected;
221 match key.code { 221
222 KeyCode::Down if self.selector.down().is_ok() => tasks.priority.push(Task::RenderAll), 222 let action = if let Some(action) = framework
223 KeyCode::Up if self.selector.up().is_ok() => tasks.priority.push(Task::RenderAll), 223 .data
224 KeyCode::Left if self.selector.first().is_ok() => tasks.priority.push(Task::RenderAll), 224 .global
225 KeyCode::Right if self.selector.last().is_ok() => tasks.priority.push(Task::RenderAll), 225 .get::<KeyBindingsConfig>()
226 KeyCode::Enter => { 226 .unwrap()
227 .get(key)
228 {
229 action
230 } else {
231 return Ok(());
232 };
233 match action {
234 KeyAction::MoveDown if self.selector.down().is_ok() => {
235 tasks.priority.push(Task::RenderAll)
236 }
237 KeyAction::MoveUp if self.selector.up().is_ok() => tasks.priority.push(Task::RenderAll),
238 KeyAction::MoveLeft | KeyAction::First => {
239 if self.selector.first().is_ok() {
240 tasks.priority.push(Task::RenderAll)
241 }
242 }
243 KeyAction::MoveRight | KeyAction::End => {
244 if self.selector.last().is_ok() {
245 tasks.priority.push(Task::RenderAll)
246 }
247 }
248 KeyAction::Select => {
227 self.select_at_cursor(framework); 249 self.select_at_cursor(framework);
228 return Ok(()); 250 return Ok(());
229 } 251 }
src/items/itemlist.rs +2 −2
@@ -378,8 +378,8 @@ impl FrameworkItem for ItemList {
378 let updated = match action { 378 let updated = match action {
379 KeyAction::MoveUp => self.textlist.up().is_ok(), 379 KeyAction::MoveUp => self.textlist.up().is_ok(),
380 KeyAction::MoveDown => self.textlist.down().is_ok(), 380 KeyAction::MoveDown => self.textlist.down().is_ok(),
381 KeyAction::MoveLeft => self.textlist.first().is_ok(), 381 KeyAction::MoveLeft | KeyAction::First => self.textlist.first().is_ok(),
382 KeyAction::MoveRight => self.textlist.last().is_ok(), 382 KeyAction::MoveRight | KeyAction::End => self.textlist.last().is_ok(),
383 KeyAction::Select => { 383 KeyAction::Select => {
384 self.select_at_cursor(framework); 384 self.select_at_cursor(framework);
385 false 385 false
src/items/searchbar.rs +20 −58
@@ -77,6 +77,7 @@ impl FrameworkItem for SearchBar {
77 key: crossterm::event::KeyEvent, 77 key: crossterm::event::KeyEvent,
78 _info: tui_additions::framework::ItemInfo, 78 _info: tui_additions::framework::ItemInfo,
79 ) -> Result<(), Box<dyn Error>> { 79 ) -> Result<(), Box<dyn Error>> {
80 let mut render = true;
80 match framework 81 match framework
81 .data 82 .data
82 .global 83 .global
@@ -90,76 +91,37 @@ impl FrameworkItem for SearchBar {
90 if content.is_empty() { 91 if content.is_empty() {
91 *framework.data.global.get_mut::<Message>().unwrap() = 92 *framework.data.global.get_mut::<Message>().unwrap() =
92 Message::Error(String::from("Clipboard empty")); 93 Message::Error(String::from("Clipboard empty"));
93 framework
94 .data
95 .state
96 .get_mut::<Tasks>()
97 .unwrap()
98 .priority
99 .push(Task::RenderAll);
100 return Ok(());
101 } 94 }
102 95
103 // push all characters at cursor location 96 // push all characters at cursor location
104 content.chars().for_each(|c| { 97 content.chars().for_each(|c| {
105 let _ = self.text_field.push(c); 98 let _ = self.text_field.push(c);
106 }); 99 });
107 framework
108 .data
109 .state
110 .get_mut::<Tasks>()
111 .unwrap()
112 .priority
113 .push(Task::RenderAll);
114 return Ok(());
115 }
116 Some(KeyAction::RemoveWord) => {
117 remove_word(&mut self.text_field);
118 framework
119 .data
120 .state
121 .get_mut::<Tasks>()
122 .unwrap()
123 .priority
124 .push(Task::RenderAll);
125 return Ok(());
126 }
127 Some(KeyAction::PreviousWord) => {
128 previous_word(&mut self.text_field);
129 framework
130 .data
131 .state
132 .get_mut::<Tasks>()
133 .unwrap()
134 .priority
135 .push(Task::RenderAll);
136 return Ok(());
137 }
138 Some(KeyAction::NextWord) => {
139 next_word(&mut self.text_field);
140 framework
141 .data
142 .state
143 .get_mut::<Tasks>()
144 .unwrap()
145 .priority
146 .push(Task::RenderAll);
147 return Ok(());
148 } 100 }
101 Some(KeyAction::RemoveWord) => remove_word(&mut self.text_field),
102 Some(KeyAction::PreviousWord) => previous_word(&mut self.text_field),
103 Some(KeyAction::NextWord) => next_word(&mut self.text_field),
149 Some(KeyAction::ClearLine) => { 104 Some(KeyAction::ClearLine) => {
150 self.text_field.content.clear(); 105 self.text_field.content.clear();
151 self.text_field.scroll = 0; 106 self.text_field.scroll = 0;
152 self.text_field.cursor = 0; 107 self.text_field.cursor = 0;
153 framework
154 .data
155 .state
156 .get_mut::<Tasks>()
157 .unwrap()
158 .priority
159 .push(Task::RenderAll);
160 return Ok(());
161 } 108 }
162 _ => {} 109 Some(KeyAction::First | KeyAction::MoveUp) => self.text_field.cursor = 0,
110 Some(KeyAction::End | KeyAction::MoveDown) => {
111 self.text_field.cursor = self.text_field.content.len()
112 }
113 _ => render = false,
114 }
115
116 if render {
117 framework
118 .data
119 .state
120 .get_mut::<Tasks>()
121 .unwrap()
122 .priority
123 .push(Task::RenderAll);
124 return Ok(());
163 } 125 }
164 // pasting clipboard content 126 // pasting clipboard content
165 127
src/items/searchfilters.rs +2 −2
@@ -288,8 +288,8 @@ impl FrameworkItem for SearchFilter {
288 } 288 }
289 KeyAction::MoveUp => hovered_textlist.up().is_ok(), 289 KeyAction::MoveUp => hovered_textlist.up().is_ok(),
290 KeyAction::MoveDown => hovered_textlist.down().is_ok(), 290 KeyAction::MoveDown => hovered_textlist.down().is_ok(),
291 KeyAction::MoveLeft => hovered_textlist.first().is_ok(), 291 KeyAction::MoveLeft | KeyAction::First => hovered_textlist.first().is_ok(),
292 KeyAction::MoveRight => hovered_textlist.last().is_ok(), 292 KeyAction::MoveRight | KeyAction::End => hovered_textlist.last().is_ok(),
293 _ => false, 293 _ => false,
294 }; 294 };
295 295
src/items/singleitem.rs +8 −4
@@ -791,8 +791,8 @@ impl FrameworkItem for SingleItem {
791 // move the cursor in the textlist, only update the screen if it is changed 791 // move the cursor in the textlist, only update the screen if it is changed
792 KeyAction::MoveUp => singlevideoitem.textlist.up().is_ok(), 792 KeyAction::MoveUp => singlevideoitem.textlist.up().is_ok(),
793 KeyAction::MoveDown => singlevideoitem.textlist.down().is_ok(), 793 KeyAction::MoveDown => singlevideoitem.textlist.down().is_ok(),
794 KeyAction::MoveLeft => singlevideoitem.textlist.first().is_ok(), 794 KeyAction::MoveLeft | KeyAction::First => singlevideoitem.textlist.first().is_ok(),
795 KeyAction::MoveRight => singlevideoitem.textlist.last().is_ok(), 795 KeyAction::MoveRight | KeyAction::End => singlevideoitem.textlist.last().is_ok(),
796 KeyAction::Select => { 796 KeyAction::Select => {
797 self.select_at_cursor(framework); 797 self.select_at_cursor(framework);
798 return Ok(()); 798 return Ok(());
@@ -806,8 +806,12 @@ impl FrameworkItem for SingleItem {
806 match action { 806 match action {
807 KeyAction::MoveUp => singleplaylistitem.commands_view.up().is_ok(), 807 KeyAction::MoveUp => singleplaylistitem.commands_view.up().is_ok(),
808 KeyAction::MoveDown => singleplaylistitem.commands_view.down().is_ok(), 808 KeyAction::MoveDown => singleplaylistitem.commands_view.down().is_ok(),
809 KeyAction::MoveLeft => singleplaylistitem.commands_view.first().is_ok(), 809 KeyAction::MoveLeft | KeyAction::First => {
810 KeyAction::MoveRight => singleplaylistitem.commands_view.last().is_ok(), 810 singleplaylistitem.commands_view.first().is_ok()
811 }
812 KeyAction::MoveRight | KeyAction::End => {
813 singleplaylistitem.commands_view.last().is_ok()
814 }
811 KeyAction::Select => { 815 KeyAction::Select => {
812 self.select_at_cursor(framework); 816 self.select_at_cursor(framework);
813 return Ok(()); 817 return Ok(());
src/items/videolist.rs +32 −10
@@ -1,4 +1,4 @@
1use crossterm::event::KeyCode; 1
2use ratatui::{ 2use ratatui::{
3 layout::{Constraint, Rect}, 3 layout::{Constraint, Rect},
4 style::Style, 4 style::Style,
@@ -10,12 +10,12 @@ use tui_additions::{
10use typemap::Key; 10use typemap::Key;
11 11
12use crate::{ 12use crate::{
13 config::{AppearanceConfig, MainConfig, Provider}, 13 config::{AppearanceConfig, KeyBindingsConfig, MainConfig, Provider},
14 global::{ 14 global::{
15 functions::set_envs, 15 functions::set_envs,
16 structs::{ 16 structs::{
17 ChannelDisplayPage, ChannelDisplayPageType, Item, MiniVideoItem, Page, StateEnvs, 17 ChannelDisplayPage, ChannelDisplayPageType, Item, KeyAction, MiniVideoItem, Page,
18 Status, Subscriptions, Task, Tasks, 18 StateEnvs, Status, Subscriptions, Task, Tasks,
19 }, 19 },
20 }, 20 },
21}; 21};
@@ -333,12 +333,34 @@ impl FrameworkItem for VideoList {
333 ) -> Result<(), Box<dyn std::error::Error>> { 333 ) -> Result<(), Box<dyn std::error::Error>> {
334 let tasks = framework.data.state.get_mut::<Tasks>().unwrap(); 334 let tasks = framework.data.state.get_mut::<Tasks>().unwrap();
335 let previously_selected = self.selector.selected; 335 let previously_selected = self.selector.selected;
336 match key.code { 336
337 KeyCode::Down if self.selector.down().is_ok() => tasks.priority.push(Task::RenderAll), 337 let action = if let Some(action) = framework
338 KeyCode::Up if self.selector.up().is_ok() => tasks.priority.push(Task::RenderAll), 338 .data
339 KeyCode::Left if self.selector.first().is_ok() => tasks.priority.push(Task::RenderAll), 339 .global
340 KeyCode::Right if self.selector.last().is_ok() => tasks.priority.push(Task::RenderAll), 340 .get::<KeyBindingsConfig>()
341 KeyCode::Enter => { 341 .unwrap()
342 .get(key)
343 {
344 action
345 } else {
346 return Ok(());
347 };
348 match action {
349 KeyAction::MoveDown if self.selector.down().is_ok() => {
350 tasks.priority.push(Task::RenderAll)
351 }
352 KeyAction::MoveUp if self.selector.up().is_ok() => tasks.priority.push(Task::RenderAll),
353 KeyAction::MoveLeft | KeyAction::First => {
354 if self.selector.first().is_ok() {
355 tasks.priority.push(Task::RenderAll)
356 }
357 }
358 KeyAction::MoveRight | KeyAction::End => {
359 if self.selector.last().is_ok() {
360 tasks.priority.push(Task::RenderAll)
361 }
362 }
363 KeyAction::Select => {
342 self.select_at_cursor(framework); 364 self.select_at_cursor(framework);
343 return Ok(()); 365 return Ok(());
344 } 366 }