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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//! Interactive terminal components for rs-rich (#451): the layer between
//! printing and a full TUI framework.
//!
//! A [`Component`] is a state machine: it handles one [`Event`] and renders
//! one [`View`]. Two drivers run it:
//!
//! - **blocking:** [`run`] takes the terminal, drives the component to an
//! [`Outcome`] and gives the terminal back, like `Prompt.ask`;
//! - **event loop:** an [`EventLoop`] runs one or more components at once,
//! with ticks and timers, and repaints only when something changed.
//!
//! Views are painted through [`rich_ext::frame::Frame::diff`], cell by cell,
//! so an idle loop writes nothing. Around them:
//!
//! - [`session`]: raw mode, the alternate screen, mouse and paste, restored
//! on every way out, including a panic, Ctrl+C and a hand-off to another
//! program (#489);
//! - [`event`]: keys, mouse, resizes and pastes, from `crossterm`;
//! - [`viewport`]: a scrollable window over rendered lines (#495);
//! - [`item`]: one item model behind every picker (#452);
//! - [`policy`]: with no terminal, under CI or with `TERM=dumb`, a
//! component asks line by line, returns its default, or fails, as the
//! caller chooses, and never blocks on a pipe (#492);
//! - [`headless`]: scripted events in, frames out, for tests;
//! - [`components`]: [`Select`], [`MultiSelect`], [`TableSelect`],
//! [`TreeSelect`], [`Input`], [`TextArea`], [`Confirm`], [`Form`],
//! [`Pager`], [`FilePicker`], [`ColorPicker`], [`AssetPicker`] and
//! [`ThemePicker`], built on the above with a [`fuzzy`] matcher, and with
//! the `data` feature `DataExplorer`, for JSON, YAML, TOML and the other
//! formats `rich_ext::data` reads;
//! - [`clipboard`]: copy to the terminal's clipboard with OSC 52, when it
//! takes it.
//!
//! Components compose (0.0.14): [`compose`] has containers that are
//! components themselves ([`Column`], [`Row`], [`Stack`], [`Split`],
//! [`Tabs`], [`Layers`]), with focus, routing and bubbling
//! ([`Flow::Ignored`]); [`kit`] has the line helpers and state types the
//! built-ins are made of; and [`keymap`] declares, rebinds and lists every
//! component's keys. On top of those, [`overlay`] has a command palette, a
//! help overlay, a shortcut sheet and an action menu read from the keymap,
//! and [`chrome`] a status bar and breadcrumbs; [`Overlays`] wires them all
//! into any component.
//!
//! Mouse support (#476) is opt-in per component ([`Component::mouse`]):
//! clicks, drags and the wheel arrive in the component's own coordinates, a
//! click on a hyperlink arrives as [`Event::Link`], and the border beside a
//! preview drags. Actions (#491) attach to list items, table rows, tree
//! nodes and file entries through [`Actions`] and an [`ActionTarget`], and
//! open in a modal menu (Ctrl+K); a region takes actions too, through
//! [`Overlays::actions`]; plugins register them through
//! `rs-rich-plugin-api`. Plugins register whole components too, and
//! [`PluginView`] mounts one by name beside the built-ins ([`plugin`]).
//!
//! ```
//! use rich_interact::{headless, Component, Context, Event, Flow, KeyCode, Outcome, View};
//!
//! /// Counts Up presses; Enter returns the count.
//! struct Counter(u32);
//!
//! impl Component for Counter {
//! type Output = u32;
//! fn handle(&mut self, event: &Event, _: &Context<'_>) -> Flow<u32> {
//! match event.key().map(|key| key.code) {
//! Some(KeyCode::Up) => self.0 += 1,
//! Some(KeyCode::Enter) => return Flow::Done(self.0),
//! _ => {}
//! }
//! Flow::Continue
//! }
//! fn render(&self, context: &Context<'_>) -> View {
//! View::new(context.markup(&format!("count: [bold]{}[/]", self.0)))
//! }
//! }
//!
//! let script = headless::Script::new().keys("up up enter");
//! let (outcome, record) = headless::run(Counter(0), script, 40, 5);
//! assert_eq!(outcome.unwrap(), Outcome::Done(2));
//! assert_eq!(record.last_frame(), "count: 2");
//! ```
pub use ;
pub use ;
pub use DataExplorer;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use PluginView;
pub use ;
pub use ;
pub use Viewport;
/// Forward every [`Component`] method to `(**self)`.
/// A component borrowed mutably is a component, so a caller can mount one
/// and still read its state after the loop.
/// A boxed component is a component: how containers hold children of
/// different types with one output ([`compose::Child`]).