etui/widgets/input
Types
Mutable editing state: current value and cursor column (in cells).
pub type InputState {
InputState(value: String, cursor: Int)
}
Constructors
-
InputState(value: String, cursor: Int)
Input widget configuration.
pub type InputWidget {
InputWidget(
max_length: Int,
placeholder: String,
fg: style.Color,
bg: style.Color,
validator: fn(String) -> Result(Nil, String),
error_fg: style.Color,
prompt: String,
password: Bool,
mask: String,
)
}
Constructors
-
InputWidget( max_length: Int, placeholder: String, fg: style.Color, bg: style.Color, validator: fn(String) -> Result(Nil, String), error_fg: style.Color, prompt: String, password: Bool, mask: String, )Arguments
- validator
-
Optional validation function; run via
validate/2. - prompt
-
Prefix shown before the value (e.g. “> “, “$ “). Counts toward width.
- password
-
When
True, render each value cell asmaskinstead of the real char. - mask
-
Mask character used in password mode. Default
"*".
Values
pub fn backspace(state: InputState) -> InputState
Delete the character immediately before the cursor (backspace semantics).
pub fn clear_state(state: InputState) -> InputState
Reset value and cursor to empty.
pub fn delete_to_end(state: InputState) -> InputState
Delete from cursor to end of value.
pub fn input_new(placeholder: String) -> InputWidget
New input widget with placeholder text. Default max length: 256 cells.
pub fn insert_char(
widget: InputWidget,
state: InputState,
ch: String,
) -> InputState
Insert character at cursor. Respects widget max_length.
pub fn move_cursor_left(state: InputState) -> InputState
Move cursor one cell left, clamped to 0.
pub fn move_cursor_right(state: InputState) -> InputState
Move cursor one cell right, clamped to end of value.
pub fn move_to_start(state: InputState) -> InputState
Move cursor to beginning of value.
pub fn render(
buf: buffer.Buffer,
area: geometry.Rect,
widget: InputWidget,
state: InputState,
) -> buffer.Buffer
Render the input field. Shows state.value (bold) or placeholder when empty.
Text is truncated to fit area.size.width (minus one cell reserved for the
trailing cursor). When password is True the value is masked.
pub fn state_from_string(s: String) -> InputState
State pre-populated with a string; cursor placed at the end.
pub fn validate(
i: InputWidget,
value: String,
) -> Result(Nil, String)
Run the validator on value. Returns Ok(Nil) or Error(message).
pub fn with_colors(
i: InputWidget,
fg: style.Color,
bg: style.Color,
) -> InputWidget
pub fn with_error_color(
i: InputWidget,
fg: style.Color,
) -> InputWidget
Set the color used to display validation errors.
pub fn with_mask(i: InputWidget, mask: String) -> InputWidget
Mask character used when password is True. Default "*".
pub fn with_max_length(i: InputWidget, len: Int) -> InputWidget
Maximum value width in cells (wide characters count as 2).
pub fn with_password(
i: InputWidget,
password: Bool,
) -> InputWidget
Render each value cell as the mask character. Use for password fields.
pub fn with_prompt(i: InputWidget, prompt: String) -> InputWidget
Set a prefix shown before the value (e.g. "> ").
pub fn with_style(i: InputWidget, s: style.Style) -> InputWidget
pub fn with_validator(
i: InputWidget,
v: fn(String) -> Result(Nil, String),
) -> InputWidget
Set a validation function. Call validate/2 to run it.