diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-01-03 06:44:23 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-01-03 07:05:53 -0500 |
commit | 6c79e520f02e7d05f389db5856fda250437a563f (patch) | |
tree | b0357b5ca41439e7a2ff59602febc4dbf2d0ca35 /src/state | |
parent | ae132f478c6cfc6ffb062fecd7efb42ac4e5d804 (diff) | |
download | nbsh-6c79e520f02e7d05f389db5856fda250437a563f.tar.gz nbsh-6c79e520f02e7d05f389db5856fda250437a563f.zip |
more clone cleanups
Diffstat (limited to 'src/state')
-rw-r--r-- | src/state/history/mod.rs | 34 | ||||
-rw-r--r-- | src/state/mod.rs | 8 | ||||
-rw-r--r-- | src/state/readline.rs | 4 |
3 files changed, 22 insertions, 24 deletions
diff --git a/src/state/history/mod.rs b/src/state/history/mod.rs index a7b5d88..3573a1c 100644 --- a/src/state/history/mod.rs +++ b/src/state/history/mod.rs @@ -87,17 +87,22 @@ impl History { pub async fn run( &mut self, - ast: &crate::parse::Commands, + ast: crate::parse::Commands, event_w: async_std::channel::Sender<crate::event::Event>, ) -> anyhow::Result<usize> { let (input_w, input_r) = async_std::channel::unbounded(); let (resize_w, resize_r) = async_std::channel::unbounded(); let entry = async_std::sync::Arc::new(async_std::sync::Mutex::new( - Entry::new(Ok(ast.clone()), self.size, input_w, resize_w), + Entry::new( + ast.input_string().to_string(), + self.size, + input_w, + resize_w, + ), )); run_commands( - ast.clone(), + ast, async_std::sync::Arc::clone(&entry), crate::env::Env::new(0), input_r, @@ -123,7 +128,8 @@ impl History { resize_r.close(); let err_str = format!("{}", e); - let mut entry = Entry::new(Err(e), self.size, input_w, resize_w); + let mut entry = + Entry::new(e.into_input(), self.size, input_w, resize_w); entry.vt.process(err_str.replace('\n', "\r\n").as_bytes()); let status = async_std::process::ExitStatus::from_raw(1 << 8); entry.exit_info = Some(ExitInfo::new(status)); @@ -249,7 +255,7 @@ impl std::iter::DoubleEndedIterator for VisibleEntries { } pub struct Entry { - ast: Result<crate::parse::Commands, crate::parse::Error>, + cmdline: String, vt: vt100::Parser, audible_bell_state: usize, visual_bell_state: usize, @@ -263,13 +269,13 @@ pub struct Entry { impl Entry { fn new( - ast: Result<crate::parse::Commands, crate::parse::Error>, + cmdline: String, size: (u16, u16), input: async_std::channel::Sender<Vec<u8>>, resize: async_std::channel::Sender<(u16, u16)>, ) -> Self { Self { - ast, + cmdline, vt: vt100::Parser::new(size.0, size.1, 0), audible_bell_state: 0, visual_bell_state: 0, @@ -302,7 +308,7 @@ impl Entry { out.reset_attributes(); set_bgcolor(out, idx, focused); - if let Some(info) = self.exit_info { + if let Some(info) = &self.exit_info { if info.status.signal().is_some() { out.set_fgcolor(textmode::color::MAGENTA); } else if info.status.success() { @@ -325,7 +331,7 @@ impl Entry { out.reset_attributes(); set_bgcolor(out, idx, focused); - let time = self.exit_info.map_or_else( + let time = self.exit_info.as_ref().map_or_else( || { format!( "[{}]", @@ -436,10 +442,7 @@ impl Entry { } pub fn cmd(&self) -> &str { - match &self.ast { - Ok(ast) => ast.input_string(), - Err(e) => e.input(), - } + &self.cmdline } pub fn toggle_fullscreen(&mut self) { @@ -468,10 +471,6 @@ impl Entry { } pub fn output_lines(&self, width: u16, focused: bool) -> usize { - if let Err(e) = &self.ast { - return e.error().to_string().lines().count(); - } - if self.binary() { return 1; } @@ -498,7 +497,6 @@ impl Entry { } } -#[derive(Copy, Clone)] struct ExitInfo { status: async_std::process::ExitStatus, instant: std::time::Instant, diff --git a/src/state/mod.rs b/src/state/mod.rs index 3317b32..20261cf 100644 --- a/src/state/mod.rs +++ b/src/state/mod.rs @@ -224,7 +224,7 @@ impl State { Ok(ast) => { let idx = self .history - .run(&ast, event_w.clone()) + .run(ast, event_w.clone()) .await .unwrap(); self.set_focus(Focus::History(idx), Some(entry)) @@ -336,12 +336,11 @@ impl State { textmode::Key::Ctrl(b'm') => { let input = self.readline.input(); if !input.is_empty() { - self.readline.clear_input(); - match self.parse(&input) { + match self.parse(input) { Ok(ast) => { let idx = self .history - .run(&ast, event_w.clone()) + .run(ast, event_w.clone()) .await .unwrap(); self.set_focus(Focus::History(idx), None).await; @@ -353,6 +352,7 @@ impl State { .await; } } + self.readline.clear_input(); } } textmode::Key::Ctrl(b'u') => self.readline.clear_backwards(), diff --git a/src/state/readline.rs b/src/state/readline.rs index 014efd8..db19bd7 100644 --- a/src/state/readline.rs +++ b/src/state/readline.rs @@ -87,8 +87,8 @@ impl Readline { 2 // XXX handle wrapping } - pub fn input(&self) -> String { - self.input_line.clone() + pub fn input(&self) -> &str { + &self.input_line } pub fn add_input(&mut self, s: &str) { |