pub struct TextArea { /* private fields */ }Expand description
Multi-line text. Returns the text, lines joined with \n.
Implementations§
Source§impl TextArea
impl TextArea
pub fn new(prompt: impl Into<String>) -> TextArea
Sourcepub fn placeholder(self, placeholder: impl Into<String>) -> Self
pub fn placeholder(self, placeholder: impl Into<String>) -> Self
Dim text shown while the area is empty.
Sourcepub fn char_limit(self, chars: usize) -> Self
pub fn char_limit(self, chars: usize) -> Self
At most chars characters (grapheme clusters, so 👨👩👧 or e
and a combining accent is one), line breaks included. Text already
there beyond it is cut.
Sourcepub fn truncate(text: &str, chars: usize) -> &str
pub fn truncate(text: &str, chars: usize) -> &str
The first chars characters of text as the character limit
counts them: grapheme clusters, a line break one. Never cuts a
cluster.
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 (in context textarea; see
keymap) on this area only; no keys unbinds
it.
Sourcepub fn emacs_keys(self) -> Self
pub fn emacs_keys(self) -> Self
Emacs’s keys on top of the defaults: Ctrl+F/B/N/P and Alt+F/B
move, Ctrl+K, Ctrl+U, Ctrl+W, Alt+D and Alt+Backspace kill onto the
buffer’s kill ring, Ctrl+Y yanks the last kill back and Alt+Y
swaps it for an older one, Alt+{ and Alt+} move by paragraph.
(Ctrl+D still submits unless submit_key
moves it.)
use rich_interact::headless::{run, Script};
use rich_interact::TextArea;
let area = TextArea::new("Note").value("one two").emacs_keys();
let script = Script::new().keys("ctrl+a alt+d ctrl+e ctrl+y ctrl+d");
let (outcome, _) = run(area, script, 30, 6);
assert_eq!(outcome.unwrap().value().as_deref(), Some(" twoone"));Sourcepub fn submit_key(self, key: Key) -> Self
pub fn submit_key(self, key: Key) -> Self
The key that submits (default Ctrl+D).
Sourcepub fn line_numbers(self, on: bool) -> Self
pub fn line_numbers(self, on: bool) -> Self
Number the lines.
pub fn theme(self, theme: Theme) -> Self
Trait Implementations§
Source§impl Component for TextArea
impl Component for TextArea
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>
Without a terminal: every line up to the end of input is the text, cut to the character limit. No lines at all answer with the text the area started with.
type Output = String
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 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 default_value(&self) -> Option<String>
fn default_value(&self) -> Option<String>
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 mouse(&self) -> bool
fn mouse(&self) -> bool
run then enables mouse reporting
for the session.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 TextArea
impl !RefUnwindSafe for TextArea
impl !Sync for TextArea
impl Send for TextArea
impl Unpin for TextArea
impl UnsafeUnpin for TextArea
impl UnwindSafe for TextArea
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.