Skip to main content

Terminal

Struct Terminal 

Source
pub struct Terminal;
Expand description

Collection of interactive terminal prompt utilities.

All methods block on stdin until the user provides valid input. Invalid responses print an inline error and re-prompt rather than returning an error value, so callers always receive a valid result.

Implementations§

Source§

impl Terminal

Source

pub fn prompt(prompt: &str) -> String

Prints prompt and reads a line from stdin.

A single trailing space is appended to prompt before printing so the cursor lands one character after the prompt text.

Source

pub fn confirm( prompt: &str, default: Option<bool>, show_default: Option<bool>, ) -> bool

Asks a yes/no question and returns the user’s answer as a bool.

Re-prompts on any input that is not y, yes, n, no, or an empty string (which selects the default).

§Arguments
  • prompt - The question text, without any trailing suffix.
  • default - The value returned when the user presses Enter with no input. Defaults to false if None.
  • show_default - When true (or None), appends [Y/n] or [y/N] to the prompt to indicate the default visually.
Source

pub fn choice( prompt: &str, choices: &[&str], default: Option<&str>, show_default: Option<bool>, show_choices: Option<bool>, ) -> String

Asks the user to pick one option from a fixed set of choices.

Matching is case-insensitive. Re-prompts until the user enters a recognized choice or presses Enter when a default is set.

§Arguments
  • prompt - The question text.
  • choices - The allowed responses. Must not be empty.
  • default - Optional default value returned on empty input. Must be present in choices if provided.
  • show_default - When true (or None), marks the default choice with a * in the suffix list.
  • show_choices - When true (or None), appends the full choice list to the prompt as [a/b*/c].
§Panics

Panics if choices is empty, or if default is set to a value not present in choices.

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