summaryrefslogtreecommitdiffstats
path: root/src/readline.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-11-17 22:29:05 -0500
committerJesse Luehrs <doy@tozt.net>2021-11-17 22:29:05 -0500
commit70f48c3ef7dde34546b6d646818333505d0e4777 (patch)
treedb5d3fd7a2f4cfd168a73e03c8c8272ac375ecc1 /src/readline.rs
parent96f335c58f9b9b9035a43f106f2dfddbe62777e7 (diff)
downloadnbsh-70f48c3ef7dde34546b6d646818333505d0e4777.tar.gz
nbsh-70f48c3ef7dde34546b6d646818333505d0e4777.zip
refactor
Diffstat (limited to 'src/readline.rs')
-rw-r--r--src/readline.rs29
1 files changed, 10 insertions, 19 deletions
diff --git a/src/readline.rs b/src/readline.rs
index 093de3d..529c102 100644
--- a/src/readline.rs
+++ b/src/readline.rs
@@ -6,23 +6,22 @@ pub struct Readline {
prompt: String,
input_line: String,
pos: usize,
- action: async_std::channel::Sender<crate::action::Action>,
}
impl Readline {
- pub fn new(
- action: async_std::channel::Sender<crate::action::Action>,
- ) -> Self {
+ pub fn new() -> Self {
Self {
size: (24, 80),
prompt: "$ ".into(),
input_line: "".into(),
pos: 0,
- action,
}
}
- pub async fn handle_key(&mut self, key: textmode::Key) {
+ pub async fn handle_key(
+ &mut self,
+ key: textmode::Key,
+ ) -> Option<crate::action::Action> {
match key {
textmode::Key::String(s) => self.add_input(&s),
textmode::Key::Char(c) => {
@@ -30,20 +29,15 @@ impl Readline {
}
textmode::Key::Ctrl(b'c') => self.clear_input(),
textmode::Key::Ctrl(b'd') => {
- self.action.send(crate::action::Action::Quit).await.unwrap();
+ return Some(crate::action::Action::Quit);
}
textmode::Key::Ctrl(b'l') => {
- self.action
- .send(crate::action::Action::ForceRedraw)
- .await
- .unwrap();
+ return Some(crate::action::Action::ForceRedraw);
}
textmode::Key::Ctrl(b'm') => {
- self.action
- .send(crate::action::Action::Run(self.input()))
- .await
- .unwrap();
+ let cmd = self.input();
self.clear_input();
+ return Some(crate::action::Action::Run(cmd));
}
textmode::Key::Ctrl(b'u') => self.clear_backwards(),
textmode::Key::Backspace => self.backspace(),
@@ -51,10 +45,7 @@ impl Readline {
textmode::Key::Right => self.cursor_right(),
_ => {}
}
- self.action
- .send(crate::action::Action::Render)
- .await
- .unwrap();
+ Some(crate::action::Action::Render)
}
pub fn lines(&self) -> usize {