Implemented scoping for expansions

This commit is contained in:
2025-03-08 01:38:42 -05:00
parent 67977f96eb
commit cdcfb23edb
18 changed files with 271 additions and 141 deletions

View File

@@ -9,13 +9,46 @@ pub mod signal;
pub mod prompt;
pub mod builtin;
pub mod expand;
pub mod tests;
use std::os::fd::AsRawFd;
use nix::sys::termios::{self, LocalFlags, Termios};
use signal::sig_setup;
use crate::prelude::*;
pub static mut SAVED_TERMIOS: Option<Option<Termios>> = None;
pub fn save_termios() {
unsafe {
SAVED_TERMIOS = Some(if isatty(std::io::stdin().as_raw_fd()).unwrap() {
let mut termios = termios::tcgetattr(std::io::stdin()).unwrap();
termios.local_flags &= !LocalFlags::ECHOCTL;
termios::tcsetattr(std::io::stdin(), nix::sys::termios::SetArg::TCSANOW, &termios).unwrap();
Some(termios)
} else {
None
});
}
}
pub fn get_saved_termios() -> Option<Termios> {
unsafe {
SAVED_TERMIOS.clone().flatten()
}
}
fn set_termios() {
if isatty(std::io::stdin().as_raw_fd()).unwrap() {
let mut termios = termios::tcgetattr(std::io::stdin()).unwrap();
termios.local_flags &= !LocalFlags::ECHOCTL;
termios::tcsetattr(std::io::stdin(), nix::sys::termios::SetArg::TCSANOW, &termios).unwrap();
}
}
pub fn main() {
sig_setup();
save_termios();
set_termios();
let mut shenv = ShEnv::new();
if let Err(e) = shenv.source_rc() {
eprintln!("Error sourcing rc file: {}", e.to_string());
@@ -23,13 +56,14 @@ pub fn main() {
loop {
log!(TRACE, "Entered loop");
let line = match prompt::read_line(&mut shenv) {
Ok(line) => line,
match prompt::read_line(&mut shenv) {
Ok(line) => {
let _ = exec_input(line, &mut shenv).eprint();
}
Err(e) => {
eprintln!("{}",e);
continue;
}
};
let _ = exec_input(line, &mut shenv).eprint();
}
}