|
190 | 190 | //!
|
191 | 191 | //! 1. Read user input from the terminal line by line, while your program concurrently
|
192 | 192 | //! 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. |
199 | 199 | //!
|
200 | 200 | //! 2. Generate a spinner (indeterminate progress indicator). This spinner works
|
201 | 201 | //! 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. |
209 | 209 | //!
|
210 | 210 | //! 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`. |
214 | 214 | //!
|
215 | 215 | //! 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. |
217 | 217 | //!
|
218 | 218 | //! This crate can detect when your terminal is not in interactive mode. Eg: when you pipe
|
219 | 219 | //! the output of your program to another program. In this case, the `readline` feature is
|
|
237 | 237 | //! - [LineState::is_paused] - Used to check if the line state is paused and affects
|
238 | 238 | //! rendering and input.
|
239 | 239 | //! - [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. |
244 | 244 | //!
|
245 | 245 | //! The [Readline::new] or [TerminalAsync::try_new] create a `line_channel` to send and
|
246 | 246 | //! 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 |
254 | 254 | //! [r3bl_core::SharedWriter::line_state_control_channel_sender].
|
255 | 255 | //! 2. The receiver end of this [tokio::sync::mpsc::channel] is moved to the task that is
|
256 | 256 | //! spawned by [Readline::new]. This is where the actual work is done when signals are
|
|
338 | 338 | //! the user can retrieve it while editing a later line), call
|
339 | 339 | //! [`Readline::add_history_entry()`].
|
340 | 340 | //!
|
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. |
343 | 343 | //!
|
344 | 344 | //! - When done, call [`crate::manage_shared_writer_output::flush_internal()`] to ensure
|
345 | 345 | //! that all lines written to the [`r3bl_core::SharedWriter`] are output.
|
|
351 | 351 | //! that the program is still running and hasn't hung up or become unresponsive. When
|
352 | 352 | //! other tasks produce output concurrently, this spinner's output will not be clobbered.
|
353 | 353 | //! 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`). |
357 | 357 | //!
|
358 | 358 | //! [`Spinner`]s also has cancellation support. Once a spinner is started,
|
359 | 359 | //! <kbd>Ctrl+C</kbd> and <kbd>Ctrl+D</kbd> are directed to the spinner, to cancel it.
|
|
417 | 417 | //! - Rearchitect the entire crate from the ground up to operate in a totally different
|
418 | 418 | //! manner than the original. All the underlying mental models are different, and
|
419 | 419 | //! 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. |
422 | 422 | //! - Drop support for all async runtimes other than `tokio`. Rewrite all the code for
|
423 | 423 | //! this.
|
424 | 424 | //! - Drop crates like `pin-project`, `thingbuf` in favor of `tokio`. Rewrite all the code
|
|
0 commit comments