Skip to main content

ShellHost

Trait ShellHost 

Source
pub trait ShellHost: Send {
Show 26 methods // Provided methods fn glob(&mut self, pattern: &str, recursive: bool) -> Vec<String> { ... } fn tilde_expand(&mut self, s: &str) -> String { ... } fn brace_expand(&mut self, s: &str) -> Vec<String> { ... } fn word_split(&mut self, s: &str) -> Vec<String> { ... } fn expand_param( &mut self, name: &str, modifier: u8, args: &[Value], ) -> Value { ... } fn array_index(&mut self, name: &str, index: &Value) -> Value { ... } fn cmd_subst(&mut self, sub: &Chunk) -> String { ... } fn process_sub_in(&mut self, sub: &Chunk) -> String { ... } fn process_sub_out(&mut self, sub: &Chunk) -> String { ... } fn redirect(&mut self, fd: u8, op: u8, target: &str) { ... } fn heredoc(&mut self, content: &str) { ... } fn herestring(&mut self, content: &str) { ... } fn pipeline_begin(&mut self, n: u8) { ... } fn pipeline_stage(&mut self) { ... } fn pipeline_end(&mut self) -> i32 { ... } fn subshell_begin(&mut self) { ... } fn subshell_end(&mut self) -> Option<i32> { ... } fn trap_set(&mut self, sig: &str, handler: &Chunk) { ... } fn trap_check(&mut self) { ... } fn with_redirects_begin(&mut self, count: u8) { ... } fn with_redirects_end(&mut self) { ... } fn call_function(&mut self, name: &str, args: Vec<String>) -> Option<i32> { ... } fn exec(&mut self, args: Vec<String>) -> i32 { ... } fn exec_bg(&mut self, args: Vec<String>) -> i32 { ... } fn str_match(&mut self, s: &str, pat: &str) -> bool { ... } fn regex_match(&mut self, s: &str, regex: &str) -> bool { ... }
}
Expand description

Frontend-supplied implementation of shell-specific runtime behavior.

All methods have default no-op or identity implementations so frontends only override what they need.

Provided Methods§

Source

fn glob(&mut self, pattern: &str, recursive: bool) -> Vec<String>

Glob expand pattern. If recursive, treat ** as a recursive marker. Returns the matched paths (empty when no match — caller decides how to handle nullglob/nomatch options).

Source

fn tilde_expand(&mut self, s: &str) -> String

Tilde expansion: ~ → $HOME, ~user → user’s home, ~+/~- → dir stack. Returns input unchanged if no expansion applies.

Source

fn brace_expand(&mut self, s: &str) -> Vec<String>

Brace expansion: {a,b} → [“a”,“b”], {1..10} → 10 strings. Returns a single-element vec containing the input when no braces present.

Source

fn word_split(&mut self, s: &str) -> Vec<String>

Word splitting using current IFS rules.

Source

fn expand_param(&mut self, name: &str, modifier: u8, args: &[Value]) -> Value

Parameter expansion: ${var:-default}, ${#var}, ${var/pat/rep}, etc. modifier is one of crate::op::param_mod::*. args are the modifier operands (already evaluated to Values) — for ${var:-x} it’s [x], for ${var/p/r} it’s [p, r], for ${var:o:l} it’s [o, l]. LENGTH/UPPER/LOWER/KEYS/INDIRECT take no args.

Source

fn array_index(&mut self, name: &str, index: &Value) -> Value

Index into an array variable: ${arr[idx]}. index is the evaluated subscript (Int for indexed arrays, Str for associative).

Source

fn cmd_subst(&mut self, sub: &Chunk) -> String

Run a sub-chunk and capture its stdout as a string. ($(cmd),`cmd`)

Source

fn process_sub_in(&mut self, sub: &Chunk) -> String

Process substitution input: spawn sub, return path to a fd/FIFO that reads its stdout. (<(cmd))

Source

fn process_sub_out(&mut self, sub: &Chunk) -> String

Process substitution output: spawn sub, return path to a fd/FIFO that writes to its stdin. (>(cmd))

Source

fn redirect(&mut self, fd: u8, op: u8, target: &str)

Apply a redirection at the next exec/builtin call. fd is the source fd, op from crate::op::redirect_op::*, target is the (already-expanded) filename or fd reference.

Source

fn heredoc(&mut self, content: &str)

Heredoc body for the next command’s stdin.

Source

fn herestring(&mut self, content: &str)

Herestring body for the next command’s stdin.

Source

fn pipeline_begin(&mut self, n: u8)

Begin an N-stage pipeline. Subsequent pipeline_stage calls separate stages; pipeline_end waits for completion and returns final status.

Source

fn pipeline_stage(&mut self)

Wire next pipeline stage (set up pipe between previous and next).

Source

fn pipeline_end(&mut self) -> i32

Wait for the pipeline to complete; return last command’s exit status.

Source

fn subshell_begin(&mut self)

Begin subshell scope (snapshot/save state).

Source

fn subshell_end(&mut self) -> Option<i32>

End subshell scope (restore state). Returns Some(status) when the subshell terminated with a deferred exit (the host wants the VM’s last_status updated so the parent’s $? sees the exit value); returns None to leave last_status untouched.

Source

fn trap_set(&mut self, sig: &str, handler: &Chunk)

Install a trap handler for signal sig. The handler is a sub-chunk that the host runs when the signal fires.

Source

fn trap_check(&mut self)

Process pending traps (called periodically by the VM dispatch loop).

Source

fn with_redirects_begin(&mut self, count: u8)

Begin scoped redirect block — cmd > out.txt style applied to a compound command. The host saves current fd state.

Source

fn with_redirects_end(&mut self)

End scoped redirect block — restore fd state.

Source

fn call_function(&mut self, name: &str, args: Vec<String>) -> Option<i32>

Call a user-defined shell function. Returns Some(status) when the function exists, None to fall through to external exec.

Source

fn exec(&mut self, args: Vec<String>) -> i32

Spawn an external command and wait. Default uses std::process::Command.

On wasm32 (a browser web worker) there is no process model, so the default returns 127 (command-not-found) rather than attempting a spawn — a worker frontend overrides this to bridge to the host environment.

Source

fn exec_bg(&mut self, args: Vec<String>) -> i32

Spawn an external command in the background and detach. Returns the child pid (or 0 on failure / when the host doesn’t track pids). Default uses std::process::Command::spawn(). Frontends override to register the pid in their job table so jobs, fg, wait, disown see it.

On wasm32 there is no process model; returns 0 (no pid tracked) unless a worker frontend overrides it.

Source

fn str_match(&mut self, s: &str, pat: &str) -> bool

Glob match: does s match the shell glob pattern pat? Used by [[ x = pat ]] and case. Default is exact equality.

Source

fn regex_match(&mut self, s: &str, regex: &str) -> bool

Regex match: s =~ regex (extended POSIX or PCRE per host).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§