Skip to main content

Module segment

Module segment 

Source
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.
SegmentLine
A line of segments.
SegmentLines
Collection of lines (multi-line text).

Enums§

ControlCode
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.