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

source

pub fn stderr_line<I: InitialContent>(&self, init: I) -> Line<'_>

Get a Line buffer to print to stderr instead of stdout

source

pub fn stderr_print<T: Print>(&self, thing: T)

Print a multi-line text segment to stderr instead of stdout

source

pub fn confirm<Q, M>(&self, default: bool, question: Q) -> bool
where Confirm<Q, M>: Input<T = bool>,

Ask a yes or no question using Confirm

source

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}!"));
source

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!
source

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:?}"))
};
source

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");
source

pub async fn spin_while<I, F, T>(&mut self, message: I, future: F) -> T
where I: InitialContent, F: Future<Output = T>,

Available on crate feature 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;

Trait Implementations§

source§

impl Conciliator for Claw

source§

fn line<I: InitialContent>(&self, init: I) -> <Self as GetLine<'_>>::Line

Get a plain buffer without a tag
source§

fn status<I: InitialContent>(&self, init: I) -> <Self as GetLine<'_>>::Line

Get a line buffer with the status tag
source§

fn info<I: InitialContent>(&self, init: I) -> <Self as GetLine<'_>>::Line

Get a line buffer with the info tag
source§

fn warn<I: InitialContent>(&self, init: I) -> <Self as GetLine<'_>>::Line

Get a line buffer with the warn tag
source§

fn error<I: InitialContent>(&self, init: I) -> <Self as GetLine<'_>>::Line

Get a line buffer with the error tag
source§

fn print<T: Print>(&self, thing: T)

Print a multi-line text segment
source§

impl<'l> GetLine<'l> for Claw

§

type Line = Line<'l>

Type of the line buffer (does not have to be the struct Line)
source§

fn get_line(&'l self) -> Self::Line

Obtain a new line buffer

Auto Trait Implementations§

§

impl RefUnwindSafe for Claw

§

impl Send for Claw

§

impl Sync for Claw

§

impl Unpin for Claw

§

impl UnwindSafe for Claw

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, 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.