summaryrefslogtreecommitdiffstats
path: root/src/state.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-11-17 22:42:51 -0500
committerJesse Luehrs <doy@tozt.net>2021-11-17 22:42:51 -0500
commit7f65b6ae852ea4297fcddcd2e33965c2ddeab063 (patch)
treeca8f55ce390cb03beb0dbd7c107c46542b9da9ac /src/state.rs
parent4025a5fa46ec24902ee1fb2d6764aed872a3d5b7 (diff)
downloadnbsh-7f65b6ae852ea4297fcddcd2e33965c2ddeab063.tar.gz
nbsh-7f65b6ae852ea4297fcddcd2e33965c2ddeab063.zip
reorder some functions
Diffstat (limited to 'src/state.rs')
-rw-r--r--src/state.rs154
1 files changed, 77 insertions, 77 deletions
diff --git a/src/state.rs b/src/state.rs
index 6f17e95..8b08fe4 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -22,6 +22,83 @@ impl State {
}
}
+ pub async fn handle_key(
+ &mut self,
+ key: textmode::Key,
+ ) -> Option<crate::action::Action> {
+ if self.escape {
+ self.escape = false;
+ let mut fallthrough = false;
+ match key {
+ textmode::Key::Ctrl(b'e') => {
+ fallthrough = true;
+ }
+ textmode::Key::Ctrl(b'l') => {
+ return Some(crate::action::Action::ForceRedraw);
+ }
+ textmode::Key::Char('f') => {
+ if let Focus::History(idx) = self.focus {
+ return Some(
+ crate::action::Action::ToggleFullscreen(idx),
+ );
+ }
+ }
+ textmode::Key::Char('j') => {
+ let new_focus = match self.focus {
+ Focus::History(idx) => {
+ if idx >= self.history.entry_count() - 1 {
+ Focus::Readline
+ } else {
+ Focus::History(idx + 1)
+ }
+ }
+ Focus::Readline => Focus::Readline,
+ };
+ return Some(crate::action::Action::UpdateFocus(
+ new_focus,
+ ));
+ }
+ textmode::Key::Char('k') => {
+ let new_focus = match self.focus {
+ Focus::History(idx) => {
+ if idx == 0 {
+ Focus::History(0)
+ } else {
+ Focus::History(idx - 1)
+ }
+ }
+ Focus::Readline => {
+ Focus::History(self.history.entry_count() - 1)
+ }
+ };
+ return Some(crate::action::Action::UpdateFocus(
+ new_focus,
+ ));
+ }
+ textmode::Key::Char('r') => {
+ return Some(crate::action::Action::UpdateFocus(
+ Focus::Readline,
+ ));
+ }
+ _ => {}
+ }
+ if !fallthrough {
+ return None;
+ }
+ } else if key == textmode::Key::Ctrl(b'e') {
+ self.escape = true;
+ return None;
+ }
+
+ match self.focus {
+ Focus::Readline => self.readline.handle_key(key).await,
+ Focus::History(idx) => {
+ self.history.handle_key(key, idx).await;
+ None
+ }
+ }
+ }
+
pub async fn render(
&self,
out: &mut textmode::Output,
@@ -99,83 +176,6 @@ impl State {
}
}
}
-
- pub async fn handle_key(
- &mut self,
- key: textmode::Key,
- ) -> Option<crate::action::Action> {
- if self.escape {
- self.escape = false;
- let mut fallthrough = false;
- match key {
- textmode::Key::Ctrl(b'e') => {
- fallthrough = true;
- }
- textmode::Key::Ctrl(b'l') => {
- return Some(crate::action::Action::ForceRedraw);
- }
- textmode::Key::Char('f') => {
- if let Focus::History(idx) = self.focus {
- return Some(
- crate::action::Action::ToggleFullscreen(idx),
- );
- }
- }
- textmode::Key::Char('j') => {
- let new_focus = match self.focus {
- Focus::History(idx) => {
- if idx >= self.history.entry_count() - 1 {
- Focus::Readline
- } else {
- Focus::History(idx + 1)
- }
- }
- Focus::Readline => Focus::Readline,
- };
- return Some(crate::action::Action::UpdateFocus(
- new_focus,
- ));
- }
- textmode::Key::Char('k') => {
- let new_focus = match self.focus {
- Focus::History(idx) => {
- if idx == 0 {
- Focus::History(0)
- } else {
- Focus::History(idx - 1)
- }
- }
- Focus::Readline => {
- Focus::History(self.history.entry_count() - 1)
- }
- };
- return Some(crate::action::Action::UpdateFocus(
- new_focus,
- ));
- }
- textmode::Key::Char('r') => {
- return Some(crate::action::Action::UpdateFocus(
- Focus::Readline,
- ));
- }
- _ => {}
- }
- if !fallthrough {
- return None;
- }
- } else if key == textmode::Key::Ctrl(b'e') {
- self.escape = true;
- return None;
- }
-
- match self.focus {
- Focus::Readline => self.readline.handle_key(key).await,
- Focus::History(idx) => {
- self.history.handle_key(key, idx).await;
- None
- }
- }
- }
}
#[derive(Copy, Clone, Debug)]