Skip to main content

Crate ftui_text

Crate ftui_text 

Source
Expand description

Text handling for FrankenTUI.

This crate provides text primitives for styled text rendering:

§Role in FrankenTUI

ftui-text owns the text model used by widgets and renderers: spans, lines, wrapping, width calculations, and editing utilities. It is deliberately independent of rendering and terminal I/O so it can be reused across widgets, the demo showcase, and any consumer crate.

§How it fits in the system

Widgets build Text and Span structures, layout depends on width measurement, and the render kernel consumes text as styled cells. This crate is the glue between high-level content and low-level cell output.

§Example

use ftui_text::{Segment, Text, Span, Line, WidthCache};
use ftui_style::Style;

// Create styled segments (low-level)
let seg = Segment::styled("Error:", Style::new().bold());

// Create styled text (high-level)
let text = Text::from_spans([
    Span::raw("Status: "),
    Span::styled("OK", Style::new().bold()),
]);

// Multi-line text
let text = Text::raw("line 1\nline 2\nline 3");
assert_eq!(text.height(), 3);

// Truncate with ellipsis
let mut text = Text::raw("hello world");
text.truncate(8, Some("..."));
assert_eq!(text.to_plain_text(), "hello...");

// Cache text widths for performance
let mut cache = WidthCache::new(1000);
let width = cache.get_or_compute("Hello, world!");
assert_eq!(width, 13);

Re-exports§

pub use cursor::CursorNavigator;
pub use cursor::CursorPosition;
pub use editor::Editor;
pub use editor::Selection;
pub use rope::Rope;
pub use segment::ControlCode;
pub use segment::Segment;
pub use segment::SegmentLine;
pub use segment::SegmentLines;
pub use segment::join_lines;
pub use segment::split_into_lines;
pub use text::Line;
pub use text::Span;
pub use text::Text;
pub use view::TextView;
pub use view::ViewLine;
pub use view::Viewport;
pub use width_cache::CacheStats;
pub use width_cache::CountMinSketch;
pub use width_cache::DEFAULT_CACHE_CAPACITY;
pub use width_cache::Doorkeeper;
pub use width_cache::TinyLfuWidthCache;
pub use width_cache::WidthCache;
pub use wrap::KpBreakResult;
pub use wrap::WrapMode;
pub use wrap::WrapOptions;
pub use wrap::ascii_width;
pub use wrap::display_width;
pub use wrap::grapheme_count;
pub use wrap::grapheme_width;
pub use wrap::graphemes;
pub use wrap::has_wide_chars;
pub use wrap::is_ascii_only;
pub use wrap::truncate_to_width;
pub use wrap::truncate_to_width_with_info;
pub use wrap::truncate_with_ellipsis;
pub use wrap::word_boundaries;
pub use wrap::word_segments;
pub use wrap::wrap_optimal;
pub use wrap::wrap_text;
pub use wrap::wrap_text_optimal;
pub use wrap::wrap_with_options;
pub use search::SearchResult;
pub use search::search_ascii_case_insensitive;
pub use search::search_exact;
pub use search::search_exact_overlapping;

Modules§

cursor
Cursor utilities for text editing widgets.
editor
Core text editing operations on top of Rope + CursorNavigator.
rope
Rope-backed text storage with line/column helpers.
search
Unicode-aware text search utilities.
segment
Segment system for styled text units.
text
Text type for styled text collections.
view
Text view utilities for scrollable, wrapped display.
width_cache
LRU width cache for efficient text measurement.
wrap
Text wrapping with Unicode correctness.

Structs§

TextMeasurement
Bounds-based text measurement for layout negotiation.