From b792d9a83d0ed5e71ba4c0ae62730db8fee00216 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 28 Feb 2022 23:02:46 -0500 Subject: push some copies up the stack --- src/main.rs | 2 +- src/parse/ast.rs | 4 ++-- src/parse/mod.rs | 4 ++-- src/runner/mod.rs | 6 +++--- src/shell/history/mod.rs | 10 +++++----- src/shell/mod.rs | 11 ++++++++--- src/shell/readline.rs | 4 ++-- 7 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1e9d70f..1ace4d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,7 +47,7 @@ async fn async_main(opt: Opt) -> Result { }) }); - return runner::run(&command, &mut shell_write).await; + return runner::run(command, &mut shell_write).await; } shell::main().await diff --git a/src/parse/ast.rs b/src/parse/ast.rs index 1f0cdc2..030ce14 100644 --- a/src/parse/ast.rs +++ b/src/parse/ast.rs @@ -12,10 +12,10 @@ pub struct Commands { } impl Commands { - pub fn parse(full_cmd: &str) -> Result { + pub fn parse(full_cmd: &String) -> Result { Ok(Self::build_ast( Shell::parse(Rule::line, full_cmd) - .map_err(|e| super::Error::new(full_cmd, e))? + .map_err(|e| super::Error::new(full_cmd.clone(), e))? .next() .unwrap() .into_inner() diff --git a/src/parse/mod.rs b/src/parse/mod.rs index cc6d92b..9663086 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -106,9 +106,9 @@ pub struct Error { } impl Error { - fn new(input: &str, e: pest::error::Error) -> Self { + fn new(input: String, e: pest::error::Error) -> Self { Self { - input: input.to_string(), + input, e, } } diff --git a/src/runner/mod.rs b/src/runner/mod.rs index 622bdd7..09eb539 100644 --- a/src/runner/mod.rs +++ b/src/runner/mod.rs @@ -69,7 +69,7 @@ enum Frame { } pub async fn run( - commands: &str, + commands: String, shell_write: &mut Option, ) -> Result { let mut env = Env::new_from_env()?; @@ -84,11 +84,11 @@ pub async fn run( } async fn run_commands( - commands: &str, + commands: String, env: &mut Env, shell_write: &mut Option, ) -> Result<()> { - let commands = crate::parse::ast::Commands::parse(commands)?; + let commands = crate::parse::ast::Commands::parse(&commands)?; let commands = commands.commands(); let mut pc = 0; let mut stack = Stack::new(); diff --git a/src/shell/history/mod.rs b/src/shell/history/mod.rs index 5bcc820..8b67ed2 100644 --- a/src/shell/history/mod.rs +++ b/src/shell/history/mod.rs @@ -90,24 +90,24 @@ impl History { pub fn run( &mut self, - cmdline: &str, - env: &Env, + cmdline: String, + env: Env, event_w: crate::shell::event::Writer, ) -> usize { let (input_w, input_r) = tokio::sync::mpsc::unbounded_channel(); let (resize_w, resize_r) = tokio::sync::mpsc::unbounded_channel(); let entry = std::sync::Arc::new(std::sync::Mutex::new(Entry::new( - cmdline.to_string(), + cmdline.clone(), env.clone(), self.size, input_w, resize_w, ))); run_commands( - cmdline.to_string(), + cmdline, std::sync::Arc::clone(&entry), - env.clone(), + env, input_r, resize_r, event_w, diff --git a/src/shell/mod.rs b/src/shell/mod.rs index ab01161..a494752 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -417,7 +417,8 @@ impl Shell { entry.should_fullscreen(), ) }); - let idx = self.history.run(&input, &self.env, event_w); + let idx = + self.history.run(input, self.env.clone(), event_w); self.set_focus(Focus::History(idx), fullscreen); self.hide_readline = true; self.env.set_idx(idx + 1); @@ -469,7 +470,7 @@ impl Shell { let input = self .history .with_entry(idx, |entry| entry.cmd().to_string()); - self.readline.set_input(&input); + self.readline.set_input(input); self.set_focus(Focus::Readline, false); } } @@ -532,7 +533,11 @@ impl Shell { textmode::Key::Ctrl(b'm') => { let input = self.readline.input(); if !input.is_empty() { - let idx = self.history.run(input, &self.env, event_w); + let idx = self.history.run( + input.to_string(), + self.env.clone(), + event_w, + ); self.set_focus( Focus::History(idx), self.history.should_fullscreen(idx), diff --git a/src/shell/readline.rs b/src/shell/readline.rs index 49a3ab6..5de9901 100644 --- a/src/shell/readline.rs +++ b/src/shell/readline.rs @@ -102,9 +102,9 @@ impl Readline { self.inc_pos(s.chars().count()); } - pub fn set_input(&mut self, s: &str) { - self.input_line = s.to_string(); + pub fn set_input(&mut self, s: String) { self.set_pos(s.chars().count()); + self.input_line = s; } pub fn backspace(&mut self) { -- cgit v1.2.3-54-g00ecf