beamtea_textinput (beamtea v0.1.2)

View Source

A bubble: a single-line text input.

Handles UTF-8 text entry, a movable caret (arrows, Home/End), backspace and delete, an optional character limit, and a placeholder. Because beamtea hides the hardware cursor, the caret is drawn with reverse video.

     init(_)         -> {beamtea_textinput:focus(beamtea_textinput:new(#{placeholder => <<"Name">>})), none}.
     update({key,K}, M) -> {M1, Cmd} = beamtea_textinput:update({key,K}, M), {M1, Cmd}.
     view(M)         -> beamtea_textinput:view(M).
     %% read it back with beamtea_textinput:value(M)

Summary

Functions

Empty the input.

Equivalent to new(#{}).

Create a text input. Options: prompt (default "> "), placeholder, limit (max chars, default infinity), color (caret/prompt accent).

Replace the value; the caret moves to the end.

Feed a message. Only key messages matter, and only while focused.

The current value as a UTF-8 binary.

Render the prompt, the current text and (when focused) the caret.

Types

model/0

-opaque model()

Functions

blur(M)

-spec blur(model()) -> model().

clear(M)

-spec clear(model()) -> model().

Empty the input.

cursor(_)

-spec cursor(model()) -> non_neg_integer().

focus(M)

-spec focus(model()) -> model().

focused(_)

-spec focused(model()) -> boolean().

new()

-spec new() -> model().

Equivalent to new(#{}).

new(Opts)

-spec new(map()) -> model().

Create a text input. Options: prompt (default "> "), placeholder, limit (max chars, default infinity), color (caret/prompt accent).

set_value(Value, M)

-spec set_value(iodata(), model()) -> model().

Replace the value; the caret moves to the end.

update(Msg, M)

-spec update(term(), model()) -> {model(), beamtea:cmd()}.

Feed a message. Only key messages matter, and only while focused.

value(_)

-spec value(model()) -> binary().

The current value as a UTF-8 binary.

view(_)

-spec view(model()) -> iodata().

Render the prompt, the current text and (when focused) the caret.