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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/// The macro that creates a [`StatusLine`]
///
/// This macro works like the [`txt!`] macro, in that [`Form`]s
/// are pushed with `[{FormName}]`. However, [`txt!`] is
/// evaluated immediately, while [`status!`] is evaluated when
/// updates occur.
///
/// The macro will mostly read from the [`Buffer`] widget and its
/// related structs. In order to do that, it will accept functions
/// as arguments. These functions can take any of the following
/// parameters, with up to 8 arguments each:
///
/// - [`&Buffer`]: The `Buffer` in question.
/// - [`&Handle`]: The `Handle` of said `Buffer`.
/// - [`&Area`]: The `Area` of said `Buffer`.
/// - [`&Pass`]: For global reading access.
/// - [`&Text`]: The `Text` of the `Buffer`.
/// - [`&Selections`]: The `Selections` of the `Buffer`.
/// - [`&Selection`]: The main `Selection` of the `Buffer`.
/// - [`&Window`]: The `Window` the `Buffer` is situated in.
///
/// Here's some examples:
///
/// ```rust
/// # duat_core::doc_duat!(duat);
/// # use duat_base::widgets::status;
/// setup_duat!(setup);
/// use duat::prelude::*;
///
/// fn name_but_funky(buf: &Buffer) -> String {
/// buf.name()
/// .chars()
/// .enumerate()
/// .map(|(i, char)| {
/// if i % 2 == 1 {
/// char.to_uppercase().to_string()
/// } else {
/// char.to_lowercase().to_string()
/// }
/// })
/// .collect()
/// }
///
/// fn powerline_main_txt(buffer: &Buffer, area: &Area) -> Text {
/// let selections = buffer.selections();
/// let opts = buffer.print_opts();
/// let v_caret = selections
/// .get_main()
/// .unwrap()
/// .v_caret(buffer.text(), area, opts);
///
/// txt!(
/// "[separator][coord]{}[separator][coord]{}[separator][coord]{}",
/// v_caret.visual_col(),
/// v_caret.line(),
/// buffer.len_lines()
/// )
/// }
///
/// fn setup() {
/// opts::fmt_status(|pa| status!("[buffer]{name_but_funky}{Spacer}{powerline_main_txt}"));
/// }
/// ```
///
/// There are other types of arguments you can push, not
/// necessarily tied to a `Buffer`:
///
/// - Static arguments:
/// - A [`Text`] argument, which can be formatted in a similar way
/// throught the [`txt!`] macro;
/// - Any [`impl Display`], such as numbers, strings, chars, etc.
/// [`impl Debug`] types also work, when including the usual
/// `":?"` and derived suffixes;
/// - Dynamic arguments:
/// - An [`RwData`] or [`DataMap`]s of the previous two types. These
/// will update whenever the data inside is changed;
///
/// Here's an examples:
///
/// ```rust
/// # duat_core::doc_duat!(duat);
/// # use duat_base::widgets::status;
/// setup_duat!(setup);
/// use std::sync::atomic::{AtomicUsize, Ordering};
///
/// use duat::prelude::*;
///
/// fn setup() {
/// let changing_str = data::RwData::new("Initial text".to_string());
///
/// fn counter(update: bool) -> usize {
/// static COUNT: AtomicUsize = AtomicUsize::new(0);
/// if update {
/// COUNT.fetch_add(1, Ordering::Relaxed) + 1
/// } else {
/// COUNT.load(Ordering::Relaxed)
/// }
/// }
///
/// hook::add::<WindowOpened>({
/// let changing_str = changing_str.clone();
/// move |pa, window| {
/// let changing_str = changing_str.clone();
/// let checker = changing_str.checker();
///
/// let text = txt!("Static text");
/// let counter = move || counter(checker());
///
/// status!("{changing_str} [counter]{counter}[] {text}")
/// .above()
/// .push_on(pa, window);
/// }
/// });
///
/// cmd::add("set-str", move |pa: &mut Pass, new: String| {
/// *changing_str.write(pa) = new.to_string();
/// Ok(None)
/// });
/// }
/// ```
///
/// In the above example, I added some dynamic [`Text`], through
/// the usage of an [`RwData<Text>`], I added some static
/// [`Text`], some [`Form`]s (`"counter"` and `"default"`) and
/// even a counter,.
///
/// [`StatusLine`]: super::StatusLine
/// [`txt!`]: duat_core::text::txt
/// [`Buffer`]: duat_core::buffer::Buffer
/// [`&Buffer`]: duat_core::buffer::Buffer
/// [`&Handle`]: duat_core::context::Handle
/// [`&Area`]: duat_core::ui::Area
/// [`&Pass`]: duat_core::data::Pass
/// [`&Text`]: duat_core::text::Text
/// [`&Selections`]: duat_core::mode::Selections
/// [`&Selection`]: duat_core::mode::Selection
/// [`&Window`]: duat_core::ui::Window
/// [`impl Display`]: std::fmt::Display
/// [`impl Debug`]: std::fmt::Debug
/// [`Text`]: duat_core::text::Text
/// [`RwData`]: duat_core::data::RwData
/// [`DataMap`]: duat_core::data::DataMap
/// [`FnOnce(&Pass) -> RwData/DataMap`]: FnOnce
/// [`(Fn(&Pass) -> Text/Display/Debug, Fn(&Pass) -> bool)`]: Fn
/// [`RwData<Text>`]: duat_core::data::RwData
/// [`Form`]: duat_core::form::Form
/// [`&Area`]: duat_core::ui::Area
/// [`Area`]: duat_core::ui::Area
/// [`Widget`]: duat_core::ui::Widget