diff options
Diffstat (limited to 'src/run/mod.rs')
| -rw-r--r-- | src/run/mod.rs | 51 |
1 files changed, 11 insertions, 40 deletions
diff --git a/src/run/mod.rs b/src/run/mod.rs index 82409e9..0a51da2 100644 --- a/src/run/mod.rs +++ b/src/run/mod.rs @@ -6,15 +6,17 @@ use std::path::PathBuf; use crate::parse::Ast; use crate::*; +mod builtin; + pub fn run(se: &Session, cmd: Vec<u8>) { run_command(&se.raw, cmd); } -pub trait Builtin : Send + Sync { - fn name(&self) -> & str; +pub trait Builtin: Send + Sync { + fn name(&self) -> &str; /// quick synchronous call, `cd` for example - fn mod_session(&self, session: &mut Session) {} + fn mod_session(&self, session: &mut Session, args: &[BString]) {} /// potentially long, pipelineable thread, builtin `cat` for example fn io( @@ -27,7 +29,12 @@ pub trait Builtin : Send + Sync { } } -const BUILTINS: &[&'static dyn Builtin] = &[]; +const BUILTINS: &[&'static dyn Builtin] = &[ + &builtin::Cd, + &builtin::Clear, + #[cfg(debug_assertions)] + &builtin::Re, +]; pub struct CommandDispatch { map: HashMap<BString, CommandKind>, @@ -110,42 +117,6 @@ fn run_command(raw: &ScopedRawMode, line: Vec<u8>) { todo!("can only handle pipes"); }; - // simple command that can probably be builtin - // TODO: handle builtins uniformly instead of big if case - if pipes.cmds.len() == 1 { - let c = &pipes.cmds[0]; - match &c.cmd[..] { - b"cd" => { - let target: &Path = match c.args.get(0).map(|v| &v[..]) { - Some(b"-") => todo!("prev"), - Some(path) => OsStr::from_bytes(path).as_ref(), - None => todo!("homedir"), - }; - - if let Err(_) = std::env::set_current_dir(target) { - print!("ERR {PROMPT}"); - } else { - print!("{PROMPT}"); - } - - return; - } - b"clear" => clear_screen(), - #[cfg(debug_assertions)] - b"re" => { - // restart shell - raw.disable(); - let _ = Command::new("cargo").arg("run").status(); - raw.disable(); - std::process::exit(0); - } - b"from" => todo!("read from file"), - b"to" | b"into" => todo!("write into file"), - b"append" => todo!("append to file"), - _ => (), - } - } - let mut children: Vec<Child> = Vec::new(); let mut prev_stdout = None; let mut spawn_error = false; |
