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 {
8383// Different pages may contain different `env`s (for example `url` is different in each page)
8484
8585fn 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 )
8789}
8890
8991fn video_default() -> Vec<HashMap<String, String>> {
src/config/keybindings.rs +8
@@ -129,6 +129,14 @@ impl Default for KeyBindingsConfigSerde {
129129 KeyCodeSerde::Char('u'),
130130 HashMap::from([(2, KeyAction::ClearLine)]),
131131 ),
132 (
133 KeyCodeSerde::Char('a'),
134 HashMap::from([(2, KeyAction::First)]),
135 ),
136 (
137 KeyCodeSerde::Char('e'),
138 HashMap::from([(2, KeyAction::End)]),
139 ),
132140 ]))
133141 }
134142}
src/config/pages.rs +2 −2
@@ -291,7 +291,7 @@ fn main_menu_default() -> PageConfig {
291291 PageRow::from_vec(vec![PageItems::MessageBar], false),
292292 ],
293293 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"),
295295 }
296296}
297297
@@ -335,7 +335,7 @@ fn channeldisplay_default() -> PageConfig {
335335 PageRow::from_vec(vec![PageItems::MessageBar], false),
336336 ],
337337 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"),
339339 }
340340}
341341
src/global/structs/keyaction.rs +4
@@ -38,4 +38,8 @@ pub enum KeyAction {
3838 PreviousWord,
3939 /// move cursor to next word in textfield
4040 NextWord,
41 /// move cursor to the first position
42 First,
43 /// move cursor to the last position
44 End,
4145}
src/items/channeldisplay.rs +36 −24
@@ -51,32 +51,44 @@ impl ChannelDisplay {
5151 match self {
5252 ChannelDisplay::Videos {
5353 videos, textlist, ..
54 } => vec![(
55 String::from("hover-url"),
56 format!(
57 "{}/watch?v={}",
58 match status.provider {
59 Provider::YouTube => "https://youtube.com",
60 Provider::Invidious => &mainconfig.invidious_instance,
61 },
62 videos[textlist.selected].id().unwrap_or_default()
63 ),
64 )],
54 } => {
55 if textlist.items.is_empty() {
56 vec![(String::from("hover-url"), "no-videos".to_string())]
57 } else {
58 vec![(
59 String::from("hover-url"),
60 format!(
61 "{}/watch?v={}",
62 match status.provider {
63 Provider::YouTube => "https://youtube.com",
64 Provider::Invidious => &mainconfig.invidious_instance,
65 },
66 videos[textlist.selected].id().unwrap_or_default()
67 ),
68 )]
69 }
70 }
6571 ChannelDisplay::Playlists {
6672 playlists,
6773 textlist,
6874 ..
69 } => vec![(
70 String::from("hover-url"),
71 format!(
72 "{}/playlist?list={}",
73 match status.provider {
74 Provider::YouTube => "https://youtube.com",
75 Provider::Invidious => &mainconfig.invidious_instance,
76 },
77 playlists[textlist.selected].id().unwrap_or_default()
78 ),
79 )],
75 } => {
76 if textlist.items.is_empty() {
77 vec![(String::from("hover-url"), "no-videos".to_string())]
78 } else {
79 vec![(
80 String::from("hover-url"),
81 format!(
82 "{}/playlist?list={}",
83 match status.provider {
84 Provider::YouTube => "https://youtube.com",
85 Provider::Invidious => &mainconfig.invidious_instance,
86 },
87 playlists[textlist.selected].id().unwrap_or_default()
88 ),
89 )]
90 }
91 }
8092 _ => Vec::new(),
8193 }
8294 }
@@ -308,8 +320,8 @@ impl FrameworkItem for ChannelDisplay {
308320 let updated = match action {
309321 KeyAction::MoveUp => textlist.up().is_ok(),
310322 KeyAction::MoveDown => textlist.down().is_ok(),
311 KeyAction::MoveLeft => textlist.first().is_ok(),
312 KeyAction::MoveRight => textlist.last().is_ok(),
323 KeyAction::MoveLeft | KeyAction::First => textlist.first().is_ok(),
324 KeyAction::MoveRight | KeyAction::End => textlist.last().is_ok(),
313325 KeyAction::Select => {
314326 self.select_at_cursor(framework);
315327 return Ok(());
src/items/channellist.rs +30 −8
@@ -1,4 +1,4 @@
1use crossterm::event::KeyCode;
1
22use ratatui::{
33 layout::{Constraint, Rect},
44 style::Style,
@@ -11,7 +11,7 @@ use tui_additions::{
1111use typemap::Key;
1212
1313use crate::{
14 config::{AppearanceConfig, MainConfig, Provider},
14 config::{AppearanceConfig, KeyBindingsConfig, MainConfig, Provider},
1515 global::{functions::set_envs, structs::*},
1616};
1717
@@ -218,12 +218,34 @@ impl FrameworkItem for ChannelList {
218218 ) -> Result<(), Box<dyn std::error::Error>> {
219219 let tasks = framework.data.state.get_mut::<Tasks>().unwrap();
220220 let previously_selected = self.selector.selected;
221 match key.code {
222 KeyCode::Down if self.selector.down().is_ok() => tasks.priority.push(Task::RenderAll),
223 KeyCode::Up if self.selector.up().is_ok() => tasks.priority.push(Task::RenderAll),
224 KeyCode::Left if self.selector.first().is_ok() => tasks.priority.push(Task::RenderAll),
225 KeyCode::Right if self.selector.last().is_ok() => tasks.priority.push(Task::RenderAll),
226 KeyCode::Enter => {
221
222 let action = if let Some(action) = framework
223 .data
224 .global
225 .get::<KeyBindingsConfig>()
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 => {
227249 self.select_at_cursor(framework);
228250 return Ok(());
229251 }
src/items/itemlist.rs +2 −2
@@ -378,8 +378,8 @@ impl FrameworkItem for ItemList {
378378 let updated = match action {
379379 KeyAction::MoveUp => self.textlist.up().is_ok(),
380380 KeyAction::MoveDown => self.textlist.down().is_ok(),
381 KeyAction::MoveLeft => self.textlist.first().is_ok(),
382 KeyAction::MoveRight => self.textlist.last().is_ok(),
381 KeyAction::MoveLeft | KeyAction::First => self.textlist.first().is_ok(),
382 KeyAction::MoveRight | KeyAction::End => self.textlist.last().is_ok(),
383383 KeyAction::Select => {
384384 self.select_at_cursor(framework);
385385 false
src/items/searchbar.rs +20 −58
@@ -77,6 +77,7 @@ impl FrameworkItem for SearchBar {
7777 key: crossterm::event::KeyEvent,
7878 _info: tui_additions::framework::ItemInfo,
7979 ) -> Result<(), Box<dyn Error>> {
80 let mut render = true;
8081 match framework
8182 .data
8283 .global
@@ -90,76 +91,37 @@ impl FrameworkItem for SearchBar {
9091 if content.is_empty() {
9192 *framework.data.global.get_mut::<Message>().unwrap() =
9293 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(());
10194 }
10295
10396 // push all characters at cursor location
10497 content.chars().for_each(|c| {
10598 let _ = self.text_field.push(c);
10699 });
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(());
148100 }
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),
149104 Some(KeyAction::ClearLine) => {
150105 self.text_field.content.clear();
151106 self.text_field.scroll = 0;
152107 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(());
161108 }
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(());
163125 }
164126 // pasting clipboard content
165127
src/items/searchfilters.rs +2 −2
@@ -288,8 +288,8 @@ impl FrameworkItem for SearchFilter {
288288 }
289289 KeyAction::MoveUp => hovered_textlist.up().is_ok(),
290290 KeyAction::MoveDown => hovered_textlist.down().is_ok(),
291 KeyAction::MoveLeft => hovered_textlist.first().is_ok(),
292 KeyAction::MoveRight => hovered_textlist.last().is_ok(),
291 KeyAction::MoveLeft | KeyAction::First => hovered_textlist.first().is_ok(),
292 KeyAction::MoveRight | KeyAction::End => hovered_textlist.last().is_ok(),
293293 _ => false,
294294 };
295295
src/items/singleitem.rs +8 −4
@@ -791,8 +791,8 @@ impl FrameworkItem for SingleItem {
791791 // move the cursor in the textlist, only update the screen if it is changed
792792 KeyAction::MoveUp => singlevideoitem.textlist.up().is_ok(),
793793 KeyAction::MoveDown => singlevideoitem.textlist.down().is_ok(),
794 KeyAction::MoveLeft => singlevideoitem.textlist.first().is_ok(),
795 KeyAction::MoveRight => singlevideoitem.textlist.last().is_ok(),
794 KeyAction::MoveLeft | KeyAction::First => singlevideoitem.textlist.first().is_ok(),
795 KeyAction::MoveRight | KeyAction::End => singlevideoitem.textlist.last().is_ok(),
796796 KeyAction::Select => {
797797 self.select_at_cursor(framework);
798798 return Ok(());
@@ -806,8 +806,12 @@ impl FrameworkItem for SingleItem {
806806 match action {
807807 KeyAction::MoveUp => singleplaylistitem.commands_view.up().is_ok(),
808808 KeyAction::MoveDown => singleplaylistitem.commands_view.down().is_ok(),
809 KeyAction::MoveLeft => singleplaylistitem.commands_view.first().is_ok(),
810 KeyAction::MoveRight => singleplaylistitem.commands_view.last().is_ok(),
809 KeyAction::MoveLeft | KeyAction::First => {
810 singleplaylistitem.commands_view.first().is_ok()
811 }
812 KeyAction::MoveRight | KeyAction::End => {
813 singleplaylistitem.commands_view.last().is_ok()
814 }
811815 KeyAction::Select => {
812816 self.select_at_cursor(framework);
813817 return Ok(());
src/items/videolist.rs +32 −10
@@ -1,4 +1,4 @@
1use crossterm::event::KeyCode;
1
22use ratatui::{
33 layout::{Constraint, Rect},
44 style::Style,
@@ -10,12 +10,12 @@ use tui_additions::{
1010use typemap::Key;
1111
1212use crate::{
13 config::{AppearanceConfig, MainConfig, Provider},
13 config::{AppearanceConfig, KeyBindingsConfig, MainConfig, Provider},
1414 global::{
1515 functions::set_envs,
1616 structs::{
17 ChannelDisplayPage, ChannelDisplayPageType, Item, MiniVideoItem, Page, StateEnvs,
18 Status, Subscriptions, Task, Tasks,
17 ChannelDisplayPage, ChannelDisplayPageType, Item, KeyAction, MiniVideoItem, Page,
18 StateEnvs, Status, Subscriptions, Task, Tasks,
1919 },
2020 },
2121};
@@ -333,12 +333,34 @@ impl FrameworkItem for VideoList {
333333 ) -> Result<(), Box<dyn std::error::Error>> {
334334 let tasks = framework.data.state.get_mut::<Tasks>().unwrap();
335335 let previously_selected = self.selector.selected;
336 match key.code {
337 KeyCode::Down if self.selector.down().is_ok() => tasks.priority.push(Task::RenderAll),
338 KeyCode::Up if self.selector.up().is_ok() => tasks.priority.push(Task::RenderAll),
339 KeyCode::Left if self.selector.first().is_ok() => tasks.priority.push(Task::RenderAll),
340 KeyCode::Right if self.selector.last().is_ok() => tasks.priority.push(Task::RenderAll),
341 KeyCode::Enter => {
336
337 let action = if let Some(action) = framework
338 .data
339 .global
340 .get::<KeyBindingsConfig>()
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 => {
342364 self.select_at_cursor(framework);
343365 return Ok(());
344366 }