summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-02-28 23:02:46 -0500
committerJesse Luehrs <doy@tozt.net>2022-02-28 23:02:46 -0500
commitb792d9a83d0ed5e71ba4c0ae62730db8fee00216 (patch)
tree45fe04a1e536e5b7df6e9a67bd86efa420667b01 /src
parentb9d919152cfa12bf74d4ffc5d0b1528e3b64857a (diff)
downloadnbsh-b792d9a83d0ed5e71ba4c0ae62730db8fee00216.tar.gz
nbsh-b792d9a83d0ed5e71ba4c0ae62730db8fee00216.zip
push some copies up the stack
Diffstat (limited to 'src')
-rw-r--r--src/main.rs2
-rw-r--r--src/parse/ast.rs4
-rw-r--r--src/parse/mod.rs4
-rw-r--r--src/runner/mod.rs6
-rw-r--r--src/shell/history/mod.rs10
-rw-r--r--src/shell/mod.rs11
-rw-r--r--src/shell/readline.rs4
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<i32> {
})
});
- 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<Self, super::Error> {
+ pub fn parse(full_cmd: &String) -> Result<Self, super::Error> {
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<ast::Rule>) -> Self {
+ fn new(input: String, e: pest::error::Error<ast::Rule>) -> 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<tokio::fs::File>,
) -> Result<i32> {
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<tokio::fs::File>,
) -> 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) {