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"
11641164
11651165[[package]]
11661166name = "tui-additions"
1167version = "0.2.0"
1167version = "0.2.1"
11681168source = "registry+https://github.com/rust-lang/crates.io-index"
1169checksum = "8e7718181edae897f9e740d9e38c6b4d6961b2172a90bd7ba5d0a0c206a040b5"
1169checksum = "1de5841ec45de71c46252a832bb1e3e69abf2ee2492eb309ea077c8d78e798e7"
11701170dependencies = [
11711171 "crossterm 0.26.1",
11721172 "dyn-clone",
Cargo.toml +1 −1
@@ -28,7 +28,7 @@ viuer = {version = "0.6", default-features = false, optional = true}
2828home = "0.5"
2929chrono = {version = "0.4", default-features = false, features = ["clock"]}
3030typemap = {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"]}
3232invidious = {version = "0.5"}
3333serde_yaml = {version = "0.9", default-features = false}
3434dyn-clone = {version = "1.0", default-features = false}
docs/src/changelogs.md +11
@@ -1,5 +1,16 @@
11# Changelogs
22
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
314## v0.7.3 (latest stable on crates.io)
415
516### Added
src/config/main.rs +7
@@ -32,6 +32,8 @@ pub struct MainConfig {
3232 pub provider: Provider,
3333 #[serde(default = "shell_default")]
3434 pub shell: String,
35 #[serde(default = "legacy_input_handling_default")]
36 pub legacy_input_handling: bool,
3537 #[serde(default = "default_env")]
3638 pub env: HashMap<String, String>,
3739}
@@ -56,6 +58,7 @@ impl Default for MainConfig {
5658 syncing: sync_config_default(),
5759 provider: provider_default(),
5860 shell: shell_default(),
61 legacy_input_handling: legacy_input_handling_default(),
5962
6063 env: default_env(),
6164 }
@@ -215,3 +218,7 @@ const fn sync_channel_cooldown_secs_default() -> u64 {
215218const fn sync_videos_cooldown_secs_default() -> u64 {
216219 600
217220}
221
222const fn legacy_input_handling_default() -> bool {
223 false
224}
src/run.rs +39 −19
@@ -1,6 +1,6 @@
11use crossterm::event::{self, Event, MouseButton, MouseEventKind};
22use ratatui::{backend::CrosstermBackend, Terminal};
3use std::{error::Error, io::Stdout};
3use std::{any::TypeId, error::Error, io::Stdout};
44use tui_additions::{
55 framework::{Framework, FrameworkDirection},
66 widgets::TextField,
@@ -9,6 +9,7 @@ use tui_additions::{
99use crate::{
1010 config::*,
1111 global::{functions::*, structs::*},
12 items::{SearchBar, SearchFilter},
1213};
1314
1415/// the main event loop of the program
@@ -61,8 +62,7 @@ pub fn run(
6162 let (mut frameworkclean, state) = framework.split_clean();
6263 for row in state.0.iter_mut() {
6364 for item in row.items.iter_mut() {
64 if item.item.r#type()
65 == "youtube_ratatui::items::searchfilters::SearchFilter"
65 if item.item.type_id() == TypeId::of::<SearchFilter>()
6666 && item.item.mouse_event(
6767 &mut frameworkclean,
6868 0,
@@ -147,17 +147,6 @@ pub fn run(
147147 continue;
148148 }
149149
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
161150 // the first part check for if the keys should be captured for entering commands
162151 if framework
163152 .data
@@ -180,6 +169,29 @@ pub fn run(
180169 continue;
181170 }
182171
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
183195 if let Some(action) = action {
184196 let mut render = true;
185197 match action {
@@ -192,10 +204,18 @@ pub fn run(
192204 .command_capture = Some(TextField::default());
193205 }
194206 KeyAction::Exit => break,
195 KeyAction::MoveUp => framework.r#move(FrameworkDirection::Up)?,
196 KeyAction::MoveDown => framework.r#move(FrameworkDirection::Down)?,
197 KeyAction::MoveLeft => framework.r#move(FrameworkDirection::Left)?,
198 KeyAction::MoveRight => framework.r#move(FrameworkDirection::Right)?,
207 KeyAction::MoveUp if !framework.is_selected() => {
208 framework.r#move(FrameworkDirection::Up)?
209 }
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 }
199219 KeyAction::Reload => framework
200220 .data
201221 .state
@@ -263,7 +283,7 @@ pub fn run(
263283 Message::Success(String::from("History cleared!"))
264284 }
265285 }
266 KeyAction::Select => {
286 KeyAction::Select if !framework.is_selected() => {
267287 let _ = framework.select();
268288 }
269289 _ => render = false,