Expand description
Styled text unit with control codes — the smallest rendering primitive.
Segment — styled text unit. Equivalent to Rich’s segment.py.
A Segment is the smallest unit of output: a piece of text with an
associated Style and optional control code.
§Core Types
Segment— text + optional style + optional control codeSegments— a collection of segments with convenience methodsControlType— 16 terminal control codes (bell, cursor movement, etc.)ControlCode— a control type with optional parameters
§Utility Functions (v0.2)
| Function | Description |
|---|---|
Segments::simplify | Combine adjacent segments with identical styles |
split_lines | Split segments into lines at newline boundaries |
strip_styles | Remove all styling, returning plain text |
strip_links | Remove link IDs and URLs from segment styles |
align_top / align_middle / align_bottom | Vertical alignment helpers |
divide | Split segments at given cell offsets |
set_shape | Pad or truncate segments to exact width × height |
filter_control | Keep only control segments (or only non-control) |
get_line_length | Total cell width of a line of segments |
§Example
use rusty_rich::{Segment, Segments, Style};
let segs = Segments::from(vec![
Segment::styled("Hello ", Style::new().bold(true)),
Segment::styled("World", Style::new().bold(true)),
]);
// Combine adjacent same-styled segments
let merged = segs.simplify();
assert_eq!(merged.segments.len(), 1);Structs§
- Segment
- A piece of text with an associated style.
- Segments
- A collection of
Segments, with convenience methods.
Enums§
- Control
Code - Control
Type - Non-printable control codes (equivalent to Rich’s
ControlType).
Functions§
- align_
bottom - Align lines to the bottom of a region of given height.
- align_
middle - Align lines to the middle of a region of given height.
- align_
top - Align lines to the top of a region of given height.
- divide
- Divide segments at the given cell offsets.
- filter_
control - Filter segments, keeping only control codes if
is_controlis true, or only non-control segments ifis_controlis false. - get_
line_ length - Get the total cell length of a line of segments.
- line
- Helper: create a newline segment.
- set_
shape - Set segments to an exact width and height, padding/truncating as needed.
- space
- Helper: create a space segment.
- split_
lines - Split an iterable of segments into lines at newline boundaries.
- strip_
links - Remove link IDs and URLs from all segment styles.
- strip_
styles - Remove all styles from segments, returning plain text only.