Struct TerminalAsync

Source
pub struct TerminalAsync {
    pub readline: Readline,
    pub shared_writer: SharedWriter,
}

Fields§

§readline: Readline§shared_writer: SharedWriter

Implementations§

Source§

impl TerminalAsync

Source

pub async fn try_new(prompt: &str) -> Result<Option<TerminalAsync>>

Create a new instance of TerminalAsync. Example of prompt is "> ".

§Example

Here’s an example of how to use this method:

async fn foo() -> miette::Result<()> {
    use r3bl_terminal_async::TerminalAsync;
    let terminal_async = TerminalAsync::try_new("> ")
        .await?
        .ok_or_else(|| miette::miette!("Failed to create terminal"))?;
    r3bl_core::ok!()
}

Another example:

async fn foo() -> miette::Result<()> {
    use r3bl_terminal_async::TerminalAsync;
    let Some(mut terminal_async) = TerminalAsync::try_new("> ").await? else {
        return Err(miette::miette!("Failed to create terminal"));
    };
    r3bl_core::ok!()
}
§Returns
  1. If the terminal is not fully interactive then it will return None, and won’t create the Readline. This is when the terminal is not considered fully interactive:
    • stdout is piped, eg: echo "foo" | cargo run --example spinner.
    • or all three stdin, stdout, stderr are not is_tty, eg when running in cargo test.
  2. Otherwise, it will return a TerminalAsync instance.
  3. In case there are any issues putting the terminal into raw mode, or getting the terminal size, it will return an error.

More info on terminal piping:

