pub struct ShellExecutionState {
pub shell_kind: ShellKind,
pub process_status: TerminalProcessStatus,
pub cwd_uri: Option<String>,
pub prompt_visible: bool,
pub current_command: Option<CommandExecution>,
pub last_command: Option<CommandExecution>,
pub history: Vec<CommandExecution>,
pub history_limit: usize,
pub next_command_id: u64,
pub last_prompt_line: Option<u64>,
pub pending_events: Vec<ShellEvent>,
}Expand description
Mutable pure state for shell integration and heuristic prompt tracking.
Normal methods keep history bounded and events ordered. Public fields and
deserialization can bypass all invariants; notably next_command_id uses
saturating allocation and will reuse u64::MAX after exhaustion.
§Examples
use ailloli_ui_terminal_core::ShellExecutionState;
let shell = ShellExecutionState::new();
assert_eq!(shell.next_command_id, 1);
assert!(shell.current_command.is_none());Fields§
§shell_kind: ShellKindDetected/configured shell family.
process_status: TerminalProcessStatusShell/PTY process lifecycle.
cwd_uri: Option<String>Current working-directory URI, or None when unknown.
prompt_visible: boolWhether a prompt is currently considered visible.
current_command: Option<CommandExecution>Running command, or None while idle.
last_command: Option<CommandExecution>Most recently finished command, even when history retention is disabled.
history: Vec<CommandExecution>Retained finished commands, oldest to newest.
history_limit: usizeMaximum retained history count; zero disables history retention.
next_command_id: u64Next saturating raw command ID.
last_prompt_line: Option<u64>Most recent prompt global line, or None before detection.
pending_events: Vec<ShellEvent>Ordered undrained changes; defaults empty in older serialized state.
Implementations§
Source§impl ShellExecutionState
impl ShellExecutionState
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates the default unknown, idle shell state.
§Examples
use ailloli_ui_terminal_core::{ShellExecutionState, TerminalProcessStatus};
assert_eq!(ShellExecutionState::new().process_status, TerminalProcessStatus::Unknown);Sourcepub fn snapshot(&self) -> TerminalShellSnapshot
pub fn snapshot(&self) -> TerminalShellSnapshot
Clones the consumer-facing shell snapshot.
This is linear in retained command history and does not drain events.
§Examples
use ailloli_ui_terminal_core::ShellExecutionState;
let mut shell = ShellExecutionState::new(); shell.set_cwd_uri("file:///tmp");
assert_eq!(shell.snapshot().cwd_uri.as_deref(), Some("file:///tmp"));Sourcepub fn drain_events(&mut self) -> Vec<ShellEvent>
pub fn drain_events(&mut self) -> Vec<ShellEvent>
Removes and returns all pending events in original order.
A second drain returns an empty vector.
§Examples
use ailloli_ui_terminal_core::ShellExecutionState;
let mut shell = ShellExecutionState::new(); shell.mark_prompt_start(2);
assert_eq!(shell.drain_events().len(), 1);
assert!(shell.drain_events().is_empty());Sourcepub fn set_cwd_uri(&mut self, cwd_uri: impl Into<String>)
pub fn set_cwd_uri(&mut self, cwd_uri: impl Into<String>)
Replaces the CWD URI and emits CwdChanged only when unequal.
Text is stored verbatim, including an empty string. This method cannot
restore None; public field mutation can.
§Examples
use ailloli_ui_terminal_core::ShellExecutionState;
let mut shell = ShellExecutionState::new(); shell.set_cwd_uri("file:///tmp"); shell.set_cwd_uri("file:///tmp");
assert_eq!(shell.drain_events().len(), 1);Sourcepub fn set_shell_kind(&mut self, shell_kind: ShellKind)
pub fn set_shell_kind(&mut self, shell_kind: ShellKind)
Replaces shell kind and emits an event only when unequal.
§Examples
use ailloli_ui_terminal_core::{ShellExecutionState, ShellKind};
let mut shell = ShellExecutionState::new(); shell.set_shell_kind(ShellKind::Fish);
assert_eq!(shell.shell_kind, ShellKind::Fish);Sourcepub fn set_process_status(&mut self, status: TerminalProcessStatus)
pub fn set_process_status(&mut self, status: TerminalProcessStatus)
Replaces process status and emits an event only when unequal.
§Examples
use ailloli_ui_terminal_core::{ShellExecutionState, TerminalProcessStatus};
let mut shell = ShellExecutionState::new(); shell.set_process_status(TerminalProcessStatus::Running);
assert_eq!(shell.process_status, TerminalProcessStatus::Running);Sourcepub fn mark_prompt_start(&mut self, line: u64)
pub fn mark_prompt_start(&mut self, line: u64)
Marks a visible prompt and always emits PromptStart.
Repeated calls for the same line are not deduplicated here; use
Self::apply_prompt_heuristic for heuristic deduplication.
§Examples
use ailloli_ui_terminal_core::ShellExecutionState;
let mut shell = ShellExecutionState::new(); shell.mark_prompt_start(9);
assert!(shell.prompt_visible && shell.last_prompt_line == Some(9));Sourcepub fn start_command(
&mut self,
command_line: impl Into<String>,
cwd_uri: Option<String>,
line: u64,
started_at_ms: Option<u64>,
)
pub fn start_command( &mut self, command_line: impl Into<String>, cwd_uri: Option<String>, line: u64, started_at_ms: Option<u64>, )
Starts a command, superseding any currently running command.
A superseded command is closed at line, forced to Unknown, retained,
and emits CommandEnd. The new command inherits state CWD only when the
argument is None, hides the prompt, sets process status to running, and
emits CommandStart. A status-change event precedes the start event when
status was not already running. IDs allocate with saturation.
§Examples
use ailloli_ui_terminal_core::{CommandStatus, ShellExecutionState};
let mut shell = ShellExecutionState::new();
shell.start_command("cargo test", None, 4, Some(100));
assert_eq!(shell.current_command.as_ref().unwrap().status, CommandStatus::Running);
assert!(!shell.prompt_visible);Sourcepub fn finish_command(
&mut self,
exit_code: Option<i32>,
signal: Option<i32>,
line: u64,
ended_at_ms: Option<u64>,
duration_ms: Option<u64>,
)
pub fn finish_command( &mut self, exit_code: Option<i32>, signal: Option<i32>, line: u64, ended_at_ms: Option<u64>, duration_ms: Option<u64>, )
Finishes the current command, or synthesizes an empty one when idle.
A signal takes precedence over exit code and sets process Signaled;
otherwise process becomes Exited. The status event (when changed)
precedes CommandEnd. last_command is always replaced; history retains
the command only when history_limit > 0 and drops oldest excess entries.
No CommandStart event is emitted for a synthesized idle finish.
§Examples
use ailloli_ui_terminal_core::{CommandStatus, ShellExecutionState};
let mut shell = ShellExecutionState::new(); shell.start_command("false", None, 1, None);
shell.finish_command(Some(1), None, 2, None, None);
assert_eq!(shell.last_command.as_ref().unwrap().status, CommandStatus::Failed);Sourcepub fn apply_prompt_heuristic(&mut self, text: &str, line: u64) -> bool
pub fn apply_prompt_heuristic(&mut self, text: &str, line: u64) -> bool
Detects a prompt only while idle and suppresses a duplicate same-line prompt.
Returns true exactly when state changed and a PromptStart event was
appended. Detection is delegated to PromptDetector::detect_text.
§Examples
use ailloli_ui_terminal_core::ShellExecutionState;
let mut shell = ShellExecutionState::new();
assert!(shell.apply_prompt_heuristic("user@host:~$ ", 3));
assert!(!shell.apply_prompt_heuristic("user@host:~$ ", 3));Trait Implementations§
Source§impl Clone for ShellExecutionState
impl Clone for ShellExecutionState
Source§fn clone(&self) -> ShellExecutionState
fn clone(&self) -> ShellExecutionState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more