etui/widgets/textarea

Types

Text area configuration.

pub type TextArea {
  TextArea(
    max_lines: Int,
    max_line_length: Int,
    fg: style.Color,
    bg: style.Color,
    cursor_style: style.Style,
  )
}

Constructors

  • TextArea(
      max_lines: Int,
      max_line_length: Int,
      fg: style.Color,
      bg: style.Color,
      cursor_style: style.Style,
    )

    Arguments

    max_lines

    Maximum lines allowed (0 = unlimited).

    max_line_length

    Maximum line width in cells, wide characters count as 2 (0 = unlimited).

    cursor_style

    Style applied to the cursor cell.

Mutable editing state.

pub type TextAreaState {
  TextAreaState(
    lines: List(String),
    cursor_x: Int,
    cursor_y: Int,
  )
}

Constructors

  • TextAreaState(lines: List(String), cursor_x: Int, cursor_y: Int)

    Arguments

    lines

    One string per line. Always at least one element.

    cursor_x

    Cursor column in cells within the current line.

    cursor_y

    Cursor row (0-based line index).

Values

pub fn backspace(state: TextAreaState) -> TextAreaState

Delete the character immediately before the cursor. If at column 0, merges the current line with the previous line.

pub fn cursor_screen_pos(
  state: TextAreaState,
  area: geometry.Rect,
) -> Result(geometry.Position, Nil)

Screen position of the hardware cursor within area. Returns Error(Nil) when the cursor column is beyond the area width (mirrors the render rule: no cursor cell is drawn off-screen).

pub fn delete_to_line_end(state: TextAreaState) -> TextAreaState

Delete from cursor to end of current line.

pub fn effective_offset(
  state: TextAreaState,
  visible_h: Int,
) -> Int

Effective scroll offset for a viewport of visible_h rows. Returns the index of the first visible line so the cursor stays in view. Pass as offset to scrollbar.scrollbar_new.

pub fn insert_char(
  w: TextArea,
  state: TextAreaState,
  ch: String,
) -> TextAreaState

Insert a character at the current cursor position.

pub fn line_count(state: TextAreaState) -> Int

Number of lines.

pub fn move_cursor_down(state: TextAreaState) -> TextAreaState

Move cursor down one line, clamping x to the new line’s width.

pub fn move_cursor_left(state: TextAreaState) -> TextAreaState

Move cursor one cell left. Wraps to end of previous line.

pub fn move_cursor_right(state: TextAreaState) -> TextAreaState

Move cursor one cell right. Wraps to start of next line.

pub fn move_cursor_up(state: TextAreaState) -> TextAreaState

Move cursor up one line, clamping x to the new line’s width.

pub fn move_to_line_end(state: TextAreaState) -> TextAreaState

Move cursor to end of current line.

pub fn move_to_line_start(state: TextAreaState) -> TextAreaState

Move cursor to beginning of current line.

pub fn newline(
  w: TextArea,
  state: TextAreaState,
) -> TextAreaState

Insert a newline at the cursor. Splits the current line.

pub fn render(
  buf: buffer.Buffer,
  area: geometry.Rect,
  w: TextArea,
  state: TextAreaState,
) -> buffer.Buffer

Render the textarea. Scrolls vertically so the cursor line is visible. Highlights the cursor cell with cursor_style.

pub fn state_from_string(s: String) -> TextAreaState

State pre-populated from a string (splits on \n).

pub fn state_new() -> TextAreaState

Empty state: one empty line, cursor at top-left.

pub fn textarea_new() -> TextArea

New textarea with default styles and no limits.

pub fn value(state: TextAreaState) -> String

All lines joined with "\n".

pub fn with_colors(
  w: TextArea,
  fg: style.Color,
  bg: style.Color,
) -> TextArea
pub fn with_cursor_style(w: TextArea, s: style.Style) -> TextArea
pub fn with_max_line_length(w: TextArea, n: Int) -> TextArea
pub fn with_max_lines(w: TextArea, n: Int) -> TextArea
pub fn with_style(w: TextArea, s: style.Style) -> TextArea
Search Document