Examples found in repository?
examples/shell_async.rs (line 292)
284    pub async fn new(pid: u32) -> miette::Result<TerminalAsyncHandle> {
285        let prompt = {
286            let prompt_seg_1 = "╭".magenta().on_dark_grey().to_string();
287            let prompt_seg_2 = format!("┤{pid}├").magenta().on_dark_grey().to_string();
288            let prompt_seg_3 = "╮".magenta().on_dark_grey().to_string();
289            format!("{}{}{} ", prompt_seg_1, prompt_seg_2, prompt_seg_3)
290        };
291
292        let Ok(Some(terminal_async)) = TerminalAsync::try_new(prompt.as_str()).await
293        else {
294            miette::bail!("Failed to create TerminalAsync instance");
295        };
296
297        let shared_writer = terminal_async.clone_shared_writer();
298
299        ok!(TerminalAsyncHandle {
300            terminal_async,
301            shared_writer
302        })
303    }
More examples
Hide additional examples
examples/spinner.rs (line 62)
61async fn example_with_concurrent_output(style: SpinnerStyle) -> miette::Result<()> {
62    let terminal_async = TerminalAsync::try_new("$ ").await?;
63    let terminal_async = terminal_async.expect("terminal is not fully interactive");
64    let address = "127.0.0.1:8000";
65    let message_trying_to_connect = format!(
66        "This is a sample indeterminate progress message: trying to connect to server on {}",
67        &address
68    );
69
70    let mut shared_writer = terminal_async.clone_shared_writer();
71
72    // Start spinner. Automatically pauses the terminal.
73    let mut maybe_spinner = Spinner::try_start(
74        message_trying_to_connect.clone(),
75        DELAY_UNIT,
76        style,
77        Arc::new(StdMutex::new(stderr())),
78        shared_writer.clone(),
79    )
80    .await?;
81
82    // Start another task, to simulate some async work, that uses a interval to display
83    // output, for a fixed amount of time, using `terminal_async.println_prefixed()`.
84    let _ = try_join!(tokio::spawn(async move {
85        // To calculate the delay.
86        let duration = ARTIFICIAL_UI_DELAY;
87        let start = Instant::now();
88
89        // Dropping the interval cancels it.
90        let mut interval = tokio::time::interval(Duration::from_millis(DELAY_MS * 5));
91
92        loop {
93            interval.tick().await;
94            let elapsed = start.elapsed();
95            if elapsed >= duration {
96                break;
97            }
98            let _ = writeln!(shared_writer, "⏳foo");
99        }
100    }));
101
102    // Stop spinner. Automatically resumes the terminal.
103    if let Some(spinner) = maybe_spinner.as_mut() {
104        spinner
105            .stop("This is a sample final message for the spinner component: Connected to server")
106            .await?;
107    }
108
109    tokio::time::sleep(Duration::from_millis(500)).await;
110
111    Ok(())
112}
examples/terminal_async.rs (line 145)
138async fn main() -> miette::Result<()> {
139    let prompt = {
140        let prompt_seg_1 = "╭>╮".magenta().on_dark_grey().to_string();
141        let prompt_seg_2 = " ".to_string();
142        format!("{}{}", prompt_seg_1, prompt_seg_2)
143    };
144
145    let maybe_terminal_async = TerminalAsync::try_new(prompt.as_str()).await?;
146
147    // If the terminal is not fully interactive, then return early.
148    let Some(mut terminal_async) = maybe_terminal_async else {
149        return Ok(());
150    };
151
152    // Pre-populate the readline's history with some entries.
153    for command in Command::iter() {
154        terminal_async
155            .readline
156            .add_history_entry(command.to_string());
157    }
158
159    // Initialize tracing w/ the "async stdout" (SharedWriter), and file writer.
160    TracingConfig::new_file_and_display(
161        None,
162        DisplayPreference::SharedWriter(terminal_async.clone_shared_writer()),
163    )
164    .install_global()?;
165
166    // Start tasks.
167    let mut state = State::default();
168    let mut interval_1_task = interval(state.task_1_state.interval_delay);
169    let mut interval_2_task = interval(state.task_2_state.interval_delay);
170
171    terminal_async.println(get_info_message().to_string()).await;
172
173    loop {
174        select! {
175            _ = interval_1_task.tick() => {
176                task_1::tick(&mut state, &mut terminal_async.clone_shared_writer())?;
177            },
178            _ = interval_2_task.tick() => {
179                task_2::tick(&mut state, &mut terminal_async.clone_shared_writer())?;
180            },
181            result_readline_event = terminal_async.get_readline_event() => {
182                match result_readline_event {
183                    Ok(readline_event) => {
184                        match readline_event {
185                            // User input event.
186                            ReadlineEvent::Line(user_input) => {
187                                let mut_state = &mut state;
188                                let shared_writer = &mut terminal_async.clone_shared_writer();
189                                let readline = &mut terminal_async.readline;
190                                let control_flow = process_input_event::process(
191                                    user_input, mut_state, shared_writer, readline)?;
192                                if let ControlFlow::Break(_) = control_flow {
193                                    break;
194                                }
195                            }
196                            // Resize event.
197                            ReadlineEvent::Resized => {
198                                let shared_writer = &mut terminal_async.clone_shared_writer();
199                                writeln!(shared_writer, "{}", "Terminal resized!".yellow()).into_diagnostic()?;
200                            }
201                            // Ctrl+D, Ctrl+C.
202                            ReadlineEvent::Eof | ReadlineEvent::Interrupted => {
203                                break;
204                            }
205                        }
206                    },
207                    Err(err) => {
208                        let msg_1 = format!("Received err: {}", format!("{:?}",err).red());
209                        let msg_2 = format!("{}", "Exiting...".red());
210                        terminal_async.println(msg_1).await;
211                        terminal_async.println(msg_2).await;
212                        break;
213                    },
214                }
215            }
216        }
217    }
218
219    // There's no need to close terminal_async or readline. Drop will take care of
220    // cleaning up (closing raw mode).
221
222    Ok(())
223}
Source

pub fn clone_shared_writer(&self) -> SharedWriter

