Early implementation of scripting elements

This commit is contained in:
2025-03-05 01:36:58 -05:00
parent 5dd9ee96ad
commit 1b3e2c0887
28 changed files with 1384 additions and 371 deletions

View File

@@ -3,10 +3,26 @@ use std::{os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, OwnedFd}, str::FromStr}
use nix::libc::getpgrp;
use crate::{expand::{expand_vars::{expand_dquote, expand_var}, tilde::expand_tilde}, prelude::*};
use crate::prelude::*;
use super::term::StyleSet;
pub trait RedirTargetType {
fn as_tgt(self) -> RedirTarget;
}
impl RedirTargetType for PathBuf {
fn as_tgt(self) -> RedirTarget {
RedirTarget::File(self)
}
}
impl RedirTargetType for i32 {
fn as_tgt(self) -> RedirTarget {
RedirTarget::Fd(self)
}
}
pub trait StrOps {
/// This function operates on anything that implements `AsRef<str>` and `Display`, which is mainly strings.
/// It takes a 'Style' which can be passed as a single Style object like `Style::Cyan` or a Bit OR of many styles,
@@ -31,7 +47,7 @@ impl ArgVec for Vec<Token> {
let mut argv_iter = self.into_iter();
let mut argv_processed = vec![];
while let Some(arg) = argv_iter.next() {
let cleaned = trim_quotes(&arg);
let cleaned = trim_quotes(&arg.as_raw(shenv));
argv_processed.push(cleaned);
}
argv_processed
@@ -248,6 +264,12 @@ impl Redir {
pub fn new(src: i32, op: RedirType, tgt: RedirTarget) -> Self {
Self { src, op, tgt }
}
pub fn output(src: i32, tgt: impl RedirTargetType) -> Self {
Self::new(src, RedirType::Output, tgt.as_tgt())
}
pub fn input(src: i32, tgt: impl RedirTargetType) -> Self {
Self::new(src, RedirType::Input, tgt.as_tgt())
}
}
#[derive(Debug,Clone)]