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>
impl<'a, W: Write> Promptuity<'a, W>
Sourcepub fn new(term: &'a mut dyn Terminal<W>, theme: &'a mut dyn Theme<W>) -> Self
pub fn new(term: &'a mut dyn Terminal<W>, theme: &'a mut dyn Theme<W>) -> Self
Creates a new Promptuity
instance.
Sourcepub fn with_intro(&mut self, intro: impl Display) -> &mut Self
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.
Sourcepub fn with_outro(&mut self, outro: impl Display) -> &mut Self
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.
Sourcepub fn begin(&mut self) -> Result<(), Error>
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
.
Sourcepub fn finish(&mut self) -> Result<(), Error>
pub fn finish(&mut self) -> Result<(), Error>
Declares the end of a prompt session.
Executing finish
deactivates Raw Mode.
Sourcepub fn step(&mut self, message: impl Display) -> Result<(), Error>
pub fn step(&mut self, message: impl Display) -> Result<(), Error>
Displays a message as a prompt step.
Sourcepub fn log(&mut self, message: impl Display) -> Result<(), Error>
pub fn log(&mut self, message: impl Display) -> Result<(), Error>
Output of messages without decoration.
Sourcepub fn info(&mut self, message: impl Display) -> Result<(), Error>
pub fn info(&mut self, message: impl Display) -> Result<(), Error>
Output of messages with info decoration.
Sourcepub fn warn(&mut self, message: impl Display) -> Result<(), Error>
pub fn warn(&mut self, message: impl Display) -> Result<(), Error>
Output of messages with warning decoration.
Sourcepub fn error(&mut self, message: impl Display) -> Result<(), Error>
pub fn error(&mut self, message: impl Display) -> Result<(), Error>
Output of messages with error decoration.