Struct Promptuity

Source
pub struct Promptuity<'a, W: Write> { /* private fields */ }
Expand description

The core struct of promptuity.

§Examples

§Basic

use promptuity::themes::MinimalTheme;
use promptuity::prompts::{Input, Confirm};
use promptuity::{Promptuity, Term};

let mut term = Term::default();
let mut theme = MinimalTheme::default();
let mut p = Promptuity::new(&mut term, &mut theme);

p.begin()?;

let name = p.prompt(Input::new("Please enter your username").with_placeholder("username"))?;
let full = p.prompt(Confirm::new("Are you a full-time software developer?").with_default(true))?;

p.finish()?;

§Logging

Executing begin activates Raw Mode. Since log outputs like println! will no longer render correctly, if you need to output logs, please use log methods such as Promptuity::log or Promptuity::warn.

p.begin()?;

p.step("Logging Step")?;
p.log("This is a log message")?;
p.info("This is a info message")?;
p.warn("This is a warn message")?;
p.error("This is a error message")?;
p.success("This is a success message")?;

p.finish()?;

Implementations§

Source§

impl<'a, W: Write> Promptuity<'a, W>

Source

pub fn new(term: &'a mut dyn Terminal<W>, theme: &'a mut dyn Theme<W>) -> Self

Creates a new Promptuity instance.

Source

pub fn term(&mut self) -> &mut dyn Terminal<W>

Returns the currently used terminal.

Source

pub fn with_intro(&mut self, intro: impl Display) -> &mut Self

Sets the intro message for the prompt session.
May be required by the Theme.

Source

pub fn with_outro(&mut self, outro: impl Display) -> &mut Self

Sets the outro message for the prompt session. May be required by the Theme.

Source

pub fn begin(&mut self) -> Result<(), Error>

Declares the start of a prompt session.
Executing begin activates Raw Mode. Since log outputs like println! will no longer render correctly, if you need to output logs, please use log methods such as Promptuity::log or Promptuity::warn.

Source

pub fn finish(&mut self) -> Result<(), Error>

Declares the end of a prompt session.
Executing finish deactivates Raw Mode.

Source

pub fn step(&mut self, message: impl Display) -> Result<(), Error>

Displays a message as a prompt step.

Source

pub fn log(&mut self, message: impl Display) -> Result<(), Error>

Output of messages without decoration.

Source

pub fn info(&mut self, message: impl Display) -> Result<(), Error>

Output of messages with info decoration.

Source

pub fn warn(&mut self, message: impl Display) -> Result<(), Error>

Output of messages with warning decoration.

Source

pub fn error(&mut self, message: impl Display) -> Result<(), Error>

Output of messages with error decoration.

Source

pub fn success(&mut self, message: impl Display) -> Result<(), Error>

Output of messages with success decoration.

Source

pub fn prompt<O>( &mut self, prompt: &mut dyn Prompt<Output = O>, ) -> Result<O, Error>

Executes the specified prompt and returns the input result.

Trait Implementations§

Source§

impl<'a, W: Write> Drop for Promptuity<'a, W>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, W> Freeze for Promptuity<'a, W>

§

impl<'a, W> !RefUnwindSafe for Promptuity<'a, W>

§

impl<'a, W> !Send for Promptuity<'a, W>

§

impl<'a, W> !Sync for Promptuity<'a, W>

§

impl<'a, W> Unpin for Promptuity<'a, W>

§

impl<'a, W> !UnwindSafe for Promptuity<'a, W>

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

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.