Commit d0e04a92b3

d0e04a92b3abe169cbf6e13b905cdfe66e2a38f6

parent: d23a77777b

Unsigned

Siriusmart <71584876+Siriusmart@users.noreply.github.com> · 2023-07-14 11:38 UTC

selected items no longer "eat" your input (configureable main.yml)

Layout: unified · split

Cargo.lock +2 −2
@@ -1164,9 +1164,9 @@ checksum = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079"
1164 1164
1165[[package]] 1165[[package]]
1166name = "tui-additions" 1166name = "tui-additions"
1167version = "0.2.0" 1167version = "0.2.1"
1168source = "registry+https://github.com/rust-lang/crates.io-index" 1168source = "registry+https://github.com/rust-lang/crates.io-index"
1169checksum = "8e7718181edae897f9e740d9e38c6b4d6961b2172a90bd7ba5d0a0c206a040b5" 1169checksum = "1de5841ec45de71c46252a832bb1e3e69abf2ee2492eb309ea077c8d78e798e7"
1170dependencies = [ 1170dependencies = [
1171 "crossterm 0.26.1", 1171 "crossterm 0.26.1",
1172 "dyn-clone", 1172 "dyn-clone",
Cargo.toml +1 −1
@@ -28,7 +28,7 @@ viuer = {version = "0.6", default-features = false, optional = true}
28home = "0.5" 28home = "0.5"
29chrono = {version = "0.4", default-features = false, features = ["clock"]} 29chrono = {version = "0.4", default-features = false, features = ["clock"]}
30typemap = {version = "0.3", default-features = false} 30typemap = {version = "0.3", default-features = false}
31tui-additions = {version = "0.2.0", default-features = false, features = ["framework", "widgets"]} 31tui-additions = {version = "0.2.1", default-features = false, features = ["framework", "widgets"]}
32invidious = {version = "0.5"} 32invidious = {version = "0.5"}
33serde_yaml = {version = "0.9", default-features = false} 33serde_yaml = {version = "0.9", default-features = false}
34dyn-clone = {version = "1.0", default-features = false} 34dyn-clone = {version = "1.0", default-features = false}
docs/src/changelogs.md +11
@@ -1,5 +1,16 @@
1# Changelogs 1# Changelogs
2 2
3### v0.7.4 (latest unstable on git)
4
5#### Added
6
7- `Ctrl + w` and `Ctrl + u` in search bar and command mode.
8- Keybindings works even when an item is selected (`legacy_input_handling: false` in `main.yml`).
9
10#### Fixed
11
12- Search filters popup closing when you click on it.
13
3## v0.7.3 (latest stable on crates.io) 14## v0.7.3 (latest stable on crates.io)
4 15
5### Added 16### Added
src/config/main.rs +7
@@ -32,6 +32,8 @@ pub struct MainConfig {
32 pub provider: Provider, 32 pub provider: Provider,
33 #[serde(default = "shell_default")] 33 #[serde(default = "shell_default")]
34 pub shell: String, 34 pub shell: String,
35 #[serde(default = "legacy_input_handling_default")]
36 pub legacy_input_handling: bool,
35 #[serde(default = "default_env")] 37 #[serde(default = "default_env")]
36 pub env: HashMap<String, String>, 38 pub env: HashMap<String, String>,
37} 39}
@@ -56,6 +58,7 @@ impl Default for MainConfig {
56 syncing: sync_config_default(), 58 syncing: sync_config_default(),
57 provider: provider_default(), 59 provider: provider_default(),
58 shell: shell_default(), 60 shell: shell_default(),
61 legacy_input_handling: legacy_input_handling_default(),
59 62
60 env: default_env(), 63 env: default_env(),
61 } 64 }
@@ -215,3 +218,7 @@ const fn sync_channel_cooldown_secs_default() -> u64 {
215const fn sync_videos_cooldown_secs_default() -> u64 { 218const fn sync_videos_cooldown_secs_default() -> u64 {
216 600 219 600
217} 220}
221
222const fn legacy_input_handling_default() -> bool {
223 false
224}
src/run.rs +39 −19
@@ -1,6 +1,6 @@
1use crossterm::event::{self, Event, MouseButton, MouseEventKind}; 1use crossterm::event::{self, Event, MouseButton, MouseEventKind};
2use ratatui::{backend::CrosstermBackend, Terminal}; 2use ratatui::{backend::CrosstermBackend, Terminal};
3use std::{error::Error, io::Stdout}; 3use std::{any::TypeId, error::Error, io::Stdout};
4use tui_additions::{ 4use tui_additions::{
5 framework::{Framework, FrameworkDirection}, 5 framework::{Framework, FrameworkDirection},
6 widgets::TextField, 6 widgets::TextField,
@@ -9,6 +9,7 @@ use tui_additions::{
9use crate::{ 9use crate::{
10 config::*, 10 config::*,
11 global::{functions::*, structs::*}, 11 global::{functions::*, structs::*},
12 items::{SearchBar, SearchFilter},
12}; 13};
13 14
14/// the main event loop of the program 15/// the main event loop of the program
@@ -61,8 +62,7 @@ pub fn run(
61 let (mut frameworkclean, state) = framework.split_clean(); 62 let (mut frameworkclean, state) = framework.split_clean();
62 for row in state.0.iter_mut() { 63 for row in state.0.iter_mut() {
63 for item in row.items.iter_mut() { 64 for item in row.items.iter_mut() {
64 if item.item.r#type() 65 if item.item.type_id() == TypeId::of::<SearchFilter>()
65 == "youtube_ratatui::items::searchfilters::SearchFilter"
66 && item.item.mouse_event( 66 && item.item.mouse_event(
67 &mut frameworkclean, 67 &mut frameworkclean,
68 0, 68 0,
@@ -147,17 +147,6 @@ pub fn run(
147 continue; 147 continue;
148 } 148 }
149 149
150 // if something is selected, pass the key input into that item
151 // if nothing is selected, the following big chunk of code handles to movement of
152 // cursor and stuff
153 if framework.is_selected() {
154 if let Err(e) = framework.key_input(key) {
155 *framework.data.global.get_mut::<Message>().unwrap() =
156 Message::Error(e.to_string());
157 };
158 continue;
159 }
160
161 // the first part check for if the keys should be captured for entering commands 150 // the first part check for if the keys should be captured for entering commands
162 if framework 151 if framework
163 .data 152 .data
@@ -180,6 +169,29 @@ pub fn run(
180 continue; 169 continue;
181 } 170 }
182 171
172 // if something is selected, pass the key input into that item
173 // if nothing is selected, the following big chunk of code handles to movement of
174 // cursor and stuff
175 if framework.is_selected() {
176 let (x, y) = framework.cursor.selected(&framework.selectables).unwrap();
177 if let Err(e) = framework.key_input(key) {
178 *framework.data.global.get_mut::<Message>().unwrap() =
179 Message::Error(e.to_string());
180 };
181
182 let selected = framework.state.get_mut(x, y);
183 if framework
184 .data
185 .global
186 .get::<MainConfig>()
187 .unwrap()
188 .legacy_input_handling
189 || (*selected).type_id() == TypeId::of::<SearchBar>()
190 {
191 continue;
192 }
193 }
194
183 if let Some(action) = action { 195 if let Some(action) = action {
184 let mut render = true; 196 let mut render = true;
185 match action { 197 match action {
@@ -192,10 +204,18 @@ pub fn run(
192 .command_capture = Some(TextField::default()); 204 .command_capture = Some(TextField::default());
193 } 205 }
194 KeyAction::Exit => break, 206 KeyAction::Exit => break,
195 KeyAction::MoveUp => framework.r#move(FrameworkDirection::Up)?, 207 KeyAction::MoveUp if !framework.is_selected() => {
196 KeyAction::MoveDown => framework.r#move(FrameworkDirection::Down)?, 208 framework.r#move(FrameworkDirection::Up)?
197 KeyAction::MoveLeft => framework.r#move(FrameworkDirection::Left)?, 209 }
198 KeyAction::MoveRight => framework.r#move(FrameworkDirection::Right)?, 210 KeyAction::MoveDown if !framework.is_selected() => {
211 framework.r#move(FrameworkDirection::Down)?
212 }
213 KeyAction::MoveLeft if !framework.is_selected() => {
214 framework.r#move(FrameworkDirection::Left)?
215 }
216 KeyAction::MoveRight if !framework.is_selected() => {
217 framework.r#move(FrameworkDirection::Right)?
218 }
199 KeyAction::Reload => framework 219 KeyAction::Reload => framework
200 .data 220 .data
201 .state 221 .state
@@ -263,7 +283,7 @@ pub fn run(
263 Message::Success(String::from("History cleared!")) 283 Message::Success(String::from("History cleared!"))
264 } 284 }
265 } 285 }
266 KeyAction::Select => { 286 KeyAction::Select if !framework.is_selected() => {
267 let _ = framework.select(); 287 let _ = framework.select();
268 } 288 }
269 _ => render = false, 289 _ => render = false,