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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//! A small lifecycle runtime for sequential, interactive prompts.
//!
//! This module owns prompt lifecycle and event delivery. Applications remain
//! responsible for terminal setup and teardown, composing widgets, mapping
//! events to state changes, rendering updates, focus management, validation,
//! and quit policy.
use LazyLock;
use StreamExt;
use Mutex;
use crate;
/// The singleton terminal event stream used by [`Prompt::run`].
///
/// A single stream is shared because repeatedly constructing an [`EventStream`]
/// can cause crossterm cursor-position reads to time out. See
/// [crossterm issue #963](https://github.com/crossterm-rs/crossterm/issues/963#issuecomment-2571259264).
///
/// Access is serialized by a [`Mutex`]. Consequently, [`Prompt::run`] is
/// intended for one active prompt at a time, not for concurrently running
/// prompts. Applications that need to combine terminal events with background
/// work or application events should own their event loop instead.
pub static EVENT_STREAM: =
new;
/// Indicates whether [`Prompt::run`] should continue reading terminal events.
/// Defines the lifecycle of a sequential, interactive prompt.
///
/// `Prompt` provides lifecycle hooks around the event loop implemented by
/// [`Prompt::run`]:
///
/// 1. [`Prompt::initialize`] prepares and normally renders the initial state.
/// 2. [`Prompt::evaluate`] handles each non-resize terminal event in order.
/// 3. [`Prompt::finalize`] produces the prompt's return value after the loop
/// ends.
///
/// Implementors own their widget state, renderer, key bindings, focus
/// transitions, validation, and quit conditions. This trait does not prescribe
/// how an event changes a widget and is not intended to replace an
/// application-specific event loop.