Struct ShellExecutionState

Source
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: ShellKind

Detected/configured shell family.

§process_status: TerminalProcessStatus

Shell/PTY process lifecycle.

§cwd_uri: Option<String>

Current working-directory URI, or None when unknown.

§prompt_visible: bool

Whether 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: usize

Maximum retained history count; zero disables history retention.

§next_command_id: u64

Next 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

Source

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);
Source

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"));
Source

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());
Source

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);
Source

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);
Source

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);
Source

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));
Source

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);
Source

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);
Source

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

Source§

fn clone(&self) -> ShellExecutionState

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ShellExecutionState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ShellExecutionState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ShellExecutionState

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ShellExecutionState

Source§

fn eq(&self, other: &ShellExecutionState) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ShellExecutionState

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for ShellExecutionState

Source§

impl StructuralPartialEq for ShellExecutionState

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,