Skip to main content

TimePicker

Struct TimePicker 

Source
pub struct TimePicker(/* private fields */);
Expand description

Pick a time of day, field by field. Returns the Time.

use rich_interact::datetime::Time;
use rich_interact::headless::{self, Script};
use rich_interact::{Outcome, TimePicker};

let picker = TimePicker::new("Start").value(Time::new(9, 0, 0));
let script = Script::new().text("1415").keys("enter");
let (outcome, _) = headless::run(picker, script, 40, 6);
assert_eq!(outcome.unwrap(), Outcome::Done(Time::new(14, 15, 0)));

Implementations§

Source§

impl TimePicker

Source

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

Source

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

Source

pub fn with_mouse(self, on: bool) -> Self

Report the mouse (#476): a click selects a day (a second click on it picks it) or focuses a time field, and the wheel turns the month or the focused field.

Source

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

Make keys do action (see date_keymap) on this picker only; no keys unbinds it.

Source

pub fn seconds(self, on: bool) -> Self

Pick the seconds too. Without them (the default) the picker works to the minute, whatever order the builders come in: the start, the default and a typed answer drop their seconds, the earliest rounds up to a minute and the latest down.

Source

pub fn twelve_hour(self, on: bool) -> Self

Show a 12-hour clock with AM and PM (a and p set them).

Source

pub fn value(self, time: Time) -> Self

Start at this time.

Source

pub fn default(self, time: Time) -> Self

Answer this time without a terminal and to an empty line, and start at it unless value says where to start.

Source

pub fn min(self, time: Time) -> Self

The earliest time that can be picked.

Source

pub fn max(self, time: Time) -> Self

The latest time that can be picked.

Source

pub fn validate( self, check: impl Fn(Time) -> Result<(), String> + Send + Sync + 'static, ) -> Self

Refuse a time check returns an error for: Enter shows the error and waits.

Source

pub fn selected(&self) -> Time

The time selected so far.

Trait Implementations§

Source§

impl Component for TimePicker

Source§

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

Tab inside: the next part, if there is one.

Source§

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

Tab from outside: the first part, or the last going back.

Source§

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

The default, unless the picker would refuse it: outside the range, or refused by the validator.

Source§

type Output = Time

Source§

fn start(&mut self, _context: &Context<'_>) -> Flow<Time>

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 handle(&mut self, event: &Event, _context: &Context<'_>) -> Flow<Time>

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 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 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 prompt( &mut self, io: &mut dyn LineIo, ) -> Result<Option<Time>, 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 tick(&self) -> Option<Duration>

How often the component wants Event::Tick, for a spinner or a countdown. None (the default): never.
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.

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