pub struct KeyWatcher { /* private fields */ }Expand description
Handle the supervisor holds while the watcher is running.
Dropping (or calling shutdown) tears the thread down,
disables raw mode, and stops keystroke delivery.
Implementations§
Source§impl KeyWatcher
impl KeyWatcher
Sourcepub fn spawn(tx: Sender<WatcherSignal>) -> Option<Self>
pub fn spawn(tx: Sender<WatcherSignal>) -> Option<Self>
Spawn the watcher. Returns None when stdin is not a
TTY (piped / CI / backgrounded — no keystrokes possible).
The signal channel tx receives one WatcherSignal
per recognised keystroke; the supervisor owns the
receiver.
On construction, raw mode is enabled on the process terminal. Do not call this if another component (e.g. an active TUI app) currently owns stdin — use the supervisor’s start/stop dance instead.
Sourcepub fn shutdown(self)
pub fn shutdown(self)
Cooperative stop. Disables raw mode after the polling thread exits so subsequent stderr / stdout writes use normal line endings again. Idempotent — safe to call after the thread has already exited (the second call is a no-op).
The join is BOUNDED. The watcher thread can be wedged in
a kernel read() on a tty that will never deliver
another byte — observed under PTY test harnesses, where
crossterm’s poll reports readiness but the subsequent
blocking read never returns. A thread stuck in read()
cannot be interrupted portably; waiting on it wedged the
entire teardown chain (sink-supervisor → run teardown →
process exit) behind a keystroke that will never come.
After the grace window the thread is deliberately leaked
— process exit reaps it.
Auto Trait Implementations§
impl !RefUnwindSafe for KeyWatcher
impl !UnwindSafe for KeyWatcher
impl Forget for KeyWatcher
impl Freeze for KeyWatcher
impl Move for KeyWatcher
impl Send for KeyWatcher
impl Sync for KeyWatcher
impl Unpin for KeyWatcher
impl UnsafeUnpin for KeyWatcherwhere
*const ArcInner<Atomic<bool>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Atomic<bool>>>: UnsafeUnpin,
*const ArcInner<Inner> is !null: UnsafeUnpin,
PhantomData<ArcInner<Inner>>: UnsafeUnpin,
*const ArcInner<Packet<'static, ()>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Packet<'static, ()>>>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more