Module textarea

Source
Expand description

Textarea component for Bubble Tea applications.

This module provides a multi-line text input component with feature parity to the Go bubbles/textarea package. It supports soft-wrapping, line numbers, customizable prompts, clipboard integration, and rich theming via Lip Gloss styles.

The component implements the crate’s Component trait so it can be focused and blurred, and it exposes a Model with idiomatic methods for editing and navigation (insert, delete, move by character/word/line, etc.).

§Features

  • Soft-wrapped lines with correct column/character accounting for double-width runes
  • Optional line numbers and per-line prompts (static or via a prompt function)
  • Cursor movement by character, word, and line with deletion/edit helpers
  • Viewport-driven rendering for large inputs
  • Clipboard paste integration (platform dependent)
  • Theming via TextareaStyle for focused and blurred states

§Example

use bubbletea_widgets::{textarea, Component};

// Create a textarea with defaults
let mut ta = textarea::new();
ta.set_width(40);
ta.set_height(6);
ta.placeholder = "Type here…".into();

// Focus to start receiving input
let _ = ta.focus();

// Programmatic edits
ta.insert_string("Hello\nworld!");
ta.word_left();
ta.uppercase_right();

// Render view (string with ANSI styling)
let view = ta.view();
println!("{}", view);

See the helpers module for key bindings and styling utilities, and memoization for the internal soft-wrap cache.

Modules§

helpers
Helper functions and types for the textarea component.
memoization
Memoization utilities for the textarea component.

Structs§

LineInfo
LineInfo helper for tracking line information regarding soft-wrapped lines Direct port from Go’s LineInfo struct
Model
Model is the Bubble Tea model for this text area element. Direct port from Go’s Model struct with all fields preserved
PasteErrMsg
Error message produced when a paste operation fails.
PasteMsg
Internal messages for clipboard operations

Functions§

default_styles
Default styles matching Go’s DefaultStyles() function
new
Create a new textarea model - convenience function