pub struct ShellState {Show 44 fields
pub variables: HashMap<String, String>,
pub exported: HashSet<String>,
pub last_exit_code: i32,
pub shell_pid: u32,
pub script_name: String,
pub dir_stack: Vec<String>,
pub aliases: HashMap<String, String>,
pub colors_enabled: bool,
pub color_scheme: ColorScheme,
pub positional_params: Vec<String>,
pub functions: HashMap<String, Ast>,
pub local_vars: Vec<HashMap<String, String>>,
pub function_depth: usize,
pub max_recursion_depth: usize,
pub returning: bool,
pub return_value: Option<i32>,
pub loop_depth: usize,
pub breaking: bool,
pub break_level: usize,
pub continuing: bool,
pub continue_level: usize,
pub capture_output: Option<Rc<RefCell<Vec<u8>>>>,
pub condensed_cwd: bool,
pub trap_handlers: Arc<Mutex<HashMap<String, String>>>,
pub exit_trap_executed: bool,
pub exit_requested: bool,
pub exit_code: i32,
pub pending_signals: bool,
pub pending_heredoc_content: Option<String>,
pub collecting_heredoc: Option<(String, String, String)>,
pub fd_table: Rc<RefCell<FileDescriptorTable>>,
pub subshell_depth: usize,
pub stdin_override: Option<RawFd>,
pub options: ShellOptions,
pub in_condition: bool,
pub in_logical_chain: bool,
pub in_negation: bool,
pub last_was_negation: bool,
pub current_line_number: usize,
pub line_number_stack: Vec<usize>,
pub job_table: Rc<RefCell<JobTable>>,
pub interactive: bool,
pub terminal_fd: Option<RawFd>,
pub last_background_pid: Option<u32>,
}Fields§
§variables: HashMap<String, String>Shell variables (local to the shell session)
exported: HashSet<String>Which variables are exported to child processes
last_exit_code: i32Last exit code ($?)
shell_pid: u32Shell process ID ($$)
script_name: StringScript name or command ($0)
dir_stack: Vec<String>Directory stack for pushd/popd
aliases: HashMap<String, String>Command aliases
colors_enabled: boolWhether colors are enabled
color_scheme: ColorSchemeCurrent color scheme
positional_params: Vec<String>Positional parameters ($1, $2, $3, …)
functions: HashMap<String, Ast>Function definitions
local_vars: Vec<HashMap<String, String>>Local variable stack for function scoping
function_depth: usizeFunction call depth for local scope management
max_recursion_depth: usizeMaximum allowed recursion depth
returning: boolFlag to indicate if we’re currently returning from a function
return_value: Option<i32>Return value when returning from a function
loop_depth: usizeLoop nesting depth for break/continue
breaking: boolFlag to indicate if we’re breaking out of a loop
break_level: usizeNumber of loop levels to break out of
continuing: boolFlag to indicate if we’re continuing to next loop iteration
continue_level: usizeNumber of loop levels to continue from
capture_output: Option<Rc<RefCell<Vec<u8>>>>Output capture buffer for command substitution
condensed_cwd: boolWhether to use condensed cwd display in prompt
trap_handlers: Arc<Mutex<HashMap<String, String>>>Signal trap handlers: maps signal name to command string
exit_trap_executed: boolFlag to track if EXIT trap has been executed
exit_requested: boolFlag to indicate that the shell should exit
exit_code: i32Exit code to use when exiting
pending_signals: boolFlag to indicate pending signals need processing Set by signal handler, checked by executor
pending_heredoc_content: Option<String>Pending here-document content from script execution
collecting_heredoc: Option<(String, String, String)>Interactive mode heredoc collection state
fd_table: Rc<RefCell<FileDescriptorTable>>File descriptor table for managing open file descriptors
subshell_depth: usizeCurrent subshell nesting depth (for recursion limit)
stdin_override: Option<RawFd>Override for stdin (used for pipeline subshells to avoid process-global fd manipulation)
options: ShellOptionsShell option flags (set builtin)
in_condition: boolContext tracking for errexit option - true when executing commands in if/while/until conditions
in_logical_chain: boolContext tracking for errexit option - true when executing commands in && or || chains
in_negation: boolContext tracking for errexit option - true when executing negated commands (!)
last_was_negation: boolTrack if the last command executed was a negation (to skip errexit check on inverted code)
current_line_number: usizeCurrent line number in script execution (for $LINENO)
line_number_stack: Vec<usize>Stack of line numbers for function calls (to restore after function returns)
job_table: Rc<RefCell<JobTable>>Job table for managing background jobs
interactive: boolWhether the shell is running in interactive mode
terminal_fd: Option<RawFd>Terminal file descriptor for job control (None if not interactive)
last_background_pid: Option<u32>PID of the last background process started ($!)
Implementations§
Source§impl ShellState
impl ShellState
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new ShellState initialized with sensible defaults and environment-derived settings.
The returned state initializes runtime fields (variables, exported, aliases, positional params, function/local scopes, FD table, traps, and control flags) and derives display preferences from environment:
colors_enabledis determined byNO_COLOR,RUSH_COLORS, and whether stdout is a terminal.condensed_cwdis determined byRUSH_CONDENSED(defaults totrue).
§Examples
use rush_sh::ShellState;
let state = ShellState::new();
// basic invariants
assert_eq!(state.last_exit_code, 0);
assert!(state.shell_pid != 0);Sourcepub fn get_var(&self, name: &str) -> Option<String>
pub fn get_var(&self, name: &str) -> Option<String>
Get a variable value, checking local scopes first, then shell variables, then environment
Sourcepub fn set_var(&mut self, name: &str, value: String)
pub fn set_var(&mut self, name: &str, value: String)
Set a shell variable (updates local scope if variable exists there, otherwise sets globally)
Sourcepub fn export_var(&mut self, name: &str)
pub fn export_var(&mut self, name: &str)
Mark a variable as exported
Sourcepub fn set_exported_var(&mut self, name: &str, value: String)
pub fn set_exported_var(&mut self, name: &str, value: String)
Set and export a variable
Sourcepub fn get_env_for_child(&self) -> HashMap<String, String>
pub fn get_env_for_child(&self) -> HashMap<String, String>
Get all environment variables for child processes (exported + inherited)
Sourcepub fn set_last_exit_code(&mut self, code: i32)
pub fn set_last_exit_code(&mut self, code: i32)
Update the last exit code
Sourcepub fn set_script_name(&mut self, name: &str)
pub fn set_script_name(&mut self, name: &str)
Set the script name ($0)
Sourcepub fn get_condensed_cwd(&self) -> String
pub fn get_condensed_cwd(&self) -> String
Get the condensed current working directory for the prompt
Sourcepub fn get_full_cwd(&self) -> String
pub fn get_full_cwd(&self) -> String
Get the full current working directory for the prompt
Sourcepub fn get_user_hostname(&self) -> String
pub fn get_user_hostname(&self) -> String
Get the user@hostname string for the prompt
Sourcepub fn get_prompt(&self) -> String
pub fn get_prompt(&self) -> String
Get the full prompt string
Sourcepub fn remove_alias(&mut self, name: &str)
pub fn remove_alias(&mut self, name: &str)
Remove an alias
Sourcepub fn get_all_aliases(&self) -> &HashMap<String, String>
pub fn get_all_aliases(&self) -> &HashMap<String, String>
Get all aliases
Sourcepub fn set_positional_params(&mut self, params: Vec<String>)
pub fn set_positional_params(&mut self, params: Vec<String>)
Set positional parameters
Sourcepub fn get_positional_params(&self) -> &[String]
pub fn get_positional_params(&self) -> &[String]
Get positional parameters
Sourcepub fn shift_positional_params(&mut self, count: usize)
pub fn shift_positional_params(&mut self, count: usize)
Shift positional parameters (remove first n parameters)
Sourcepub fn push_positional_param(&mut self, param: String)
pub fn push_positional_param(&mut self, param: String)
Add a positional parameter at the end
Sourcepub fn define_function(&mut self, name: String, body: Ast)
pub fn define_function(&mut self, name: String, body: Ast)
Define a function
Sourcepub fn get_function(&self, name: &str) -> Option<&Ast>
pub fn get_function(&self, name: &str) -> Option<&Ast>
Get a function definition
Sourcepub fn remove_function(&mut self, name: &str)
pub fn remove_function(&mut self, name: &str)
Remove a function definition
Sourcepub fn get_function_names(&self) -> Vec<&String>
pub fn get_function_names(&self) -> Vec<&String>
Get all function names
Sourcepub fn push_local_scope(&mut self)
pub fn push_local_scope(&mut self)
Push a new local variable scope
Sourcepub fn pop_local_scope(&mut self)
pub fn pop_local_scope(&mut self)
Pop the current local variable scope
Sourcepub fn set_local_var(&mut self, name: &str, value: String)
pub fn set_local_var(&mut self, name: &str, value: String)
Set a local variable in the current scope
Sourcepub fn enter_function(&mut self)
pub fn enter_function(&mut self)
Enter a function context (push local scope if needed)
Sourcepub fn exit_function(&mut self)
pub fn exit_function(&mut self)
Exit a function context (pop local scope if needed)
Sourcepub fn set_return(&mut self, value: i32)
pub fn set_return(&mut self, value: i32)
Set return state for function returns
Sourcepub fn clear_return(&mut self)
pub fn clear_return(&mut self)
Clear return state
Sourcepub fn is_returning(&self) -> bool
pub fn is_returning(&self) -> bool
Check if currently returning
Sourcepub fn get_return_value(&self) -> Option<i32>
pub fn get_return_value(&self) -> Option<i32>
Get return value if returning
Sourcepub fn enter_loop(&mut self)
pub fn enter_loop(&mut self)
Enter a loop context (increment loop depth)
Sourcepub fn clear_break(&mut self)
pub fn clear_break(&mut self)
Clear break state
Sourcepub fn is_breaking(&self) -> bool
pub fn is_breaking(&self) -> bool
Check if currently breaking
Sourcepub fn get_break_level(&self) -> usize
pub fn get_break_level(&self) -> usize
Get break level
Sourcepub fn decrement_break_level(&mut self)
pub fn decrement_break_level(&mut self)
Decrement break level (when exiting a loop level)
Sourcepub fn set_continue(&mut self, level: usize)
pub fn set_continue(&mut self, level: usize)
Set continue state for loop control
Sourcepub fn clear_continue(&mut self)
pub fn clear_continue(&mut self)
Clear continue state
Sourcepub fn is_continuing(&self) -> bool
pub fn is_continuing(&self) -> bool
Check if currently continuing
Sourcepub fn get_continue_level(&self) -> usize
pub fn get_continue_level(&self) -> usize
Get continue level
Sourcepub fn decrement_continue_level(&mut self)
pub fn decrement_continue_level(&mut self)
Decrement continue level (when exiting a loop level)
Sourcepub fn remove_trap(&mut self, signal: &str)
pub fn remove_trap(&mut self, signal: &str)
Remove a trap handler for a signal
Sourcepub fn get_all_traps(&self) -> HashMap<String, String>
pub fn get_all_traps(&self) -> HashMap<String, String>
Get all trap handlers
Sourcepub fn clear_traps(&mut self)
pub fn clear_traps(&mut self)
Clear all trap handlers
Trait Implementations§
Source§impl Clone for ShellState
impl Clone for ShellState
Source§fn clone(&self) -> ShellState
fn clone(&self) -> ShellState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more