Skip to content

Commit fcaf6ee

Browse files
committed
[tui] Add spinner to empty-state of Telemetry HUD report display
- Add HUD to examples/demo - 0. no layout - 1. 1 col layout - 2. 2 col layout - 3. markdown editor - 4. presentation example - 5. r3bl cmdr demo
1 parent 8f0487e commit fcaf6ee

File tree

16 files changed

+527
-149
lines changed

16 files changed

+527
-149
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
"neovim",
106106
"newtype",
107107
"nextest",
108+
"nocapture",
108109
"Nodesource",
109110
"notcurses",
110111
"nushell",

1.code-search

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@
22
# Flags: CaseSensitive RegExp
33
# Excluding: scratch.rs
44

5-
1 result - 1 file
6-
7-
tui/examples/demo/ex_app_no_layout/app_main.rs:
8-
544: // REVIEW: [ ] introduce HUD telemetry & copy to all other examples
5+
No Results

terminal_async/examples/spinner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async fn example_with_concurrent_output(style: SpinnerStyle) -> miette::Result<(
6868

6969
// Start spinner. Automatically pauses the terminal.
7070
let mut maybe_spinner = Spinner::try_start(
71-
message_trying_to_connect.clone(),
71+
message_trying_to_connect,
7272
DELAY_UNIT,
7373
style,
7474
Arc::new(StdMutex::new(stderr())),

terminal_async/src/lib.rs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -190,30 +190,30 @@
190190
//!
191191
//! 1. Read user input from the terminal line by line, while your program concurrently
192192
//! writes lines to the same terminal. One [`Readline`] instance can be used to spawn
193-
//! many async `stdout` writers ([r3bl_core::SharedWriter]) that can write to
194-
//! the terminal concurrently. For most users the [`TerminalAsync`] struct is the
195-
//! simplest way to use this crate. You rarely have to access the underlying
196-
//! [`Readline`] or [`r3bl_core::SharedWriter`] directly. But you can if you
197-
//! need to. [`r3bl_core::SharedWriter`] can be cloned and is thread-safe.
198-
//! However, there is only one instance of [`Readline`] per [`TerminalAsync`] instance.
193+
//! many async `stdout` writers ([r3bl_core::SharedWriter]) that can write to the
194+
//! terminal concurrently. For most users the [`TerminalAsync`] struct is the simplest
195+
//! way to use this crate. You rarely have to access the underlying [`Readline`] or
196+
//! [`r3bl_core::SharedWriter`] directly. But you can if you need to.
197+
//! [`r3bl_core::SharedWriter`] can be cloned and is thread-safe. However, there is
198+
//! only one instance of [`Readline`] per [`TerminalAsync`] instance.
199199
//!
200200
//! 2. Generate a spinner (indeterminate progress indicator). This spinner works
201201
//! concurrently with the rest of your program. When the [`Spinner`] is active it
202-
//! automatically pauses output from all the [`r3bl_core::SharedWriter`]
203-
//! instances that are associated with one [`Readline`] instance. Typically a spawned
204-
//! task clones its own [`r3bl_core::SharedWriter`] to generate its output.
205-
//! This is useful when you want to show a spinner while waiting for a long-running
206-
//! task to complete. Please look at the example to see this in action, by running
207-
//! `cargo run --example terminal_async`. Then type `starttask1`, press Enter. Then
208-
//! type `spinner`, press Enter.
202+
//! automatically pauses output from all the [`r3bl_core::SharedWriter`] instances that
203+
//! are associated with one [`Readline`] instance. Typically a spawned task clones its
204+
//! own [`r3bl_core::SharedWriter`] to generate its output. This is useful when you
205+
//! want to show a spinner while waiting for a long-running task to complete. Please
206+
//! look at the example to see this in action, by running `cargo run --example
207+
//! terminal_async`. Then type `starttask1`, press Enter. Then type `spinner`, press
208+
//! Enter.
209209
//!
210210
//! 3. Use tokio tracing with support for concurrent `stout` writes. If you choose to log
211-
//! to `stdout` then the concurrent version ([`r3bl_core::SharedWriter`]) from
212-
//! this crate will be used. This ensures that the concurrent output is supported even
213-
//! for your tracing logs to `stdout`.
211+
//! to `stdout` then the concurrent version ([`r3bl_core::SharedWriter`]) from this
212+
//! crate will be used. This ensures that the concurrent output is supported even for
213+
//! your tracing logs to `stdout`.
214214
//!
215215
//! 4. You can also plug in your own terminal, like `stdout`, or `stderr`, or any other
216-
//! terminal that implements [`SendRawTerminal`] trait for more details.
216+
//! terminal that implements [r3bl_core::SendRawTerminal] trait for more details.
217217
//!
218218
//! This crate can detect when your terminal is not in interactive mode. Eg: when you pipe
219219
//! the output of your program to another program. In this case, the `readline` feature is
@@ -237,20 +237,20 @@
237237
//! - [LineState::is_paused] - Used to check if the line state is paused and affects
238238
//! rendering and input.
239239
//! - [LineState::set_paused] - Use to set the paused state via the
240-
//! [r3bl_core::SharedWriter] below. This can't be called directly (outside the
241-
//! crate itself).
242-
//! - [r3bl_core::SharedWriter::line_state_control_channel_sender] - Mechanism
243-
//! used to manipulate the paused state.
240+
//! [r3bl_core::SharedWriter] below. This can't be called directly (outside the crate
241+
//! itself).
242+
//! - [r3bl_core::SharedWriter::line_state_control_channel_sender] - Mechanism used to
243+
//! manipulate the paused state.
244244
//!
245245
//! The [Readline::new] or [TerminalAsync::try_new] create a `line_channel` to send and
246246
//! receive [r3bl_core::LineStateControlSignal]:
247-
//! 1. The sender end of this channel is moved to the [r3bl_core::SharedWriter].
248-
//! So any [r3bl_core::SharedWriter] can be used to send
249-
//! [r3bl_core::LineStateControlSignal]s to the channel, which will be
250-
//! processed in the task started, just for this, in [Readline::new]. This is the
251-
//! primary mechanism to switch between pause and resume. Some helper functions are
252-
//! provided in [TerminalAsync::pause] and [TerminalAsync::resume], though you can just
253-
//! send the signals directly to the channel's sender via the
247+
//! 1. The sender end of this channel is moved to the [r3bl_core::SharedWriter]. So any
248+
//! [r3bl_core::SharedWriter] can be used to send [r3bl_core::LineStateControlSignal]s
249+
//! to the channel, which will be processed in the task started, just for this, in
250+
//! [Readline::new]. This is the primary mechanism to switch between pause and resume.
251+
//! Some helper functions are provided in [TerminalAsync::pause] and
252+
//! [TerminalAsync::resume], though you can just send the signals directly to the
253+
//! channel's sender via the
254254
//! [r3bl_core::SharedWriter::line_state_control_channel_sender].
255255
//! 2. The receiver end of this [tokio::sync::mpsc::channel] is moved to the task that is
256256
//! spawned by [Readline::new]. This is where the actual work is done when signals are
@@ -338,8 +338,8 @@
338338
//! the user can retrieve it while editing a later line), call
339339
//! [`Readline::add_history_entry()`].
340340
//!
341-
//! - Lines written to the associated [`r3bl_core::SharedWriter`] while
342-
//! `readline()` is in progress will be output to the screen above the input line.
341+
//! - Lines written to the associated [`r3bl_core::SharedWriter`] while `readline()` is in
342+
//! progress will be output to the screen above the input line.
343343
//!
344344
//! - When done, call [`crate::manage_shared_writer_output::flush_internal()`] to ensure
345345
//! that all lines written to the [`r3bl_core::SharedWriter`] are output.
@@ -351,9 +351,9 @@
351351
//! that the program is still running and hasn't hung up or become unresponsive. When
352352
//! other tasks produce output concurrently, this spinner's output will not be clobbered.
353353
//! Neither will the spinner output clobber the output from other tasks. It suspends the
354-
//! output from all the [`r3bl_core::SharedWriter`] instances that are associated
355-
//! with one [`Readline`] instance. Both the `terminal_async.rs` and `spinner.rs` examples
356-
//! shows this (`cargo run --example terminal_async` and `cargo run --example spinner`).
354+
//! output from all the [`r3bl_core::SharedWriter`] instances that are associated with one
355+
//! [`Readline`] instance. Both the `terminal_async.rs` and `spinner.rs` examples shows
356+
//! this (`cargo run --example terminal_async` and `cargo run --example spinner`).
357357
//!
358358
//! [`Spinner`]s also has cancellation support. Once a spinner is started,
359359
//! <kbd>Ctrl+C</kbd> and <kbd>Ctrl+D</kbd> are directed to the spinner, to cancel it.
@@ -417,8 +417,8 @@
417417
//! - Rearchitect the entire crate from the ground up to operate in a totally different
418418
//! manner than the original. All the underlying mental models are different, and
419419
//! simpler. The main event loop is redone. And a task is used to monitor the line
420-
//! channel for communication between multiple [`r3bl_core::SharedWriter`]s and
421-
//! the [`Readline`], to properly support pause and resume, and other control functions.
420+
//! channel for communication between multiple [`r3bl_core::SharedWriter`]s and the
421+
//! [`Readline`], to properly support pause and resume, and other control functions.
422422
//! - Drop support for all async runtimes other than `tokio`. Rewrite all the code for
423423
//! this.
424424
//! - Drop crates like `pin-project`, `thingbuf` in favor of `tokio`. Rewrite all the code

tui/README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ commands:
185185

186186
```sh
187187
cd tui/examples
188-
cargo run --release --example demo
188+
cargo run --release --example demo -- --no-log
189189
```
190190

191191
These examples cover the entire surface area of the TUI API. You can also take a look
@@ -198,13 +198,29 @@ allows you to easily build, run, test, and do so much more with the repo.
198198
199199
## Nushell scripts to build, run, test etc.
200200

201+
Typically in the `tui` sub folder of the repo, you will run the following commands,
202+
each in a separate terminal window or pane.
203+
204+
```sh
205+
# Terminal 1, run this first.
206+
cd tui
207+
nu run log
208+
```
209+
210+
```sh
211+
# Terminal 2, run this second.
212+
cd tui
213+
nu run release-examples
214+
```
215+
201216
| Command | Description |
202217
| -------------------------------------- | ------------------------------------------------- |
218+
| `nu run log` | View the log output. This [video](https://youtu.be/Sy26IMkOEiM) has a walkthrough of how to use this. |
219+
| `nu run examples` | Run all the examples, with logging |
220+
| `nu run release-examples` | Run all the examples with the release binary, with logging |
221+
| `nu run release-examples-no-log` | Run all the examples with the release binary, no logging |
203222
| `nu run help` | See all the commands you can pass to the `run` script |
204-
| `nu run examples` | Run all the examples |
205-
| `nu run release-examples` | Run all the examples with the release binary |
206223
| `nu run examples-with-flamegraph-profiling` | This will run the examples and generate a flamegraph at the end so you can see profile the performance of the app. This [video](https://www.youtube.com/watch?v=Sy26IMkOEiM) has a walkthrough of how to use this |
207-
| `nu run log` | View the log output. This [video](https://www.youtube.com/watch?v=Sy26IMkOEiM) has a walkthrough of how to use this. |
208224
| `nu run build` | Build |
209225
| `nu run clean` | Clean |
210226
| `nu run test` | Run tests |

tui/examples/demo/ex_app_no_layout/app_main.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,12 @@ mod app_main_impl_trait_app {
293293
acc_render_ops
294294
});
295295

296-
status_bar::create_status_bar_message(&mut pipeline, window_size);
296+
status_bar::render_status_bar(&mut pipeline, window_size);
297297

298298
hud::create_hud(
299299
&mut pipeline,
300300
window_size,
301-
global_data.get_hud_report_as_str(),
301+
global_data.get_hud_report_with_spinner(),
302302
);
303303

304304
// Handle animation.
@@ -541,8 +541,6 @@ mod app_main_impl_trait_app {
541541
}
542542
}
543543

544-
// REVIEW: [ ] introduce HUD telemetry & copy to all other examples
545-
546544
mod hud {
547545
use super::*;
548546

@@ -579,7 +577,7 @@ mod status_bar {
579577
use super::*;
580578

581579
/// Shows helpful messages at the bottom row of the screen.
582-
pub fn create_status_bar_message(pipeline: &mut RenderPipeline, size: Dim) {
580+
pub fn render_status_bar(pipeline: &mut RenderPipeline, size: Dim) {
583581
let color_bg = TuiColor::Rgb(RgbValue::from_hex("#076DEB"));
584582
let color_fg = TuiColor::Rgb(RgbValue::from_hex("#E9C940"));
585583
let styled_texts = tui_styled_texts! {

tui/examples/demo/ex_app_with_1col_layout/app_main.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
1718
use r3bl_core::{col,
1819
height,
1920
req_size_pc,
@@ -199,14 +200,11 @@ mod app_main_impl_app_trait {
199200
hud::create_hud(
200201
&mut surface.render_pipeline,
201202
window_size,
202-
global_data.get_hud_report_as_str(),
203+
global_data.get_hud_report_with_spinner(),
203204
);
204205

205206
// Render status bar.
206-
status_bar::create_status_bar_message(
207-
&mut surface.render_pipeline,
208-
window_size,
209-
);
207+
status_bar::render_status_bar(&mut surface.render_pipeline, window_size);
210208

211209
// Return RenderOps pipeline (which will actually be painted elsewhere).
212210
surface.render_pipeline
@@ -297,19 +295,10 @@ mod stylesheet {
297295
}
298296
}
299297

300-
// REVIEW: [ ] add HUD here
301-
302298
mod hud {
303-
use std::borrow::Cow;
304-
305299
use super::*;
306300

307-
pub fn create_hud(pipeline: &mut RenderPipeline, size: Dim, arg_hud_report: &str) {
308-
let mut hud_report_str = Cow::Borrowed(arg_hud_report);
309-
if hud_report_str.is_empty() {
310-
hud_report_str = Cow::Borrowed("⠎ Collecting data ...");
311-
}
312-
301+
pub fn create_hud(pipeline: &mut RenderPipeline, size: Dim, hud_report_str: &str) {
313302
let color_bg = TuiColor::Rgb(RgbValue::from_hex("#fdb6fd"));
314303
let color_fg = TuiColor::Rgb(RgbValue::from_hex("#942997"));
315304
let styled_texts = tui_styled_texts! {
@@ -342,7 +331,7 @@ mod status_bar {
342331
use super::*;
343332

344333
/// Shows helpful messages at the bottom row of the screen.
345-
pub fn create_status_bar_message(pipeline: &mut RenderPipeline, size: Dim) {
334+
pub fn render_status_bar(pipeline: &mut RenderPipeline, size: Dim) {
346335
let color_bg = TuiColor::Rgb(RgbValue::from_hex("#076DEB"));
347336
let color_fg = TuiColor::Rgb(RgbValue::from_hex("#E9C940"));
348337
let styled_texts = tui_styled_texts! {

0 commit comments

Comments
 (0)