Commit dcb033702a

dcb033702a74c154afb5f727664cea0ad1e9645e

parent: d0e04a92b3

Unsigned

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

previous/next word in textfield, `key` command, auto focus on page load

Layout: unified · split

README.md +2 −2
@@ -77,9 +77,9 @@ It also includes features like:
7777### What it doesn't have
7878
7979- [URGENT] Replace the no-longer-going-to-compile `typemap` dependency with either a self implementation of it or a useable crate.
80- Strip down some libraries to reduce compile speed.
80- Strip down some libraries to reduce compile speed, specifically removing.
8181- Add command section for channel main page (first priority)
82- Up arrow command history + Ctrl arrow keys move between words
82- Add NewPipe as a source alongside Invidious
8383
8484## How to contribute
8585
docs/src/commands.md +5
@@ -42,6 +42,7 @@ flush
4242quit (alt `q`, `exit`, `x`)
4343run [command]
4444parrun [command]
45key [keycode] [keymodifier]
4546```
4647
4748> The `flush` command is used to run all tasks in queue immediately, this is usually done automatically.
@@ -50,6 +51,10 @@ parrun [command]
5051
5152> `run` is used for running *blocking commands*, while `parrun` is non-blocking.
5253
54> Valid keycodes are the same as in [`keybindings.yml`](./config/keybindings.md) and [`commandbindings.yml`](./config/commandbindings.md). For a full list of keys, check out [`KeyCodeSerde`](https://docs.rs/youtube-tui/latest/youtube_tui/config/serde/enum.KeyCodeSerde.html) in [`/src/config/serde.rs`](https://github.com/Siriusmart/youtube-tui/blob/master/src/config/serde.rs).
55>
56> More about keymodifiers can be found in the doc page for [`keybindings.yml`](./config/keybindings.md)
57
5358## Library
5459
5560```vim
docs/src/config/keybindings.md +3 −3
@@ -58,9 +58,9 @@ Each modifier has its own code, for instance `Shift` would be `1` and `Ctrl` wou
5858
5959All possible keys can be found <a href="https://docs.rs/crossterm/latest/crossterm/event/enum.KeyCode.html" target=_blank>*here*</a>.
6060
61> Enums are represented using the character `!`, for example the `q` key would be `!Char 'q'`
62>
63> `Shift + Q` however would be `!Char 'Q'` with `0` as modifier code as `Shift` turns `q` into an upper case character.
61### Key actions
62
63All key actions can be found in [`KeyAction`](https://docs.rs/youtube-tui/latest/youtube_tui/global/structs/enum.KeyAction.html) under [`/src/global/structs/keyaction.rs`](https://github.com/Siriusmart/youtube-tui/blob/master/src/global/structs/keyaction.rs).
6464
6565### Modifiers reference
6666
docs/src/config/main.md +35 −1
@@ -82,6 +82,30 @@ Whether to refresh the current search page after search filters are modified
8282
8383*Accept: `true`/`false`*
8484
85### download_images
86
87Whether to download images for all subscription videos
88
89*Accept: `true`/`false`*
90
91### sync_channel_info
92
93Whether to also request an updated version of the channel info when syncing feeds. Disabling this halves the number of requests sent to Invidious, but channel info will not be updated (the videos will).
94
95*Accept: `true`/`false`*
96
97### sync_channel_cooldown_secs
98
99Sync all do not sync channel info if it has been synced in the past *n* seconds.
100
101*Accept: integer value seconds*
102
103### sync_videos_cooldown_secs
104
105Sync all do not sync videos from channel if it has been synced in the past *n* seconds.
106
107*Accept: integer value seconds*
108
85109### image_index
86110
87111The index in the array of thumbnail qualities you want to download
@@ -104,7 +128,7 @@ Usually you don't want to use the max resolution as it will create a large gap b
104128
105129*Accept: integer that is a valid index*
106130
107### Provider
131### provider
108132
109133This changes the `${url}` and `${embed-url}` of videos, allowing you to watch videos from Invidious if it is restricted on YouTube.
110134
@@ -112,6 +136,16 @@ This changes the `${url}` and `${embed-url}` of videos, allowing you to watch vi
112136
113137*Accept: `YouTube`/`Invidious`*
114138
139### shell
140
141Shell used to run commands, such as `sh` (default), `bash` or even `zsh`.
142
143*Accept: any valid path to a shell binary*
144
145### legacy_input_handling
146
147Switch back the old key input handling where the selected item captures all input (except escape).
148
115149### env
116150
117151Env are variables that can be used in `commands.yml`, this allows you to change multiple commands by modifying just one env variable. And not to be confused with system/terminal environment variables, these are just *"a thing"* that you can use in the TUI.
docs/src/config/pages.md +5
@@ -23,6 +23,7 @@ main_menu:
2323 items:
2424 - MessageBar
2525 message: Loading main menu...
26 command: key Esc 0 ;; key Up 0 ;; key Left 0 ;; key Enter 0 # this focuses on the search bar
2627
2728# and much more ...
2829```
@@ -43,6 +44,10 @@ Each item are ordered from left to right.
4344
4445The message to display when loading the page.
4546
47## Command
48
49Command to run when the page loads, you can use the `key` command to select an item on load.
50
4651### Items reference
4752
4853|Item|Can be used in page|Description|
src/config/keybindings.rs +8 −3
@@ -39,14 +39,19 @@ impl ConfigTrait for KeyBindingsConfigSerde {
3939impl Default for KeyBindingsConfigSerde {
4040 fn default() -> Self {
4141 Self(HashMap::from([
42 // movement keys // Alt left should be back
42 // movement keys
43 // Alt left should be back
4344 (
4445 KeyCodeSerde::KeyVariants(KeyVariantsSerde::Left),
45 HashMap::from([(0, KeyAction::MoveLeft), (4, KeyAction::Back)]),
46 HashMap::from([
47 (0, KeyAction::MoveLeft),
48 (2, KeyAction::PreviousWord),
49 (4, KeyAction::Back),
50 ]),
4651 ),
4752 (
4853 KeyCodeSerde::KeyVariants(KeyVariantsSerde::Right),
49 HashMap::from([(0, KeyAction::MoveRight)]),
54 HashMap::from([(0, KeyAction::MoveRight), (2, KeyAction::NextWord)]),
5055 ),
5156 (
5257 KeyCodeSerde::KeyVariants(KeyVariantsSerde::Up),
src/config/pages.rs +6
@@ -66,6 +66,7 @@ impl Default for PagesConfig {
6666pub struct PageConfig {
6767 pub layout: Vec<PageRow>,
6868 pub message: String,
69 pub command: String,
6970}
7071
7172impl PageConfig {
@@ -290,6 +291,7 @@ fn main_menu_default() -> PageConfig {
290291 PageRow::from_vec(vec![PageItems::MessageBar], false),
291292 ],
292293 message: String::from("Loading main menu..."),
294 command: String::from("key Esc 0 ;; key Up 0 ;; key Left 0 ;; key Enter 0"),
293295 }
294296}
295297
@@ -301,6 +303,7 @@ fn search_default() -> PageConfig {
301303 PageRow::from_vec(vec![PageItems::MessageBar], false),
302304 ],
303305 message: String::from("Loading search results..."),
306 command: String::from("key Esc 0 ;; key Down 0 ;; key Enter 0"),
304307 }
305308}
306309
@@ -312,6 +315,7 @@ fn singleitem_default() -> PageConfig {
312315 PageRow::from_vec(vec![PageItems::MessageBar], false),
313316 ],
314317 message: String::from("Loading item details..."),
318 command: String::from("key Esc 0 ;; key Down 0 ;; key Enter 0"),
315319 }
316320}
317321
@@ -331,6 +335,7 @@ fn channeldisplay_default() -> PageConfig {
331335 PageRow::from_vec(vec![PageItems::MessageBar], false),
332336 ],
333337 message: String::from("Loading channel details..."),
338 command: String::from("key Esc 0 ;; key Down 0 ;; key Enter 0"),
334339 }
335340}
336341
@@ -347,5 +352,6 @@ fn feed_default() -> PageConfig {
347352 PageRow::from_vec(vec![PageItems::MessageBar], false),
348353 ],
349354 message: String::from("Loading feed..."),
355 command: String::from("key Esc 0 ;; key Down 0 ;; key Down 0 ;; key Enter 0"),
350356 }
351357}
src/config/serde.rs +2 −2
@@ -123,7 +123,7 @@ fn from_hex_digit(d: &str) -> Option<u8> {
123123}
124124
125125/// serde version of a single key code
126#[derive(Serialize, Deserialize, Clone, Hash, PartialEq, Eq)]
126#[derive(Serialize, Deserialize, Clone, Hash, PartialEq, Eq, Debug)]
127127#[serde(untagged)]
128128pub enum KeyCodeSerde {
129129 Char(char),
@@ -132,7 +132,7 @@ pub enum KeyCodeSerde {
132132}
133133
134134/// values of all default keys (excluding chars and function keys)
135#[derive(Serialize, Deserialize, Clone, Hash, PartialEq, Eq)]
135#[derive(Serialize, Deserialize, Clone, Hash, PartialEq, Eq, Debug)]
136136pub enum KeyVariantsSerde {
137137 Backspace,
138138 Enter,
src/global/functions/command_capture.rs +40
@@ -66,6 +66,46 @@ pub fn command_capture(framework: &mut FrameworkClean, key: KeyEvent) -> bool {
6666 .clear();
6767 return true;
6868 }
69 Some(KeyAction::PreviousWord) => {
70 previous_word(
71 framework
72 .data
73 .global
74 .get_mut::<Status>()
75 .unwrap()
76 .command_capture
77 .as_mut()
78 .unwrap(),
79 );
80 framework
81 .data
82 .state
83 .get_mut::<Tasks>()
84 .unwrap()
85 .priority
86 .push(Task::RenderAll);
87 return true;
88 }
89 Some(KeyAction::NextWord) => {
90 next_word(
91 framework
92 .data
93 .global
94 .get_mut::<Status>()
95 .unwrap()
96 .command_capture
97 .as_mut()
98 .unwrap(),
99 );
100 framework
101 .data
102 .state
103 .get_mut::<Tasks>()
104 .unwrap()
105 .priority
106 .push(Task::RenderAll);
107 return true;
108 }
69109 _ => {}
70110 }
71111
src/global/functions/key_input.rs added +214
@@ -0,0 +1,214 @@
1use std::{any::TypeId, io::Stdout};
2
3use crossterm::event::KeyEvent;
4use ratatui::{backend::CrosstermBackend, Terminal};
5use tui_additions::{
6 framework::{Framework, FrameworkDirection},
7 widgets::TextField,
8};
9
10use crate::{config::*, global::structs::*, items::SearchBar};
11
12use super::*;
13
14pub fn key_input(
15 key: KeyEvent,
16 framework: &mut Framework,
17 terminal: &mut Terminal<CrosstermBackend<Stdout>>,
18) {
19 // check if key binds to any commands
20 let command_to_run = framework
21 .data
22 .global
23 .get::<CommandBindings>()
24 .unwrap()
25 .get_command(&key, framework.data.state.get::<Page>().unwrap());
26 if !command_to_run.is_empty() {
27 run_command(&apply_envs(command_to_run), framework, terminal);
28 framework
29 .data
30 .state
31 .get_mut::<Tasks>()
32 .unwrap()
33 .priority
34 .push(Task::RenderAll);
35 }
36
37 // 1. get the corresponding action
38 // 2. check if action is deselect, if yes, deselect
39 // 3. check is anything is selected, if yes, run `.key_event()` with the key
40 // 4. if nothing is selected, do stuff like moving the cursor or exiting
41
42 let action = framework
43 .data
44 .global
45 .get::<KeyBindingsConfig>()
46 .unwrap()
47 .get(key);
48
49 if action == Some(KeyAction::Deselect) {
50 let _ = framework.deselect();
51 framework
52 .data
53 .state
54 .get_mut::<Tasks>()
55 .unwrap()
56 .priority
57 .push(Task::RenderAll);
58 framework
59 .data
60 .global
61 .get_mut::<Status>()
62 .unwrap()
63 .command_capture = None;
64 return;
65 }
66
67 // the first part check for if the keys should be captured for entering commands
68 if framework
69 .data
70 .global
71 .get::<Status>()
72 .unwrap()
73 .command_capture
74 .is_some()
75 // the second part runs the command, and see if the returned boolean
76 // `is_updated` is true, if so update the screen
77 && command_capture(&mut framework.split_clean().0, key)
78 {
79 framework
80 .data
81 .state
82 .get_mut::<Tasks>()
83 .unwrap()
84 .priority
85 .push(Task::RenderAll);
86 return;
87 }
88
89 // if something is selected, pass the key input into that item
90 // if nothing is selected, the following big chunk of code handles to movement of
91 // cursor and stuff
92 if framework.is_selected() {
93 let (x, y) = framework.cursor.selected(&framework.selectables).unwrap();
94 if let Err(e) = framework.key_input(key) {
95 *framework.data.global.get_mut::<Message>().unwrap() = Message::Error(e.to_string());
96 };
97
98 let selected = framework.state.get_mut(x, y);
99 if framework
100 .data
101 .global
102 .get::<MainConfig>()
103 .unwrap()
104 .legacy_input_handling
105 || (*selected).type_id() == TypeId::of::<SearchBar>()
106 {
107 return;
108 }
109 }
110
111 if let Some(action) = action {
112 let mut render = true;
113 match action {
114 KeyAction::StartCommandCapture => {
115 framework
116 .data
117 .global
118 .get_mut::<Status>()
119 .unwrap()
120 .command_capture = Some(TextField::default());
121 }
122 KeyAction::Exit => framework
123 .data
124 .state
125 .get_mut::<Tasks>()
126 .unwrap()
127 .priority
128 .push(Task::Command("q".to_string())),
129 KeyAction::MoveUp if !framework.is_selected() => {
130 let _ = framework.r#move(FrameworkDirection::Up);
131 }
132 KeyAction::MoveDown if !framework.is_selected() => {
133 let _ = framework.r#move(FrameworkDirection::Down);
134 }
135 KeyAction::MoveLeft if !framework.is_selected() => {
136 let _ = framework.r#move(FrameworkDirection::Left);
137 }
138 KeyAction::MoveRight if !framework.is_selected() => {
139 let _ = framework.r#move(FrameworkDirection::Right);
140 }
141 KeyAction::Reload => framework
142 .data
143 .state
144 .get_mut::<Tasks>()
145 .unwrap()
146 .priority
147 .push(Task::Reload),
148 KeyAction::Back => {
149 if !framework.history.is_empty() {
150 clear_envs(&mut framework.data.state.get::<StateEnvs>().unwrap().0.clone());
151 }
152 if framework.revert_last_history().is_err() {
153 *framework.data.global.get_mut::<Message>().unwrap() =
154 Message::Error(String::from("This is already the beginning of history"))
155 } else {
156 let status = framework.data.global.get_mut::<Status>().unwrap();
157 status.render_image = true;
158
159 framework
160 .data
161 .state
162 .get_mut::<Tasks>()
163 .unwrap()
164 .priority
165 .push(Task::ClearPage);
166 let state_envs = framework.data.state.get_mut::<StateEnvs>().unwrap();
167 set_envs(state_envs.clone().0.into_iter(), &mut state_envs.0);
168 update_provider(&mut framework.data);
169 }
170 }
171 KeyAction::FirstHistory => {
172 if framework.revert_history(0).is_err() {
173 *framework.data.global.get_mut::<Message>().unwrap() =
174 Message::Error(String::from("This is already the beginning of history"))
175 } else {
176 let status = framework.data.global.get_mut::<Status>().unwrap();
177 status.render_image = true;
178
179 update_provider(&mut framework.data);
180 framework
181 .data
182 .state
183 .get_mut::<Tasks>()
184 .unwrap()
185 .priority
186 .push(Task::ClearPage);
187 }
188 }
189 KeyAction::ClearHistory => {
190 if framework.history.is_empty() {
191 *framework.data.global.get_mut::<Message>().unwrap() =
192 Message::Error(String::from("This is already the beginning of history"))
193 } else {
194 framework.clear_history();
195 *framework.data.global.get_mut::<Message>().unwrap() =
196 Message::Success(String::from("History cleared!"))
197 }
198 }
199 KeyAction::Select if !framework.is_selected() => {
200 let _ = framework.select();
201 }
202 _ => render = false,
203 }
204 if render {
205 framework
206 .data
207 .state
208 .get_mut::<Tasks>()
209 .unwrap()
210 .priority
211 .push(Task::RenderAll);
212 }
213 }
214}
src/global/functions/mod.rs +2
@@ -31,3 +31,5 @@ mod singleitem_load;
3131pub use singleitem_load::*;
3232mod remove_word;
3333pub use remove_word::*;
34mod key_input;
35pub use key_input::*;
src/global/functions/remove_word.rs +29
@@ -17,3 +17,32 @@ pub fn remove_word(field: &mut TextField) {
1717 field.content = format!("{}{}", before, &field.content[field.cursor..]);
1818 field.cursor = before.len();
1919}
20
21pub fn previous_word(field: &mut TextField) {
22 let bytes = field.content.as_bytes();
23 while field.cursor != 0 {
24 field.cursor -= 1;
25 if bytes[field.cursor].is_ascii_whitespace() {
26 return;
27 }
28 }
29
30 field.cursor = 0;
31}
32
33pub fn next_word(field: &mut TextField) {
34 let bytes = field.content.as_bytes();
35 for (i, c) in bytes
36 .iter()
37 .enumerate()
38 .take(field.content.len())
39 .skip(field.cursor + 1)
40 {
41 if c.is_ascii_whitespace() {
42 field.cursor = i;
43 return;
44 }
45 }
46
47 field.cursor = field.content.len();
48}
src/global/functions/run_command.rs +26 −1
@@ -1,8 +1,9 @@
11use crate::{
2 config::*,
2 config::{serde::KeyCodeSerde, *},
33 global::{functions::*, structs::*, traits::*},
44 load_configs,
55};
6use crossterm::event::{KeyEvent, KeyModifiers};
67use home::home_dir;
78use ratatui::{backend::CrosstermBackend, Terminal};
89use std::{
@@ -475,6 +476,29 @@ pub fn run_single_command(
475476 .priority
476477 .push(Task::RenderAll);
477478 }
479 ["key", keycode, modifier] => {
480 let (keycodeserde, modifier) =
481 match (|| -> Result<(KeyCodeSerde, u8), Box<dyn Error>> {
482 Ok((serde_yaml::from_str(keycode)?, modifier.parse()?))
483 })() {
484 Ok(stuff) => stuff,
485 Err(e) => {
486 *framework.data.global.get_mut::<Message>().unwrap() =
487 Message::Error(format!("Cannot parse keycode: `{e}`"));
488 return;
489 }
490 };
491 let keycode = match keycodeserde.to_keycode() {
492 Some(code) => code,
493 None => {
494 *framework.data.global.get_mut::<Message>().unwrap() =
495 Message::Error("Unknown keycode".to_string());
496 return;
497 }
498 };
499 let keymodifier = KeyModifiers::from_bits_truncate(modifier);
500 key_input(KeyEvent::new(keycode, keymodifier), framework, terminal)
501 }
478502 _ => {
479503 *framework.data.global.get_mut::<Message>().unwrap() =
480504 Message::Error(format!("Unknown command: `{}`", command.join(" ")));
@@ -550,6 +574,7 @@ const HELP_MSG: &str = "\x1b[32mYouTube TUI commands\x1b[0m
550574 \x1b[33mrun [command]\x1b[0m Runs a system command (e.g. `run rm -rf / --no-preserve-root`)
551575 \x1b[33mparrun [command]\x1b[0m Runs a system command non blocking (e.g. `run firefox example.com`)
552576 \x1b[33mcopy [text]\x1b[0m Copies text to clipboard
577 \x1b[33mkey [keycode] [keymodifier]\x1b[0m Create a key input event
553578
554579\x1b[91mLIBRARY:\x1b[0m
555580 \x1b[33mbookmark [id]\x1b[0m Bookmark item with ID (item must be already loaded)
src/global/structs/keyaction.rs +4
@@ -34,4 +34,8 @@ pub enum KeyAction {
3434 RemoveWord,
3535 /// removes all content in textfield
3636 ClearLine,
37 /// move cursor to previous word in textfield
38 PreviousWord,
39 /// move cursor to next word in textfield
40 NextWord,
3741}
src/global/structs/tasks.rs +1
@@ -141,6 +141,7 @@ impl TaskQueue {
141141 status.provider_updated = true;
142142 status.render_image = true;
143143 self.render = RenderTask::All;
144 run_command(&page_config.command, framework, terminal);
144145 }
145146
146147 if self.reload {
src/items/searchbar.rs +22
@@ -124,6 +124,28 @@ impl FrameworkItem for SearchBar {
124124 .push(Task::RenderAll);
125125 return Ok(());
126126 }
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 }
127149 Some(KeyAction::ClearLine) => {
128150 self.text_field.content.clear();
129151 self.text_field.scroll = 0;
src/run.rs +3 −206
@@ -1,15 +1,12 @@
11use crossterm::event::{self, Event, MouseButton, MouseEventKind};
22use ratatui::{backend::CrosstermBackend, Terminal};
33use std::{any::TypeId, error::Error, io::Stdout};
4use tui_additions::{
5 framework::{Framework, FrameworkDirection},
6 widgets::TextField,
7};
4use tui_additions::framework::Framework;
85
96use crate::{
107 config::*,
118 global::{functions::*, structs::*},
12 items::{SearchBar, SearchFilter},
9 items::SearchFilter,
1310};
1411
1512/// the main event loop of the program
@@ -98,207 +95,7 @@ pub fn run(
9895 .push(Task::RenderAll);
9996 }
10097 }
101 Event::Key(key) => {
102 // check if key binds to any commands
103 let command_to_run = framework
104 .data
105 .global
106 .get::<CommandBindings>()
107 .unwrap()
108 .get_command(&key, framework.data.state.get::<Page>().unwrap());
109 if !command_to_run.is_empty() {
110 run_command(&apply_envs(command_to_run), framework, terminal);
111 framework
112 .data
113 .state
114 .get_mut::<Tasks>()
115 .unwrap()
116 .priority
117 .push(Task::RenderAll);
118 }
119
120 // 1. get the corresponding action
121 // 2. check if action is deselect, if yes, deselect
122 // 3. check is anything is selected, if yes, run `.key_event()` with the key
123 // 4. if nothing is selected, do stuff like moving the cursor or exiting
124
125 let action = framework
126 .data
127 .global
128 .get::<KeyBindingsConfig>()
129 .unwrap()
130 .get(key);
131
132 if action == Some(KeyAction::Deselect) {
133 let _ = framework.deselect();
134 framework
135 .data
136 .state
137 .get_mut::<Tasks>()
138 .unwrap()
139 .priority
140 .push(Task::RenderAll);
141 framework
142 .data
143 .global
144 .get_mut::<Status>()
145 .unwrap()
146 .command_capture = None;
147 continue;
148 }
149
150 // the first part check for if the keys should be captured for entering commands
151 if framework
152 .data
153 .global
154 .get::<Status>()
155 .unwrap()
156 .command_capture
157 .is_some()
158 // the second part runs the command, and see if the returned boolean
159 // `is_updated` is true, if so update the screen
160 && command_capture(&mut framework.split_clean().0, key)
161 {
162 framework
163 .data
164 .state
165 .get_mut::<Tasks>()
166 .unwrap()
167 .priority
168 .push(Task::RenderAll);
169 continue;
170 }
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
195 if let Some(action) = action {
196 let mut render = true;
197 match action {
198 KeyAction::StartCommandCapture => {
199 framework
200 .data
201 .global
202 .get_mut::<Status>()
203 .unwrap()
204 .command_capture = Some(TextField::default());
205 }
206 KeyAction::Exit => break,
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 }
219 KeyAction::Reload => framework
220 .data
221 .state
222 .get_mut::<Tasks>()
223 .unwrap()
224 .priority
225 .push(Task::Reload),
226 KeyAction::Back => {
227 if !framework.history.is_empty() {
228 clear_envs(
229 &mut framework.data.state.get::<StateEnvs>().unwrap().0.clone(),
230 );
231 }
232 if framework.revert_last_history().is_err() {
233 *framework.data.global.get_mut::<Message>().unwrap() =
234 Message::Error(String::from(
235 "This is already the beginning of history",
236 ))
237 } else {
238 let status = framework.data.global.get_mut::<Status>().unwrap();
239 status.render_image = true;
240
241 framework
242 .data
243 .state
244 .get_mut::<Tasks>()
245 .unwrap()
246 .priority
247 .push(Task::ClearPage);
248 let state_envs =
249 framework.data.state.get_mut::<StateEnvs>().unwrap();
250 set_envs(state_envs.clone().0.into_iter(), &mut state_envs.0);
251 update_provider(&mut framework.data);
252 }
253 }
254 KeyAction::FirstHistory => {
255 if framework.revert_history(0).is_err() {
256 *framework.data.global.get_mut::<Message>().unwrap() =
257 Message::Error(String::from(
258 "This is already the beginning of history",
259 ))
260 } else {
261 let status = framework.data.global.get_mut::<Status>().unwrap();
262 status.render_image = true;
263
264 update_provider(&mut framework.data);
265 framework
266 .data
267 .state
268 .get_mut::<Tasks>()
269 .unwrap()
270 .priority
271 .push(Task::ClearPage);
272 }
273 }
274 KeyAction::ClearHistory => {
275 if framework.history.is_empty() {
276 *framework.data.global.get_mut::<Message>().unwrap() =
277 Message::Error(String::from(
278 "This is already the beginning of history",
279 ))
280 } else {
281 framework.clear_history();
282 *framework.data.global.get_mut::<Message>().unwrap() =
283 Message::Success(String::from("History cleared!"))
284 }
285 }
286 KeyAction::Select if !framework.is_selected() => {
287 let _ = framework.select();
288 }
289 _ => render = false,
290 }
291 if render {
292 framework
293 .data
294 .state
295 .get_mut::<Tasks>()
296 .unwrap()
297 .priority
298 .push(Task::RenderAll);
299 }
300 }
301 }
98 Event::Key(key) => key_input(key, framework, terminal),
30299 // always render if there is a screen resize event
303100 Event::Resize(_, _) => {
304101 framework