aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJonas Maier <>2026-03-07 09:53:18 +0100
committerJonas Maier <>2026-03-07 09:53:18 +0100
commit424a1f5e4039e40dd714f8172f0b34d0f25782ec (patch)
tree4da1e74921f5886d562a51869e0e95f8a973441b /src
parent7bd6e6253268ec626a7191344ce9ff77358f94db (diff)
downloadpish-424a1f5e4039e40dd714f8172f0b34d0f25782ec.tar.gz
compiles again
Diffstat (limited to 'src')
-rw-r--r--src/main.rs10
-rw-r--r--src/run/builtin.rs2
-rw-r--r--src/run/mod.rs38
3 files changed, 29 insertions, 21 deletions
diff --git a/src/main.rs b/src/main.rs
index 36868ca..33193f2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,6 +5,7 @@ use std::os::unix::ffi::OsStrExt;
use std::os::unix::io::AsRawFd;
use std::path::Path;
use std::process::{Command, Stdio};
+use std::sync::{Arc, Mutex};
use std::thread::sleep;
use std::time::Duration;
@@ -205,6 +206,8 @@ fn event_loop() {
print!("{}", se.prompt());
+ let session = Arc::new(Mutex::new(se));
+
loop {
let mut buf = [0u8; 1];
@@ -212,6 +215,8 @@ fn event_loop() {
break;
};
+ let mut se = session.lock().unwrap();
+
match buf[0] {
// Ctrl+A
1 => {
@@ -253,7 +258,8 @@ fn event_loop() {
print!("\r\n");
se.history.push(line.clone());
se.history_visit = 0;
- run::run(&mut se, line);
+ drop(se);
+ run::run(session.clone(), line);
}
}
@@ -367,7 +373,7 @@ fn event_loop() {
}
}
- se.raw.disable();
+ session.lock().unwrap().raw.disable();
}
fn main() {
diff --git a/src/run/builtin.rs b/src/run/builtin.rs
index 0b5b914..e03e19e 100644
--- a/src/run/builtin.rs
+++ b/src/run/builtin.rs
@@ -3,7 +3,7 @@
use std::sync::{Arc, Mutex};
use std::{env::*, fs::OpenOptions, path::PathBuf};
-use super::{Builtin, BuiltinError as Error, BuiltinResult as Result};
+use super::{Builtin, BuiltinResult as Result};
use crate::*;
pub struct cd;
diff --git a/src/run/mod.rs b/src/run/mod.rs
index a27812f..e230824 100644
--- a/src/run/mod.rs
+++ b/src/run/mod.rs
@@ -1,3 +1,4 @@
+use std::clone;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
@@ -12,8 +13,8 @@ enum ExecError {
ExecError(i32),
}
-struct Executor<'a> {
- se: &'a mut Session,
+struct Executor {
+ se: Arc<Mutex<Session>>,
}
#[derive(Clone)]
@@ -43,7 +44,7 @@ impl std::io::Write for ArcWriter {
}
}
-impl<'a> Executor<'a> {
+impl Executor {
fn execute(
&mut self,
ast: Ast<parse::PostExpansion>,
@@ -72,7 +73,7 @@ impl<'a> Executor<'a> {
(None, None)
};
- let dc = self.se.dispatch.get(&cmd.cmd[..]);
+ let dc = self.se.lock().unwrap().dispatch.get(&cmd.cmd[..]);
match dc {
CommandKind::Path(path) => {
@@ -131,8 +132,6 @@ impl<'a> Executor<'a> {
CommandKind::Builtin(builtin) => {
last_is_command = false;
- builtin.mod_session(&mut self.se, &cmd.args);
-
let mut input: Box<dyn io::Read + Send> = match prev_reader.take() {
Some(r) => Box::new(r),
None if capture.is_some() => Box::new(io::empty()),
@@ -145,8 +144,11 @@ impl<'a> Executor<'a> {
None => Box::new(io::stdout()),
};
- let handle =
- std::thread::spawn(move || builtin.io(&cmd.args, &mut input, &mut output));
+ let cloned_session = self.se.clone();
+
+ let handle = std::thread::spawn(move || {
+ builtin.io(cloned_session, &cmd.args, &mut input, &mut output)
+ });
threads.push(handle);
}
@@ -200,7 +202,7 @@ impl<'a> Executor<'a> {
}
}
-impl<'a> parse::Expander for Executor<'a> {
+impl parse::Expander for Executor {
type Error = ExecError;
fn expand_var(&mut self, var: BString) -> Result<BString, Self::Error> {
@@ -220,29 +222,29 @@ impl<'a> parse::Expander for Executor<'a> {
}
}
-fn exec(se: &mut Session, ast: Ast<PreExpansion>) -> Result<(), ExecError> {
+fn exec(se: Arc<Mutex<Session>>, ast: Ast<PreExpansion>) -> Result<(), ExecError> {
let mut exec = Executor { se };
let ast = ast.expand(&mut exec)?;
exec.execute(ast, None)
}
-pub fn run(se: &mut Session, cmd: Vec<u8>) {
+pub fn run(se: Arc<Mutex<Session>>, cmd: Vec<u8>) {
let parsed = parse::do_parse(&cmd);
let parsed = match parsed {
Ok(p) => p,
Err(err) => {
- se.raw.disable();
+ se.lock().unwrap().raw.disable();
println!("{:?}: {}", err.0, String::from_utf8_lossy(&err.1));
- print!("{}", se.prompt());
+ print!("{}", se.lock().unwrap().prompt());
std::io::stdout().lock().flush().unwrap();
- se.raw.enable();
+ se.lock().unwrap().raw.enable();
return;
}
};
- se.raw.disable();
- let result = exec(se, parsed);
- se.raw.enable();
+ se.lock().unwrap().raw.disable();
+ let result = exec(se.clone(), parsed);
+ se.lock().unwrap().raw.enable();
let status_string = match result {
Ok(_) => String::new(),
@@ -252,7 +254,7 @@ pub fn run(se: &mut Session, cmd: Vec<u8>) {
Err(ExecError::ExecError(i)) => i.to_string(),
};
- print!("\r{status_string}\r\n{}", se.prompt());
+ print!("\r{status_string}\r\n{}", se.lock().unwrap().prompt());
let _ = std::io::stdout().lock().flush();
}