Struct conciliator::Claw
source · pub struct Claw { /* private fields */ }
Expand description
The main Conciliator
implementor
Offers Conciliator
methods for printing to stdout and basic methods for stderr.
Constructed using conciliator::init
.
Implementations§
source§impl Claw
impl Claw
sourcepub fn stderr_line<I: InitialContent>(&self, init: I) -> Line<'_> ⓘ
pub fn stderr_line<I: InitialContent>(&self, init: I) -> Line<'_> ⓘ
Get a Line
buffer to print to stderr instead of stdout
sourcepub fn stderr_print<T: Print>(&self, thing: T)
pub fn stderr_print<T: Print>(&self, thing: T)
Print
a multi-line text segment to stderr instead of stdout
sourcepub fn confirm<Q, M>(&self, default: bool, question: Q) -> bool
pub fn confirm<Q, M>(&self, default: bool, question: Q) -> bool
Ask a yes or no question using Confirm
sourcepub fn input<I: Input>(&self, request: I) -> I::T
pub fn input<I: Input>(&self, request: I) -> I::T
Request arbitrary user Input
use conciliator::Conciliator;
let con = conciliator::init();
let name = con.input("Please enter your name");
con.status(format_args!("Hello {name}!"));
sourcepub fn select<T: Inline>(
&self,
things: Vec<T>,
description: &str,
question: &str
) -> Option<T>
pub fn select<T: Inline>( &self, things: Vec<T>, description: &str, question: &str ) -> Option<T>
Ask the user to pick an element from a Vec
Returns None
only if the Vec
is empty.
If there is only 1 item, it is returned without asking.
Otherwise it will ask (and keep asking) until the user has made a selection.
For example:
use conciliator::{Conciliator, Wrap, Paint};
let con = conciliator::init();
let list = vec![
Wrap::Iota("62bfe952-c9b3-4d32-a2fb-eba5a9b77136"),
Wrap::Iota("3ba08f2d-6b37-42d6-a12b-b22e0b5ad01f"),
Wrap::Iota("0730fbdf-9703-4ffb-9186-d93e412cec63"),
Wrap::Iota("36f295d9-1a94-42f4-a4f2-f2c298cf7716"),
Wrap::Iota("879738e8-82e5-418f-8557-d7b95c6be06a"),
Wrap::Iota("2d5f0e37-f578-4764-9ffe-9542c99ef761")
];
let x = con.select(list, "UUIDs", "Select UUID").unwrap();
con.info("Selected ").push(&x).push_plain("!");
Produces:
[ > ] 6 UUIDs:
[1] - 62bfe952-c9b3-4d32-a2fb-eba5a9b77136
[2] - 3ba08f2d-6b37-42d6-a12b-b22e0b5ad01f
[3] - 0730fbdf-9703-4ffb-9186-d93e412cec63
[4] - 36f295d9-1a94-42f4-a4f2-f2c298cf7716
[5] - 879738e8-82e5-418f-8557-d7b95c6be06a
[6] - 2d5f0e37-f578-4764-9ffe-9542c99ef761
Select UUID [1 - 6]: 2
[ + ] Selected 3ba08f2d-6b37-42d6-a12b-b22e0b5ad01f!
sourcepub fn edit<E: Editable>(&self, to_edit: E) -> Edited<E::E>
pub fn edit<E: Editable>(&self, to_edit: E) -> Edited<E::E>
Invoke the text editor
For further information, see the edit
module.
use conciliator::{Conciliator, edit::Edited};
let con = conciliator::init();
match con.edit("Test123 :^)") {
Edited::Ok(s) => con.status(format_args!("Edited:\n{s}")),
Edited::Cancelled => con.info("Edit aborted!"),
Edited::Err(e) => con.error(format_args!("{e:?}"))
};
sourcepub fn spin<I: InitialContent>(&mut self, message: I) -> Spinner<'_>
pub fn spin<I: InitialContent>(&mut self, message: I) -> Spinner<'_>
Start a Spinner
with the CHASE
animation
Takes &mut self
to prevent accidentally messing up the Spinner
output – use its Conciliator
methods instead!
You can choose a different animation with Spinner::new
.
See the spin
module for more information.
use conciliator::Conciliator;
// `mut` so that the Spinner can get an exclusive (mutable) reference
let mut con = conciliator::init();
con.status("Starting process");
let sp = con.spin("Downloading thing...");
// < download the thing >
sp.status("Download complete");
sp.message("Unpacking thing...");
// < unpack the thing >
sp.status("Thing unpacked");
sp.message("Process finished");
sp.finish();
// you can only use the Claw after the Spinner is finished
con.info("Doing other thing");
sourcepub async fn spin_while<I, F, T>(&mut self, message: I, future: F) -> Twhere
I: InitialContent,
F: Future<Output = T>,
Available on crate feature tokio
only.
pub async fn spin_while<I, F, T>(&mut self, message: I, future: F) -> Twhere
I: InitialContent,
F: Future<Output = T>,
tokio
only.Run a Spinner
with the CHASE
animation while waiting for a future to complete
Needs &mut self
to prevent accidentally messing up the Spinner
output.
See the spin
module for more information.
use conciliator::Conciliator;
async fn download_thing() { /* ... */ }
// `mut` so that the Spinner can get an exclusive (mutable) reference
let mut con = conciliator::init();
con.spin_while("Downloading thing...", download_thing()).await;