Skip to main content

Input

Struct Input 

Source
pub struct Input { /* private fields */ }
Expand description

One line of text.

Implementations§

Source§

impl Input

Source

pub fn new(prompt: impl Into<String>) -> Input

Source

pub fn masked(prompt: impl Into<String>) -> Input

A masked input, for passwords and tokens: what is typed shows as •, and a default only as (default set).

Source

pub fn mask(self, mask: char) -> Self

Source

pub fn value(self, value: impl Into<String>) -> Self

Start with this text.

Source

pub fn rebind(self, action: &str, keys: impl IntoIterator<Item = Key>) -> Self

Make keys do action (see input_keymap) on this input only; no keys unbinds it.

Source

pub fn placeholder(self, placeholder: impl Into<String>) -> Self

Dim text shown while the line is empty.

Source

pub fn default(self, default: impl Into<String>) -> Self

The answer when Enter is pressed on an empty line, and without a terminal when the policy asks for defaults.

Source

pub fn help(self, help: impl Into<String>) -> Self

A line of help under the input.

Source

pub fn validate( self, validator: impl Fn(&str) -> Result<(), String> + 'static, ) -> Self

Check the answer on Enter; an Err message shows under the line.

Source

pub fn history<I: IntoIterator<Item = S>, S: Into<String>>( self, history: I, ) -> Self

Earlier answers, oldest first, for Up and Down.

Source

pub fn suggestions<I: IntoIterator<Item = S>, S: Into<Suggestion>>( self, suggestions: I, ) -> Self

Fixed suggestions, filtered by what is typed.

Source

pub fn provider( self, provider: impl Fn(&str) -> Vec<Suggestion> + Send + Sync + 'static, ) -> Self

Suggestions from provider, called on a background thread after each change; results for text since changed are dropped.

Source

pub fn limit(self, rows: usize) -> Self

Show at most rows suggestions (default 5).

Source

pub fn theme(self, theme: Theme) -> Self

Source

pub fn text(&self) -> &str

The text typed so far.

Source

pub fn buffer(&self) -> &TextBuffer

The line being edited.

Source

pub fn resolve(&self) -> Result<String, String>

The answer Enter would give: the text, or the default when empty, checked by the validator.

Source

pub fn field(&self, available: usize) -> (Vec<Segment>, usize)

The line’s text as shown (masked, or the placeholder) in available cells, scrolled to keep the caret in view, and the caret’s column in it.

Source

pub fn label(&self) -> &str

The prompt.

Source

pub fn suggesting(&self) -> bool

Whether suggestions are showing: Tab, Up, Down and Enter (with one selected) are theirs.

Source

pub fn has_selection(&self) -> bool

Whether Enter would accept a selected suggestion rather than submit.

Source

pub fn accept_selected(&mut self)

Accept the selected suggestion, as Enter does before submitting.

Source

pub fn suggestion_rows(&self, width: usize, indent: &str) -> Vec<Vec<Segment>>

The suggestion rows (or a pending marker), each after indent.

Source

pub fn display_value(&self, value: &str) -> String

value as this input shows it: masked, for a masked input.

Trait Implementations§

Source§

impl Component for Input

Source§

type Output = String

Source§

fn handle(&mut self, event: &Event, _: &Context<'_>) -> Flow<String>

Handle one event. Ctrl+C never arrives here: the event loop ends the component with Outcome::Interrupted.
Source§

fn render(&self, context: &Context<'_>) -> View

Render the current state.
Source§

fn tick(&self) -> Option<Duration>

How often the component wants Event::Tick, for a spinner or a countdown. None (the default): never.
Source§

fn keymap(&self) -> Keymap

The bindings this component has right now, for a help overlay, a shortcut list or status-bar hints to read (see keymap). A container’s include its focused child’s, before its own. The default declares none.
Source§

fn default_value(&self) -> Option<String>

The value to return when the terminal is not interactive and the policy asks for defaults. None: there is none.
Source§

fn prompt( &mut self, io: &mut dyn LineIo, ) -> Result<Option<String>, NotInteractive>

Ask for the value line by line, for when the terminal is not interactive and the policy asks for a prompt. The default says the component has no line-based form. Read more
Source§

fn start(&mut self, context: &Context<'_>) -> Flow<Self::Output>

Called once, before the component is first painted, with the terminal’s size: for work that needs it, such as rendering content at the width. Returning Done or Cancel finishes the component without waiting for an event. The default does nothing.
Source§

fn mouse(&self) -> bool

Whether the component wants mouse events (#476): clicks, drags and the wheel. Off by default, since reporting the mouse takes text selection away from the terminal; a component turns it on when its caller opts in, and run then enables mouse reporting for the session.
Source§

fn focusable(&self) -> bool

Whether the component takes focus in a container: Tab stops on it and keys go to it. The default: yes. A label, or a component that has finished, says no.
Source§

fn focus_step(&mut self, forward: bool) -> bool

Move focus to the next (forward) or previous focus stop inside this component, for Tab and Shift+Tab. false when there is none after the current one, so the container moves on to its next child. The default, for a component that is one stop: false.
Source§

fn focus_enter(&mut self, forward: bool) -> bool

Take focus from outside: at the first stop inside when forward, at the last otherwise. false when nothing in it can take focus. The default: whether the component is focusable.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Input

§

impl !Send for Input

§

impl !Sync for Input

§

impl !UnwindSafe for Input

§

impl Freeze for Input

§

impl Unpin for Input

§

impl UnsafeUnpin for Input

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<C> ComponentExt for C
where C: Component,

Source§

fn map<'a, M>( self, done: impl FnMut(Self::Output) -> Flow<M> + 'a, ) -> Map<'a, Self, M>
where Self: 'a,

Turn this component’s answer into M’s flow: Flow::Done(m) to finish the whole composition with m, Flow::Continue to carry on (the component stays, showing its answer, and focus moves past it). Cancelling cancels the composition unless on_cancel says otherwise.
Source§

fn with_overlays<'a>(self) -> Overlays<'a, Self::Output>
where Self: 'a, Self::Output: 'a,

Wrap this component in Overlays: a command palette, help and a shortcut sheet read from its keymap, and room for a status bar and breadcrumbs.
Source§

fn boxed<'a>(self) -> Child<'a, Self::Output>
where Self: 'a,

Box this component as a Child.
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.