pub struct ThemePicker { /* private fields */ }Expand description
Pick a theme while its preview shows a sample rendered in it (#460). Returns the theme’s name.
Themes come from anywhere: a configuration file’s [themes.NAME], a
plugin’s (ExtensionRegistry::theme), or code. Each is layered over
the extended theme, so a theme that
sets only a few names previews with the rest at their defaults.
use rich::{Style, Theme};
use rich_interact::components::ThemePicker;
use rich_interact::headless::{self, Script};
let mut night = Theme::new();
night.insert("info", Style::parse("bold blue").unwrap());
let picker = ThemePicker::new("Theme", [("default", Theme::new()), ("night", night)]);
let (outcome, record) = headless::run(picker, Script::new().keys("down enter"), 80, 14);
assert_eq!(outcome.unwrap().value().as_deref(), Some("night"));
assert!(record.frames[0].contains("Theme preview"));Implementations§
Source§impl ThemePicker
impl ThemePicker
Sourcepub fn new<I, S>(prompt: impl Into<String>, themes: I) -> ThemePicker
pub fn new<I, S>(prompt: impl Into<String>, themes: I) -> ThemePicker
Pick one of themes, by name, previewing THEME_SAMPLE.
Sourcepub fn with_sample<I, S>(
prompt: impl Into<String>,
themes: I,
sample: Arc<dyn Renderable + Send + Sync>,
) -> ThemePicker
pub fn with_sample<I, S>( prompt: impl Into<String>, themes: I, sample: Arc<dyn Renderable + Send + Sync>, ) -> ThemePicker
Pick one of themes, previewing sample in each.
Sourcepub fn from_registry(
prompt: impl Into<String>,
registry: &ExtensionRegistry,
) -> ThemePicker
pub fn from_registry( prompt: impl Into<String>, registry: &ExtensionRegistry, ) -> ThemePicker
Pick one of the themes plugins registered in registry (theme
packs), after rich’s own default theme, listed as default.
Sourcepub fn preview(self, layout: PreviewLayout) -> Self
pub fn preview(self, layout: PreviewLayout) -> Self
Where the preview goes (default: beside the list from 72 columns).
Sourcepub fn preview_height(self, rows: usize) -> Self
pub fn preview_height(self, rows: usize) -> Self
Rows the preview takes when it is below the list (default 10).
pub fn theme(self, theme: Theme) -> Self
Sourcepub fn default(self, name: &str) -> Self
pub fn default(self, name: &str) -> Self
Focus the theme called name first; it is also the answer without
a terminal.
Sourcepub fn with_mouse(self, on: bool) -> Self
pub fn with_mouse(self, on: bool) -> Self
Report the mouse: see Select::with_mouse.
Trait Implementations§
Source§impl Component for ThemePicker
impl Component for ThemePicker
type Output = String
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 handle(&mut self, event: &Event, context: &Context<'_>) -> Flow<String>
fn handle(&mut self, event: &Event, context: &Context<'_>) -> Flow<String>
Outcome::Interrupted.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 mouse(&self) -> bool
fn mouse(&self) -> bool
run then enables mouse reporting
for the session.Source§fn default_value(&self) -> Option<String>
fn default_value(&self) -> Option<String>
None: there is none.Source§fn prompt(
&mut self,
io: &mut dyn LineIo,
) -> Result<Option<String>, NotInteractive>
fn prompt( &mut self, io: &mut dyn LineIo, ) -> Result<Option<String>, NotInteractive>
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 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 ThemePicker
impl !RefUnwindSafe for ThemePicker
impl !Sync for ThemePicker
impl !UnwindSafe for ThemePicker
impl Send for ThemePicker
impl Unpin for ThemePicker
impl UnsafeUnpin for ThemePicker
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.