1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use TerminalSize;
use crateExitStatus;
/// Push-style observer for raw I/O and lifecycle events on a [`Session`].
///
/// `on_output` and `on_input` are required; `on_resize` and `on_exit` have
/// empty default implementations so impls can opt in to the lifecycle hooks
/// they care about.
///
/// # Threading
///
/// Callbacks run on driver-internal threads:
///
/// - `on_output` runs on the PTY reader thread, before the screen parser
/// sees the bytes.
/// - `on_input` runs on the PTY writer thread, after the bytes have been
/// written to and flushed through the PTY writer.
/// - `on_resize` runs on the thread that called [`Session::resize`].
/// - `on_exit` runs on the driver's exit-reaper thread.
///
/// # Convention: do not block
///
/// Callbacks must return promptly. Blocking inside `on_output` stalls the
/// PTY reader thread, which in turn stalls every subsequent screen update.
/// The expected pattern is to push the chunk into a channel and return; a
/// dedicated consumer thread or task drains the channel and does any heavy
/// work (file I/O, JSON encoding, ...) off the reader thread.
///
/// [`Session`]: crate::Session
/// [`Session::resize`]: crate::Session::resize