Skip to main content

Form

Struct Form 

Source
pub struct Form {
    pub title: Option<String>,
    pub fields: Vec<Field>,
    pub mode: FormMode,
    /* private fields */
}
Expand description

A vim-modal form. Holds an ordered list of fields, the focused index, the current FormMode, an optional title, and a submit closure consumed on first call.

Fields§

§title: Option<String>§fields: Vec<Field>§mode: FormMode

Implementations§

Source§

impl Form

Source

pub fn new() -> Self

Build an empty form.

Source

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

Set an optional title row rendered above the fields.

Source

pub fn with_field(self, field: Field) -> Self

Append a field to the form. Order matters — first field is focused by default and j/k walks the list in order.

Source

pub fn with_submit(self, submit: SubmitFn) -> Self

Register the submit closure. Consumed via Option::take on the first successful submit.

Source

pub fn focused(&self) -> usize

Index of the currently-focused field.

Source

pub fn focused_field(&self) -> Option<&Field>

Borrow the focused field, if any.

Source

pub fn focused_field_mut(&mut self) -> Option<&mut Field>

Mutably borrow the focused field, if any.

Source

pub fn set_focus(&mut self, index: usize)

Programmatically set the focus index. Out-of-range indices are ignored.

Source

pub fn dirty_gen(&self) -> u64

Sum of the form-level dirty counter and every text field’s buffer dirty_gen. Renderers can cheap-check this to skip redraws.

Source§

impl Form

Source

pub fn handle_input(&mut self, input: Input) -> Option<FormEvent>

Route a key event through the form. Returns an event if the keystroke produced one (focus moved, value changed, submit fired, etc.).

Source§

impl Form

Source

pub fn try_submit(&mut self) -> Option<SubmitOutcome>

Validate every field and, on success, fire the submit closure (consumed via Option::take). Returns:

  • Some(SubmitOutcome::Ok) / Some(SubmitOutcome::Err(_)) — submit ran (or no submit was registered, in which case Ok).
  • None — validation failed; per-field errors populated.
Source§

impl Form

Source

pub fn validate_focused(&mut self) -> bool

Validate the focused field. Returns the same boolean as validate_field.

Source

pub fn validate_all(&mut self) -> Result<(), Vec<(usize, String)>>

Validate every field. On error, returns the list of (field_index, error_message) tuples and leaves each field’s meta.error populated.

Trait Implementations§

Source§

impl Default for Form

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Form

§

impl !Send for Form

§

impl !Sync for Form

§

impl !UnwindSafe for Form

§

impl Freeze for Form

§

impl Unpin for Form

§

impl UnsafeUnpin for Form

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more