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

source

pub const ENTER: KeyCombination = _

source

pub const ALT_ENTER: KeyCombination = _

source

pub fn new(area: Area) -> Self

source

pub fn set_mono_line(&mut self)

source

pub fn new_line_on<K: Into<KeyCombination>>(&mut self, key: K)

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);
source

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

source

pub fn set_area(&mut self, area: Area)

source

pub const fn area(&self) -> &Area

source

pub const fn scroll(&self) -> Pos

return the current scrolling state on both axis

source

pub fn set_focus(&mut self, b: bool)

Tell the input to be or not focused

source

pub const fn focused(&self) -> bool

source

pub fn set_normal_style(&mut self, style: CompoundStyle)

source

pub fn set_unfocused_style(&mut self, style: CompoundStyle)

source

pub const fn content(&self) -> &InputFieldContent

source

pub fn get_content(&self) -> String

source

pub fn can_move_left(&self) -> bool

source

pub fn can_move_right(&self) -> bool

source

pub fn is_empty(&self) -> bool

source

pub fn copy_selection(&mut self) -> String

source

pub fn cut_selection(&mut self) -> String

source

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.

source

pub fn is_content(&self, s: &str) -> bool

tell whether the content of the input is equal to the argument

source

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.

source

pub fn insert_new_line(&mut self) -> bool

source

pub fn put_char(&mut self, c: char) -> bool

put a char at cursor position (and increment this position).

source

pub fn clear(&mut self)

source

pub fn insert_str<S: AsRef<str>>(&mut self, s: S)

Insert the string on cursor point, as if it was typed

source

pub fn move_up(&mut self) -> bool

source

pub fn move_down(&mut self) -> bool

source

pub fn move_left(&mut self) -> bool

source

pub fn move_right(&mut self) -> bool

source

pub fn move_to_start(&mut self) -> bool

source

pub fn move_to_end(&mut self) -> bool

source

pub fn move_to_line_start(&mut self) -> bool

source

pub fn move_to_line_end(&mut self) -> bool

source

pub fn move_word_left(&mut self) -> bool

source

pub fn move_word_right(&mut self) -> bool

source

pub fn del_char_below(&mut self) -> bool

source

pub fn del_selection(&mut self) -> bool

source

pub fn del_char_left(&mut self) -> bool

source

pub fn del_word_left(&mut self) -> bool

source

pub fn del_word_right(&mut self) -> bool

source

pub fn move_current_line_up(&mut self) -> bool

source

pub fn move_current_line_down(&mut self) -> bool

source

pub fn select_word_around(&mut self) -> bool

source

pub fn page_up(&mut self) -> bool

source

pub fn page_down(&mut self) -> bool

source

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.

source

pub fn apply_key_combination<K: Into<KeyCombination>>(&mut self, key: K) -> bool

apply a key combination

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.

source

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.

source

pub fn apply_click_event(&mut self, x: u16, y: u16) -> bool

Apply a simple left click event

source

pub fn apply_mouse_event( &mut self, mouse_event: MouseEvent, is_double_click: bool ) -> bool

Apply a mouse event

source

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.

source

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.

source

pub fn scroll_up(&mut self) -> bool

source

pub fn scroll_down(&mut self) -> bool

source

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)

source

pub fn display(&self) -> Result<(), Error>

render the input field on stdout

Trait Implementations§

source§

impl Default for InputField

source§

fn default() -> Self

Returns the “default value” for a type. Read more

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<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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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.