Implemented heredocs and herestrings

This commit is contained in:
2025-03-09 00:34:49 -05:00
parent 4f58c1c3fd
commit 1808786313
14 changed files with 233 additions and 89 deletions

View File

@@ -43,6 +43,9 @@ impl ExecCtx {
pub fn redirs(&self) -> &Vec<Redir> {
&self.redirs
}
pub fn clear_redirs(&mut self) {
self.redirs.clear()
}
pub fn sort_redirs(&self) -> (Vec<Redir>,Vec<Redir>) {
let mut cond_redirs = vec![];
let mut body_redirs = vec![];

View File

@@ -11,6 +11,7 @@ pub mod meta;
pub mod shenv;
pub mod vars;
pub mod input;
pub mod shopt;
/// Calls attach_tty() on the shell's process group to retake control of the terminal
pub fn take_term() -> ShResult<()> {
@@ -56,6 +57,17 @@ pub fn wait_fg(job: Job, shenv: &mut ShEnv) -> ShResult<()> {
Ok(())
}
pub fn dispatch_job(job: Job, is_bg: bool, shenv: &mut ShEnv) -> ShResult<()> {
if is_bg {
write_jobs(|j| {
j.insert_job(job, false)
})?;
} else {
wait_fg(job, shenv)?;
}
Ok(())
}
pub fn log_level() -> crate::libsh::utils::LogLevel {
let level = env::var("FERN_LOG_LEVEL").unwrap_or_default();
match level.to_lowercase().as_str() {
@@ -80,7 +92,7 @@ pub fn attach_tty(pgid: Pid) -> ShResult<()> {
if !isatty(0).unwrap_or(false) || pgid == term_ctlr() || killpg(pgid, None).is_err() {
return Ok(())
}
log!(DEBUG, "Attaching tty to pgid: {}",pgid);
log!(TRACE, "Attaching tty to pgid: {}",pgid);
if pgid == getpgrp() && term_ctlr() != getpgrp() {
kill(term_ctlr(), Signal::SIGTTOU).ok();

View File

@@ -71,7 +71,6 @@ impl ShEnv {
let old = &input[range.clone()];
let delta: isize = new.len() as isize - old.len() as isize;
input.replace_range(range, new);
log!(INFO,input);
for span in self.input_man.spans_mut() {
let mut span_mut = span.borrow_mut();
@@ -162,6 +161,7 @@ impl ShEnv {
}
pub fn reset_io(&mut self) -> ShResult<()> {
let ctx = self.ctx_mut();
ctx.clear_redirs();
if let Some(saved) = ctx.saved_io().take() {
let saved_in = saved.stdin;
let saved_out = saved.stdout;

11
src/shellenv/shopt.rs Normal file
View File

@@ -0,0 +1,11 @@
pub struct ShOpts {
}
pub struct CoreOpts {
}
pub struct PromptOpts {
}