pub struct Paginator { /* private fields */ }Expand description
Which page of several is showing.
use rich_interact::headless::{self, Script};
use rich_interact::{Paginator, PaginatorStyle};
// Embedded: state and an indicator line.
let mut pages = Paginator::new(3);
assert!(pages.next_page());
assert_eq!(pages.page(), 1);
assert_eq!(pages.indicator_text(80), "○ ● ○");
assert_eq!(pages.style(PaginatorStyle::Fraction).indicator_text(80), "2/3");
// Standalone: a list shown a page at a time; Enter returns the page.
let letters = ["a", "b", "c", "d", "e"];
let paginator = Paginator::over("Letters", letters, 2);
let (outcome, record) = headless::run(paginator, Script::new().keys("right enter"), 40, 8);
assert_eq!(outcome.unwrap().value(), Some(1));
assert_eq!(record.last_frame(), "? Letters › page 2 of 3");Implementations§
Source§impl Paginator
impl Paginator
Sourcepub fn new(pages: usize) -> Paginator
pub fn new(pages: usize) -> Paginator
A paginator over pages pages (at least one), on the first.
Sourcepub fn over<I, S>(
title: impl Into<String>,
items: I,
per_page: usize,
) -> Paginator
pub fn over<I, S>( title: impl Into<String>, items: I, per_page: usize, ) -> Paginator
A paginator over items, per_page at a time, titled title: the
standalone component shows the current page’s items above the
indicator.
Sourcepub fn style(self, style: PaginatorStyle) -> Self
pub fn style(self, style: PaginatorStyle) -> Self
Dots or a fraction (default: dots).
Sourcepub fn dots(
self,
active: impl Into<String>,
inactive: impl Into<String>,
) -> Self
pub fn dots( self, active: impl Into<String>, inactive: impl Into<String>, ) -> Self
The dots for the current page and the others (default ● and ○).
Sourcepub fn start_at(self, page: usize) -> Self
pub fn start_at(self, page: usize) -> Self
Start on page (0-based; past the last means the last).
Sourcepub fn theme(self, theme: Theme) -> Self
pub fn theme(self, theme: Theme) -> Self
The current dot is drawn in the theme’s checked_style, the others
and the fraction’s count in hint.
Sourcepub fn with_mouse(self, on: bool) -> Self
pub fn with_mouse(self, on: bool) -> Self
Report the mouse: a click on a dot goes to its page, and the wheel moves a page.
Sourcepub fn rebind(self, action: &str, keys: impl IntoIterator<Item = Key>) -> Self
pub fn rebind(self, action: &str, keys: impl IntoIterator<Item = Key>) -> Self
Make keys do action on this paginator only (see
paginator_keymap); no keys unbinds it.
Sourcepub fn set_pages(&mut self, pages: usize)
pub fn set_pages(&mut self, pages: usize)
Change the number of pages (at least one), keeping the current page if it is still there.
Sourcepub fn previous_page(&mut self) -> bool
pub fn previous_page(&mut self) -> bool
Move to the previous page; false on the first.
pub fn on_first(&self) -> bool
pub fn on_last(&self) -> bool
Sourcepub fn bounds(&self, len: usize, per_page: usize) -> Range<usize> ⓘ
pub fn bounds(&self, len: usize, per_page: usize) -> Range<usize> ⓘ
The range of a list of len items on the current page, at
per_page a page: what to slice for it.
Sourcepub fn handle_key(&mut self, key: Key) -> bool
pub fn handle_key(&mut self, key: Key) -> bool
Move for key if it is one of the moving keys (next, previous,
first, last page): true when it was, whether or not the page
changed. For a container that embeds a paginator.
Sourcepub fn indicator(&self, width: usize) -> Vec<Segment>
pub fn indicator(&self, width: usize) -> Vec<Segment>
The indicator line, at most width columns.
Sourcepub fn indicator_text(&self, width: usize) -> String
pub fn indicator_text(&self, width: usize) -> String
The indicator as plain text: what a screen reader or a log reads.
Trait Implementations§
Source§impl Component for Paginator
impl Component for Paginator
Source§fn prompt(
&mut self,
io: &mut dyn LineIo,
) -> Result<Option<usize>, NotInteractive>
fn prompt( &mut self, io: &mut dyn LineIo, ) -> Result<Option<usize>, NotInteractive>
Without a terminal: every item, then the page asked for by number.
type Output = usize
Source§fn handle(&mut self, event: &Event, context: &Context<'_>) -> Flow<usize>
fn handle(&mut self, event: &Event, context: &Context<'_>) -> Flow<usize>
Outcome::Interrupted.Source§fn keymap(&self) -> Keymap
fn keymap(&self) -> Keymap
keymap). A container’s include its focused
child’s, before its own. The default declares none.Source§fn mouse(&self) -> bool
fn mouse(&self) -> bool
run then enables mouse reporting
for the session.Source§fn default_value(&self) -> Option<usize>
fn default_value(&self) -> Option<usize>
None: there is none.Source§fn start(&mut self, context: &Context<'_>) -> Flow<Self::Output>
fn start(&mut self, context: &Context<'_>) -> Flow<Self::Output>
Done or Cancel finishes the component
without waiting for an event. The default does nothing.Source§fn tick(&self) -> Option<Duration>
fn tick(&self) -> Option<Duration>
Event::Tick, for a spinner or a
countdown. None (the default): never.Source§fn focusable(&self) -> bool
fn focusable(&self) -> bool
Source§fn focus_step(&mut self, forward: bool) -> bool
fn focus_step(&mut self, forward: bool) -> bool
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.Auto Trait Implementations§
impl Freeze for Paginator
impl RefUnwindSafe for Paginator
impl Send for Paginator
impl Sync for Paginator
impl Unpin for Paginator
impl UnsafeUnpin for Paginator
impl UnwindSafe for Paginator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<C> ComponentExt for Cwhere
C: Component,
impl<C> ComponentExt for Cwhere
C: Component,
Source§fn map<'a, M>(
self,
done: impl FnMut(Self::Output) -> Flow<M> + 'a,
) -> Map<'a, Self, M>where
Self: 'a,
fn map<'a, M>(
self,
done: impl FnMut(Self::Output) -> Flow<M> + 'a,
) -> Map<'a, Self, M>where
Self: 'a,
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.