Examples found in repository?
examples/shell_async.rs (line 297)
284    pub async fn new(pid: u32) -> miette::Result<TerminalAsyncHandle> {
285        let prompt = {
286            let prompt_seg_1 = "╭".magenta().on_dark_grey().to_string();
287            let prompt_seg_2 = format!("┤{pid}├").magenta().on_dark_grey().to_string();
288            let prompt_seg_3 = "╮".magenta().on_dark_grey().to_string();
289            format!("{}{}{} ", prompt_seg_1, prompt_seg_2, prompt_seg_3)
290        };
291
292        let Ok(Some(terminal_async)) = TerminalAsync::try_new(prompt.as_str()).await
293        else {
294            miette::bail!("Failed to create TerminalAsync instance");
295        };
296
297        let shared_writer = terminal_async.clone_shared_writer();
298
299        ok!(TerminalAsyncHandle {
300            terminal_async,
301            shared_writer
302        })
303    }
More examples
Hide additional examples
examples/spinner.rs (line 70)
61async fn example_with_concurrent_output(style: SpinnerStyle) -> miette::Result<()> {
62    let terminal_async = TerminalAsync::try_new("$ ").await?;
63    let terminal_async = terminal_async.expect("terminal is not fully interactive");
64    let address = "127.0.0.1:8000";
65    let message_trying_to_connect = format!(
66        "This is a sample indeterminate progress message: trying to connect to server on {}",
67        &address
68    );
69
70    let mut shared_writer = terminal_async.clone_shared_writer();
71
72    // Start spinner. Automatically pauses the terminal.
73    let mut maybe_spinner = Spinner::try_start(
74        message_trying_to_connect.clone(),
75        DELAY_UNIT,
76        style,
77        Arc::new(StdMutex::new(stderr())),
78        shared_writer.clone(),
79    )
80    .await?;
81
82    // Start another task, to simulate some async work, that uses a interval to display
83    // output, for a fixed amount of time, using `terminal_async.println_prefixed()`.
84    let _ = try_join!(tokio::spawn(async move {
85        // To calculate the delay.
86        let duration = ARTIFICIAL_UI_DELAY;
87        let start = Instant::now();
88
89        // Dropping the interval cancels it.
90        let mut interval = tokio::time::interval(Duration::from_millis(DELAY_MS * 5));
91
92        loop {
93            interval.tick().await;
94            let elapsed = start.elapsed();
95            if elapsed >= duration {
96                break;
97            }
98            let _ = writeln!(shared_writer, "⏳foo");
99        }
100    }));
101
102    // Stop spinner. Automatically resumes the terminal.
103    if let Some(spinner) = maybe_spinner.as_mut() {
104        spinner
105            .stop("This is a sample final message for the spinner component: Connected to server")
106            .await?;
107    }
108
109    tokio::time::sleep(Duration::from_millis(500)).await;
110
111    Ok(())
112}
examples/terminal_async.rs (line 162)
138async fn main() -> miette::Result<()> {
139    let prompt = {
140        let prompt_seg_1 = "╭>╮".magenta().on_dark_grey().to_string();
141        let prompt_seg_2 = " ".to_string();
142        format!("{}{}", prompt_seg_1, prompt_seg_2)
143    };
144
145    let maybe_terminal_async = TerminalAsync::try_new(prompt.as_str()).await?;
146
147    // If the terminal is not fully interactive, then return early.
148    let Some(mut terminal_async) = maybe_terminal_async else {
149        return Ok(());
150    };
151
152    // Pre-populate the readline's history with some entries.
153    for command in Command::iter() {
154        terminal_async
155            .readline
156            .add_history_entry(command.to_string());
157    }
158
159    // Initialize tracing w/ the "async stdout" (SharedWriter), and file writer.
160    TracingConfig::new_file_and_display(
161        None,
162        DisplayPreference::SharedWriter(terminal_async.clone_shared_writer()),
163    )
164    .install_global()?;
165
166    // Start tasks.
167    let mut state = State::default();
168    let mut interval_1_task = interval(state.task_1_state.interval_delay);
169    let mut interval_2_task = interval(state.task_2_state.interval_delay);
170
171    terminal_async.println(get_info_message().to_string()).await;
172
173    loop {
174        select! {
175            _ = interval_1_task.tick() => {
176                task_1::tick(&mut state, &mut terminal_async.clone_shared_writer())?;
177            },
178            _ = interval_2_task.tick() => {
179                task_2::tick(&mut state, &mut terminal_async.clone_shared_writer())?;
180            },
181            result_readline_event = terminal_async.get_readline_event() => {
182                match result_readline_event {
183                    Ok(readline_event) => {
184                        match readline_event {
185                            // User input event.
186                            ReadlineEvent::Line(user_input) => {
187                                let mut_state = &mut state;
188                                let shared_writer = &mut terminal_async.clone_shared_writer();
189                                let readline = &mut terminal_async.readline;
190                                let control_flow = process_input_event::process(
191                                    user_input, mut_state, shared_writer, readline)?;
192                                if let ControlFlow::Break(_) = control_flow {
193                                    break;
194                                }
195                            }
196                            // Resize event.
197                            ReadlineEvent::Resized => {
198                                let shared_writer = &mut terminal_async.clone_shared_writer();
199                                writeln!(shared_writer, "{}", "Terminal resized!".yellow()).into_diagnostic()?;
200                            }
201                            // Ctrl+D, Ctrl+C.
202                            ReadlineEvent::Eof | ReadlineEvent::Interrupted => {
203                                break;
204                            }
205                        }
206                    },
207                    Err(err) => {
208                        let msg_1 = format!("Received err: {}", format!("{:?}",err).red());
209                        let msg_2 = format!("{}", "Exiting...".red());
210                        terminal_async.println(msg_1).await;
211                        terminal_async.println(msg_2).await;
212                        break;
213                    },
214                }
215            }
216        }
217    }
218
219    // There's no need to close terminal_async or readline. Drop will take care of
220    // cleaning up (closing raw mode).
221
222    Ok(())
223}
Source

