pub enum TerminalState {
Created,
Running,
ShuttingDown,
Closed,
}Expand description
STATE MACHINE: TerminalInstance
Tracks the lifecycle of a PTY-backed terminal instance.
State Diagram:
Created ──────► Running ──────► ShuttingDown ──────► Closed │ ▲ │ (process exit, │ │ read error) │ └────────────────────────────────────┘
Transitions: Created -> Running (start signal sent via start_sender channel) Running -> ShuttingDown (shutdown_signal flag set to true) Running -> Closed (PTY process exits, reader thread detects EOF) ShuttingDown -> Closed (reader thread sees shutdown flag, exits loop)
Concurrency Invariant: Terminal I/O uses std::sync::Mutex (not tokio) because PTY operations are synchronous. The reader thread runs on a dedicated OS thread (not tokio task). ShutdownSignal uses AtomicBool for lock-free cross-thread signaling. State transitions should be synchronized through the TerminalManager’s terminals Mutex.
Interruption Table: ┌──────────────┬──────────────────────────────────────────────────────────┐ │ State │ What happens on crash/error │ ├──────────────┼──────────────────────────────────────────────────────────┤ │ Created │ PTY allocated but reader waiting for start signal. │ │ │ If app crashes: PTY master handle dropped, slave exits. │ │ │ start_sender channel dropped, reader thread unblocks │ │ │ and exits (recv() returns Err). │ ├──────────────┼──────────────────────────────────────────────────────────┤ │ Running │ Reader thread actively reading PTY output. │ │ │ If app crashes: PTY handles dropped, OS cleans up. │ │ │ If shell process exits: reader gets EOF, -> Closed. │ │ │ If reader thread panics: JoinHandle::join returns Err. │ │ │ Writer can still try to write (will get error). │ ├──────────────┼──────────────────────────────────────────────────────────┤ │ ShuttingDown │ Shutdown flag set. Reader thread checking flag each │ │ │ iteration. May take up to one read timeout to notice. │ │ │ If reader hangs on blocking read: may not shut down │ │ │ gracefully. Consider: close PTY master to force EOF. │ ├──────────────┼──────────────────────────────────────────────────────────┤ │ Closed │ Reader thread joined. PTY resources released. │ │ │ Terminal entry removed from TerminalManager map. │ └──────────────┴──────────────────────────────────────────────────────────┘
Variants§
Trait Implementations§
Source§impl Clone for TerminalState
impl Clone for TerminalState
Source§fn clone(&self) -> TerminalState
fn clone(&self) -> TerminalState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TerminalState
impl Debug for TerminalState
Source§impl PartialEq for TerminalState
impl PartialEq for TerminalState
impl Copy for TerminalState
impl Eq for TerminalState
impl StructuralPartialEq for TerminalState
Auto Trait Implementations§
impl Freeze for TerminalState
impl RefUnwindSafe for TerminalState
impl Send for TerminalState
impl Sync for TerminalState
impl Unpin for TerminalState
impl UnsafeUnpin for TerminalState
impl UnwindSafe for TerminalState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.