Implemented the exec builtin

Fixed readline and terminal interactions using stdin instead of /dev/tty
This commit is contained in:
2026-02-20 12:17:48 -05:00
parent 2184b9b361
commit 129390c2da
16 changed files with 384 additions and 41 deletions

View File

@@ -1,3 +1,5 @@
use std::sync::LazyLock;
use termios::{LocalFlags, Termios};
use crate::prelude::*;
@@ -31,6 +33,11 @@ use crate::prelude::*;
/// lifecycle could lead to undefined behavior.
pub(crate) static mut SAVED_TERMIOS: Option<Option<Termios>> = None;
pub static TTY_FILENO: LazyLock<RawFd> = LazyLock::new(|| {
open("/dev/tty", OFlag::O_RDWR, Mode::empty())
.expect("Failed to open /dev/tty")
});
#[derive(Debug)]
pub struct TermiosGuard {
saved_termios: Option<Termios>,
@@ -42,7 +49,7 @@ impl TermiosGuard {
saved_termios: None,
};
if isatty(std::io::stdin().as_raw_fd()).unwrap() {
if isatty(*TTY_FILENO).unwrap() {
let current_termios = termios::tcgetattr(std::io::stdin()).unwrap();
new.saved_termios = Some(current_termios);