Struct termimad::InputField
source · pub struct InputField {
pub password_mode: bool,
/* private fields */
}
Expand description
A simple input field, managing its cursor position and either handling the events you give it or being managed through direct manipulation functions (put_char, del_char_left, etc.).
To create a multiline input_field (otherwise called a
textarea) you should set an area with a height of more
than 1 and allow newline to be created on keyboard with
new_line_on
.
Fields§
§password_mode: bool
when true, the display will have stars instead of the normal chars
Implementations§
source§impl InputField
impl InputField
pub const ENTER: KeyEvent = _
pub const ALT_ENTER: KeyEvent = _
pub fn new(area: Area) -> Self
pub fn set_mono_line(&mut self)
sourcepub fn new_line_on(&mut self, key: KeyEvent)
pub fn new_line_on(&mut self, key: KeyEvent)
define a key which will be interpreted as a new line.
You may define several ones. If you set none, the input field will stay monoline unless you manage key events yourself to insert new lines.
Beware that keys like Ctrl-Enter and Shift-Enter are usually received by TUI applications as simple Enter.
Example:
use termimad::*;
let mut textarea = InputField::new(Area::new(5, 5, 20, 10));
textarea.new_line_on(InputField::ALT_ENTER);
sourcepub fn change_area(&mut self, x: u16, y: u16, w: u16)
pub fn change_area(&mut self, x: u16, y: u16, w: u16)
Change the area x, y and width, but not the height.
Makes most sense for monoline inputs
pub fn set_area(&mut self, area: Area)
pub const fn area(&self) -> &Area
pub const fn focused(&self) -> bool
pub fn set_normal_style(&mut self, style: CompoundStyle)
pub fn set_unfocused_style(&mut self, style: CompoundStyle)
pub const fn content(&self) -> &InputFieldContent
pub fn get_content(&self) -> String
pub fn is_empty(&self) -> bool
pub fn copy_selection(&mut self) -> String
pub fn cut_selection(&mut self) -> String
sourcepub fn replace_selection<S: AsRef<str>>(&mut self, s: S)
pub fn replace_selection<S: AsRef<str>>(&mut self, s: S)
Write the given string in place of the selection, or insert the string if there’s no wide selection.
This is the usual behavior for pasting a string.
sourcepub fn is_content(&self, s: &str) -> bool
pub fn is_content(&self, s: &str) -> bool
tell whether the content of the input is equal to the argument
sourcepub fn set_str<S: AsRef<str>>(&mut self, s: S)
pub fn set_str<S: AsRef<str>>(&mut self, s: S)
change the content to the new one and put the cursor at the end if the content is different from the previous one.
pub fn insert_new_line(&mut self) -> bool
sourcepub fn put_char(&mut self, c: char) -> bool
pub fn put_char(&mut self, c: char) -> bool
put a char at cursor position (and increment this position).
pub fn clear(&mut self)
sourcepub fn insert_str<S: AsRef<str>>(&mut self, s: S)
pub fn insert_str<S: AsRef<str>>(&mut self, s: S)
Insert the string on cursor point, as if it was typed
pub fn move_up(&mut self) -> bool
pub fn move_down(&mut self) -> bool
pub fn move_left(&mut self) -> bool
pub fn move_right(&mut self) -> bool
pub fn move_to_start(&mut self) -> bool
pub fn move_to_end(&mut self) -> bool
pub fn move_to_line_start(&mut self) -> bool
pub fn move_to_line_end(&mut self) -> bool
pub fn move_word_left(&mut self) -> bool
pub fn move_word_right(&mut self) -> bool
pub fn del_char_below(&mut self) -> bool
pub fn del_selection(&mut self) -> bool
pub fn del_char_left(&mut self) -> bool
pub fn del_word_left(&mut self) -> bool
pub fn del_word_right(&mut self) -> bool
pub fn move_current_line_up(&mut self) -> bool
pub fn move_current_line_down(&mut self) -> bool
pub fn select_word_around(&mut self) -> bool
pub fn page_up(&mut self) -> bool
pub fn page_down(&mut self) -> bool
sourcepub fn apply_key_event(&mut self, key: KeyEvent) -> bool
pub fn apply_key_event(&mut self, key: KeyEvent) -> bool
apply an event being a key
This function handles a few events like deleting a
char, or going to the start (home key) or end (end key)
of the input. If you want to totally handle events, you
may call function like put_char
and del_char_left
directly.
sourcepub fn apply_keycode_event(&mut self, code: KeyCode, shift: bool) -> bool
pub fn apply_keycode_event(&mut self, code: KeyCode, shift: bool) -> bool
apply an event being a key without modifier.
You don’t usually call this function but the more
general apply_event
. This one is useful when you
manage events mostly yourselves.
sourcepub fn apply_click_event(&mut self, x: u16, y: u16) -> bool
pub fn apply_click_event(&mut self, x: u16, y: u16) -> bool
Apply a simple left click event
sourcepub fn apply_mouse_event(
&mut self,
mouse_event: MouseEvent,
is_double_click: bool
) -> bool
pub fn apply_mouse_event(
&mut self,
mouse_event: MouseEvent,
is_double_click: bool
) -> bool
Apply a mouse event
sourcepub fn apply_event(&mut self, event: Event, is_double_click: bool) -> bool
pub fn apply_event(&mut self, event: Event, is_double_click: bool) -> bool
apply the event to change the state (content, cursor)
Return true when the event was used.
sourcepub fn apply_timed_event(&mut self, event: TimedEvent) -> bool
pub fn apply_timed_event(&mut self, event: TimedEvent) -> bool
apply the event to change the state (content, cursor, focus)
Return true when the event was used.
pub fn scroll_up(&mut self) -> bool
pub fn scroll_down(&mut self) -> bool
sourcepub fn display_on<W: Write>(&self, w: &mut W) -> Result<(), Error>
pub fn display_on<W: Write>(&self, w: &mut W) -> Result<(), Error>
Render the input field on screen.
All rendering must be explicitely called, no rendering is done on functions changing the state.
w is typically either stderr or stdout. This function doesn’t flush by itself (useful to avoid flickering)