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.
1613use std:: { collections:: HashSet , sync:: Arc , time:: Duration } ;
1714
1815use 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 ) ]
4239enum 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]
433429async fn main ( ) -> anyhow:: Result < ( ) > {
434- Byop :: try_default ( ) . await ?. spawn ( ) . await
430+ AsyncTaskPrompt :: try_default ( ) . await ?. spawn ( ) . await
435431}
0 commit comments