pub async fn get_readline_event(&mut self) -> Result<ReadlineEvent>

Replacement for std::io::Stdin::read_line() (this is async and non blocking).

Examples found in repository?
examples/shell_async.rs (line 199)
181    pub async fn start_event_loop(
182        mut stdin: tokio::process::ChildStdin,
183        mut terminal_async: TerminalAsync,
184        mut child: tokio::process::Child,
185        shutdown_sender: tokio::sync::broadcast::Sender<()>,
186    ) {
187        let mut shutdown_receiver = shutdown_sender.subscribe();
188
189        loop {
190            tokio::select! {
191                // Branch: Monitor shutdown signal. This is cancel safe as `recv()` is
192                // cancel safe.
193                _ = shutdown_receiver.recv() => {
194                    break;
195                }
196
197                // Branch: Monitor terminal_async for user input. This is cancel safe as
198                // `get_readline_event()` is cancel safe.
199                result_readline_event = terminal_async.get_readline_event() => {
200                    match ControlFlow::from(result_readline_event) {
201                        ControlFlow::ShutdownKillChild => {
202                            _ = child.kill().await;
203                            _= shutdown_sender.send(());
204                            break;
205                        }
206                        ControlFlow::ProcessLine(input) => {
207                            let input = format!("{}\n", input);
208                            _ = stdin.write_all(input.as_bytes()).await;
209                            _ = stdin.flush().await;
210                        }
211                        ControlFlow::Resized => {}
212                    }
213                }
214            }
215        }
216    }
More examples
Hide additional examples
examples/terminal_async.rs (line 181)
138async fn main() -> miette::Result<()> {
139    let prompt = {
140        let prompt_seg_1 = "╭>╮".magenta().on_dark_grey().to_string();
141        let prompt_seg_2 = " ".to_string();
142        format!("{}{}", prompt_seg_1, prompt_seg_2)
143    };
144
145    let maybe_terminal_async = TerminalAsync::try_new(prompt.as_str()).await?;
146
147    // If the terminal is not fully interactive, then return early.
148    let Some(mut terminal_async) = maybe_terminal_async else {
149        return Ok(());
150    };
151
152    // Pre-populate the readline's history with some entries.
153    for command in Command::iter() {
154        terminal_async
155            .readline
156            .add_history_entry(command.to_string());
157    }
158
159    // Initialize tracing w/ the "async stdout" (SharedWriter), and file writer.
160    TracingConfig::new_file_and_display(
161        None,
162        DisplayPreference::SharedWriter(terminal_async.clone_shared_writer()),
163    )
164    .install_global()?;
165
166    // Start tasks.
167    let mut state = State::default();
168    let mut interval_1_task = interval(state.task_1_state.interval_delay);
169    let mut interval_2_task = interval(state.task_2_state.interval_delay);
170
171    terminal_async.println(get_info_message().to_string()).await;
172
173    loop {
174        select! {
175            _ = interval_1_task.tick() => {
176                task_1::tick(&mut state, &mut terminal_async.clone_shared_writer())?;
177            },
178            _ = interval_2_task.tick() => {
179                task_2::tick(&mut state, &mut terminal_async.clone_shared_writer())?;
180            },
181            result_readline_event = terminal_async.get_readline_event() => {
182                match result_readline_event {
183                    Ok(readline_event) => {
184                        match readline_event {
185                            // User input event.
186                            ReadlineEvent::Line(user_input) => {
187                                let mut_state = &mut state;
188                                let shared_writer = &mut terminal_async.clone_shared_writer();
189                                let readline = &mut terminal_async.readline;
190                                let control_flow = process_input_event::process(
191                                    user_input, mut_state, shared_writer, readline)?;
192                                if let ControlFlow::Break(_) = control_flow {
193                                    break;
194                                }
195                            }
196                            // Resize event.
197                            ReadlineEvent::Resized => {
198                                let shared_writer = &mut terminal_async.clone_shared_writer();
199                                writeln!(shared_writer, "{}", "Terminal resized!".yellow()).into_diagnostic()?;
200                            }
201                            // Ctrl+D, Ctrl+C.
202                            ReadlineEvent::Eof | ReadlineEvent::Interrupted => {
203                                break;
204                            }
205                        }
206                    },
207                    Err(err) => {
208                        let msg_1 = format!("Received err: {}", format!("{:?}",err).red());
209                        let msg_2 = format!("{}", "Exiting...".red());
210                        terminal_async.println(msg_1).await;
211                        terminal_async.println(msg_2).await;
212                        break;
213                    },
214                }
215            }
216        }
217    }
218
219    // There's no need to close terminal_async or readline. Drop will take care of
220    // cleaning up (closing raw mode).
221
222    Ok(())
223}
Source

