Skip to content

Commit 78521d8

Browse files
committed
examples: rename BYOP demo to async task
1 parent 5f337b0 commit 78521d8

4 files changed

Lines changed: 19 additions & 23 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,20 +222,20 @@ cargo run --bin text
222222
These examples demonstrate how to compose widgets and rendering primitives for
223223
application-specific event loops and asynchronous workflows.
224224

225-
### BYOP
225+
### Async Task with Spinner
226226

227227
<details>
228228
<summary>Command</summary>
229229

230230
```bash
231-
cargo run --bin byop
231+
cargo run --bin async_task
232232
```
233233

234234
</details>
235235

236-
[Code](./examples/byop/src/byop.rs)
236+
[Code](./examples/async_task/src/async_task.rs)
237237

238-
<img src="https://github.com/ynqa/ynqa/blob/master/demo/promkit/byop.gif" width="50%" height="auto">
238+
<img src="https://github.com/ynqa/ynqa/blob/master/demo/promkit/async_task.gif" width="50%" height="auto">
239239

240240
### Multiline REPL
241241

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "byop"
2+
name = "async-task"
33
version = "0.1.0"
44
edition = "2021"
55
publish = false
@@ -9,5 +9,5 @@ promkit = { path = "../../promkit", features = ["readline", "spinner"] }
99
tokio = { workspace = true }
1010

1111
[[bin]]
12-
name = "byop"
13-
path = "src/byop.rs"
12+
name = "async_task"
13+
path = "src/async_task.rs"
Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
/// BYOP (Build Your Own Preset) example for promkit.
1+
/// Async task with spinner example for promkit.
22
///
3-
/// This example demonstrates how to create a custom prompt using the `promkit` library.
3+
/// This example demonstrates how to create a responsive prompt that runs a background task.
44
/// It includes a text editor for input, a spinner for async task execution, and a task
5-
/// monitor for managing background tasks.
5+
/// monitor for coordinating task state and rendered results.
66
/// The prompt allows users to enter text, start a heavy task (actually a simulated delay),
77
/// and see the results (actually show the input text) or errors
88
/// displayed in the UI. The example showcases the integration of various widgets and state
99
/// management techniques to create a responsive and interactive command-line application.
1010
///
11-
/// # Example Usage
12-
/// To run this example, ensure you have the `promkit` library and its dependencies set up in
13-
/// your Rust project. Then, execute the main function which initializes the BYOP prompt and
14-
/// starts the event loop. You can interact with the prompt by typing commands and pressing
15-
/// Enter to execute tasks. Use Ctrl+C to exit the prompt.
11+
/// Type text and press Enter to start the task. The editor remains responsive while the
12+
/// spinner is active. Use Ctrl+C to exit the prompt.
1613
use std::{collections::HashSet, sync::Arc, time::Duration};
1714

1815
use promkit::{
@@ -37,7 +34,7 @@ use tokio::{
3734
task::JoinHandle,
3835
};
3936

40-
/// Represents the indices of various components in BYOP.
37+
/// Represents the indices of the async task prompt components.
4138
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
4239
enum Index {
4340
Readline = 0,
@@ -153,16 +150,15 @@ impl TaskMonitor {
153150
}
154151
}
155152

156-
/// Build Your Own Prompt
157-
struct Byop {
153+
struct AsyncTaskPrompt {
158154
renderer: SharedRenderer<Index>,
159155
task_monitor: Arc<TaskMonitor>,
160156
readline: text_editor::State,
161157
spinner: Arc<spinner::Spinner>,
162158
}
163159

164160
#[async_trait::async_trait]
165-
impl Prompt for Byop {
161+
impl Prompt for AsyncTaskPrompt {
166162
async fn initialize(&mut self) -> anyhow::Result<()> {
167163
Ok(())
168164
}
@@ -188,7 +184,7 @@ impl Prompt for Byop {
188184
}
189185
}
190186

191-
impl Byop {
187+
impl AsyncTaskPrompt {
192188
async fn try_default() -> anyhow::Result<Self> {
193189
let readline = text_editor::State {
194190
config: text_editor::config::Config {
@@ -431,5 +427,5 @@ impl Byop {
431427

432428
#[tokio::main]
433429
async fn main() -> anyhow::Result<()> {
434-
Byop::try_default().await?.spawn().await
430+
AsyncTaskPrompt::try_default().await?.spawn().await
435431
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Output tapes/byop.gif
1+
Output tapes/async_task.gif
22

33
Require cargo
44

@@ -8,7 +8,7 @@ Set FontSize 32
88
Set Width 1200
99
Set Height 600
1010

11-
Type@50ms "cargo run -q --bin byop" Enter Sleep 4s
11+
Type@50ms "cargo run -q --bin async_task" Enter Sleep 4s
1212
Type@50ms "background task" Sleep 1s
1313
Enter Sleep 1s
1414
Type@50ms " + live edit" Sleep 3s

0 commit comments

Comments
 (0)