| @@ -1,6 +1,6 @@ |
| 1 | 1 | use crossterm::event::{self, Event, MouseButton, MouseEventKind}; |
| 2 | 2 | use ratatui::{backend::CrosstermBackend, Terminal}; |
| 3 | | use std::{error::Error, io::Stdout}; |
| 3 | use std::{any::TypeId, error::Error, io::Stdout}; |
| 4 | 4 | use tui_additions::{ |
| 5 | 5 | framework::{Framework, FrameworkDirection}, |
| 6 | 6 | widgets::TextField, |
| @@ -9,6 +9,7 @@ use tui_additions::{ |
| 9 | 9 | use crate::{ |
| 10 | 10 | config::*, |
| 11 | 11 | global::{functions::*, structs::*}, |
| 12 | items::{SearchBar, SearchFilter}, |
| 12 | 13 | }; |
| 13 | 14 | |
| 14 | 15 | /// the main event loop of the program |
| @@ -61,8 +62,7 @@ pub fn run( |
| 61 | 62 | let (mut frameworkclean, state) = framework.split_clean(); |
| 62 | 63 | for row in state.0.iter_mut() { |
| 63 | 64 | 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>() |
| 66 | 66 | && item.item.mouse_event( |
| 67 | 67 | &mut frameworkclean, |
| 68 | 68 | 0, |
| @@ -147,17 +147,6 @@ pub fn run( |
| 147 | 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 | 150 | // the first part check for if the keys should be captured for entering commands |
| 162 | 151 | if framework |
| 163 | 152 | .data |
| @@ -180,6 +169,29 @@ pub fn run( |
| 180 | 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 | 195 | if let Some(action) = action { |
| 184 | 196 | let mut render = true; |
| 185 | 197 | match action { |
| @@ -192,10 +204,18 @@ pub fn run( |
| 192 | 204 | .command_capture = Some(TextField::default()); |
| 193 | 205 | } |
| 194 | 206 | 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 | } |
| 199 | 219 | KeyAction::Reload => framework |
| 200 | 220 | .data |
| 201 | 221 | .state |
| @@ -263,7 +283,7 @@ pub fn run( |
| 263 | 283 | Message::Success(String::from("History cleared!")) |
| 264 | 284 | } |
| 265 | 285 | } |
| 266 | | KeyAction::Select => { |
| 286 | KeyAction::Select if !framework.is_selected() => { |
| 267 | 287 | let _ = framework.select(); |
| 268 | 288 | } |
| 269 | 289 | _ => render = false, |