pub async fn println<T>(&mut self, content: T)
where T: Display,

Don’t change the content. Print it as is. This works concurrently and is async and non blocking. And it is compatible w/ the get_readline_event method.

Examples found in repository?
examples/terminal_async.rs (line 171)
138async fn main() -> miette::Result<()> {
139    let prompt = {
140        let prompt_seg_1 = "╭>╮".magenta().on_dark_grey().to_string();
141        let prompt_seg_2 = " ".to_string();
142        format!("{}{}", prompt_seg_1, prompt_seg_2)
143    };
144
145    let maybe_terminal_async = TerminalAsync::try_new(prompt.as_str()).await?;
146
147    // If the terminal is not fully interactive, then return early.
148    let Some(mut terminal_async) = maybe_terminal_async else {
149        return Ok(());
150    };
151
152    // Pre-populate the readline's history with some entries.
153    for command in Command::iter() {
154        terminal_async
155            .readline
156            .add_history_entry(command.to_string());
157    }
158
159    // Initialize tracing w/ the "async stdout" (SharedWriter), and file writer.
160    TracingConfig::new_file_and_display(
161        None,
162        DisplayPreference::SharedWriter(terminal_async.clone_shared_writer()),
163    )
164    .install_global()?;
165
166    // Start tasks.
167    let mut state = State::default();
168    let mut interval_1_task = interval(state.task_1_state.interval_delay);
169    let mut interval_2_task = interval(state.task_2_state.interval_delay);
170
171    terminal_async.println(get_info_message().to_string()).await;
172
173    loop {
174        select! {
175            _ = interval_1_task.tick() => {
176                task_1::tick(&mut state, &mut terminal_async.clone_shared_writer())?;
177            },
178            _ = interval_2_task.tick() => {
179                task_2::tick(&mut state, &mut terminal_async.clone_shared_writer())?;
180            },
181            result_readline_event = terminal_async.get_readline_event() => {
182                match result_readline_event {
183                    Ok(readline_event) => {
184                        match readline_event {
185                            // User input event.
186                            ReadlineEvent::Line(user_input) => {
187                                let mut_state = &mut state;
188                                let shared_writer = &mut terminal_async.clone_shared_writer();
189                                let readline = &mut terminal_async.readline;
190                                let control_flow = process_input_event::process(
191                                    user_input, mut_state, shared_writer, readline)?;
192                                if let ControlFlow::Break(_) = control_flow {
193                                    break;
194                                }
195                            }
196                            // Resize event.
197                            ReadlineEvent::Resized => {
198                                let shared_writer = &mut terminal_async.clone_shared_writer();
199                                writeln!(shared_writer, "{}", "Terminal resized!".yellow()).into_diagnostic()?;
200                            }
201                            // Ctrl+D, Ctrl+C.
202                            ReadlineEvent::Eof | ReadlineEvent::Interrupted => {
203                                break;
204                            }
205                        }
206                    },
207                    Err(err) => {
208                        let msg_1 = format!("Received err: {}", format!("{:?}",err).red());
209                        let msg_2 = format!("{}", "Exiting...".red());
210                        terminal_async.println(msg_1).await;
211                        terminal_async.println(msg_2).await;
212                        break;
213                    },
214                }
215            }
216        }
217    }
218
219    // There's no need to close terminal_async or readline. Drop will take care of
220    // cleaning up (closing raw mode).
221
222    Ok(())
223}
Source

pub async fn println_prefixed<T>(&mut self, content: T)
where T: Display,

Prefix the content with a color and special characters, then print it.

Source

pub async fn flush(&mut self)

Simply flush the buffer. If there’s a newline in the buffer, it will be printed. Otherwise it won’t.

Source

pub async fn pause(&mut self)

Source

pub async fn resume(&mut self)

Source

pub fn print_exit_message(message: &str) -> Result<()>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more