Expand description
Text handling for FrankenTUI.
This crate provides text primitives for styled text rendering:
Segment- atomic unit of styled text with cell-aware splittingSegmentLine- a line of segmentsSegmentLines- multi-line textSpan- styled text span for ergonomic constructionLine- a line of styled spansText- multi-line styled textRope- rope-backed text storageCursorPosition/CursorNavigator- text cursor utilitiesEditor- core text editing operations (insert, delete, cursor movement)WidthCache- LRU cache for text width measurements
§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 cluster_map::ClusterEntry;pub use cluster_map::ClusterMap;pub use cursor::CursorPosition;pub use editor::Editor;pub use editor::Selection;pub use hyphenation::HyphenBreakPoint;pub use hyphenation::HyphenationDict;pub use hyphenation::HyphenationPattern;pub use hyphenation::PatternTrie;pub use hyphenation::break_penalties;pub use hyphenation::compile_pattern;pub use hyphenation::english_dict_mini;pub use incremental_break::BreakerSnapshot;pub use incremental_break::EditEvent;pub use incremental_break::IncrementalBreaker;pub use incremental_break::ReflowResult;pub use justification::GlueSpec;pub use justification::JustificationControl;pub use justification::JustifyMode;pub use justification::SUBCELL_SCALE;pub use justification::SpaceCategory;pub use justification::SpacePenalty;pub use layout_policy::LayoutPolicy;pub use layout_policy::LayoutTier;pub use layout_policy::PolicyError;pub use layout_policy::ResolvedPolicy;pub use layout_policy::RuntimeCapability;pub use rope::Rope;pub use script_segmentation::RunCacheKey;pub use script_segmentation::RunDirection;pub use script_segmentation::Script;pub use script_segmentation::ScriptRun;pub use script_segmentation::TextRun;pub use script_segmentation::partition_by_script;pub use script_segmentation::partition_text_runs;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 shaped_render::CellPlacement;pub use shaped_render::RenderHint;pub use shaped_render::ShapedLineLayout;pub use shaped_render::SpacingDelta;pub use shaping::FontFeature;pub use shaping::FontFeatures;pub use shaping::FontId;pub use shaping::NoopShaper;pub use shaping::ShapedGlyph;pub use shaping::ShapedRun;pub use shaping::ShapingCache;pub use shaping::ShapingCacheStats;pub use shaping::ShapingKey;pub use shaping::TextShaper;pub use shaping_fallback::FallbackEvent;pub use shaping_fallback::FallbackStats;pub use shaping_fallback::ShapingFallback;pub use text::Line;pub use text::Span;pub use text::Text;pub use tier_budget::FrameBudget;pub use tier_budget::MemoryBudget;pub use tier_budget::QueueBudget;pub use tier_budget::SafetyInvariant;pub use tier_budget::TierBudget;pub use tier_budget::TierFeatures;pub use tier_budget::TierLadder;pub use vertical_metrics::BaselineGrid;pub use vertical_metrics::LeadingSpec;pub use vertical_metrics::ParagraphSpacing;pub use vertical_metrics::VerticalMetrics;pub use vertical_metrics::VerticalPolicy;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::S3FifoWidthCache;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::WidthMode;pub use search::display_col_at;pub use search::search_ascii_case_insensitive;pub use search::search_exact;pub use search::search_exact_overlapping;
Modules§
- cluster_
map - Bidirectional cluster↔cell mapping for shaped text.
- cursor
- Cursor utilities for text editing widgets.
- editor
- Core text editing operations on top of Rope + CursorNavigator.
- hyphenation
- Deterministic hyphenation engine using Liang’s TeX algorithm.
- incremental_
break - Incremental Knuth-Plass line-break optimizer.
- justification
- Microtypographic justification controls for the Knuth-Plass pipeline.
- layout_
policy - User-facing layout policy presets and deterministic fallback contract.
- rope
- Rope-backed text storage with line/column helpers.
- script_
segmentation - Script segmentation and bidi-safe text run partitioning.
- search
- Unicode-aware text search utilities.
- segment
- Segment system for styled text units.
- shaped_
render - Shaped-run render path with spacing/kerning deltas.
- shaping
- Text shaping backend and deterministic shaped-run cache.
- shaping_
fallback - Deterministic fallback path for shaped text rendering.
- text
- Text type for styled text collections.
- tier_
budget - Frame-time, memory, and queue budgets per quality tier.
- vertical_
metrics - Leading, baseline-grid, and paragraph spacing system.
- view
- Text view utilities for scrollable, wrapped display.
- width_
cache - LRU width cache for efficient text measurement.
- wrap
- Text wrapping with Unicode correctness.
Structs§
- Text
Measurement - Bounds-based text measurement for layout negotiation.