Expand description
Segment system for styled text units.
A Segment is the atomic unit of styled text that can be:
- Cheaply borrowed (
Cow<str>) for string literals / static content - Split at cell positions (not byte positions) for correct wrapping
Segments bridge higher-level text/layout systems to the render pipeline.
§Example
use ftui_text::Segment;
use ftui_style::Style;
// Static text (zero-copy)
let seg = Segment::text("Hello, world!");
assert_eq!(seg.cell_length(), 13);
// Styled text
let styled = Segment::styled("Error!", Style::new().bold());
// Split at cell position
let (left, right) = seg.split_at_cell(5);
assert_eq!(left.as_str(), "Hello");
assert_eq!(right.as_str(), ", world!");Structs§
- Segment
- A segment of styled text.
- Segment
Line - A line of segments.
- Segment
Lines - Collection of lines (multi-line text).
Enums§
- Control
Code - Control codes that can be carried by a segment.
Functions§
- find_
cell_ boundary - Find the byte position that corresponds to a cell position.
- join_
lines - Join lines into a flat sequence of segments with newlines between.
- split_
into_ lines - Split segments by newlines into lines.