pub struct Painter<'s, S: TextSurface + ?Sized> { /* private fields */ }Expand description
Paint styled strings into a TextSurface.
The painter snapshots its target’s WidthMode and eaw_wide policy at
construction, both fixed for the painter’s lifetime. It holds no style of
its own: each paint call starts with an empty SGR pen and the base link from
its Pen value. It parses inline SGR and OSC 8 sequences, then writes
each cell with the inherited visual style and active link. Text is written
into the borrowed target surface; dropping a painter has no side effects.
Implementations§
Source§impl<'s, S: TextSurface + ?Sized> Painter<'s, S>
impl<'s, S: TextSurface + ?Sized> Painter<'s, S>
Trait Implementations§
Source§impl<'s, S: TextSurface + ?Sized> Bounded for Painter<'s, S>
impl<'s, S: TextSurface + ?Sized> Bounded for Painter<'s, S>
Source§impl<'s, S: TextSurface + ?Sized> SurfaceMut for Painter<'s, S>
impl<'s, S: TextSurface + ?Sized> SurfaceMut for Painter<'s, S>
Source§fn set_cell(&mut self, pos: Position, cell: &Cell)
fn set_cell(&mut self, pos: Position, cell: &Cell)
cell at pos. Implementations are responsible for
wide-cell semantics (continuation markers, blanking covered
cells) and any dirty tracking they care to do. Taking &Cell
lets implementations skip the clone when the destination
already matches. Read moreSource§fn insert_lines(&mut self, y: u16, count: u16, bounds_bottom: u16, fill: &Cell)
fn insert_lines(&mut self, y: u16, count: u16, bounds_bottom: u16, fill: &Cell)
n blank rows at y, pushing existing rows down within
[y, bounds_bottom). Rows pushed past bounds_bottom are lost.
Freed top rows are filled with fill. Read moreSource§fn delete_lines(&mut self, y: u16, count: u16, bounds_bottom: u16, fill: &Cell)
fn delete_lines(&mut self, y: u16, count: u16, bounds_bottom: u16, fill: &Cell)
n rows at y, pulling existing rows up within
[y, bounds_bottom). The bottom n rows of the window are
filled with fill. Read moreSource§fn insert_cells(
&mut self,
pos: Position,
count: u16,
bounds_right: u16,
fill: &Cell,
)
fn insert_cells( &mut self, pos: Position, count: u16, bounds_right: u16, fill: &Cell, )
n blank cells at pos, pushing cells in
[pos.x, bounds_right) right within row pos.y. Cells pushed
past bounds_right are lost. The freed slots [pos.x, pos.x + n)
are filled with fill. Read moreSource§fn delete_cells(
&mut self,
pos: Position,
count: u16,
bounds_right: u16,
fill: &Cell,
)
fn delete_cells( &mut self, pos: Position, count: u16, bounds_right: u16, fill: &Cell, )
n cells at pos, pulling cells in
[pos.x + n, bounds_right) left within row pos.y. The freed
slots [bounds_right - n, bounds_right) are filled with fill. Read moreSource§fn clear(&mut self)
fn clear(&mut self)
Cell::BLANK. Read moreSource§fn clear_rect(&mut self, rect: Rect)
fn clear_rect(&mut self, rect: Rect)
Cell::BLANK. Read moreSource§impl<'s, S: TextSurface + ?Sized> TextSurface for Painter<'s, S>
A Painter is itself a TextSurface whose set_str family recognizes
inline SGR and OSC 8 hyperlink sequences, updating the running
the running style as the input is parsed. This is the escape-aware
counterpart to the literal painting of the default TextSurface methods.
impl<'s, S: TextSurface + ?Sized> TextSurface for Painter<'s, S>
A Painter is itself a TextSurface whose set_str family recognizes
inline SGR and OSC 8 hyperlink sequences, updating the running
the running style as the input is parsed. This is the escape-aware
counterpart to the literal painting of the default TextSurface methods.
Source§fn str_width(&self, s: &str) -> u16
fn str_width(&self, s: &str) -> u16
Measure s, skipping recognized inline SGR and OSC 8 escape
sequences so they contribute no width. This is the escape-aware
counterpart to the literal default
str_width.
Source§fn set_str(
&mut self,
pos: impl Into<Position>,
s: &str,
pen: impl Into<Pen>,
) -> Position
fn set_str( &mut self, pos: impl Into<Position>, s: &str, pen: impl Into<Pen>, ) -> Position
Paint s starting at pos, clipped to the target bounds.
Inline SGR state inherits unset fields from pen.style, and the
optional link applies until an inline OSC 8 sequence changes it. Each
call starts from its own pen. Newline advances
to the next row at the bounds’ left edge; carriage return returns to that
left edge on the current row. Right-edge behavior is
WrapMode::Truncate.
§Parameters
pos— starting cell position.s— UTF-8 input string.pen— base visual style and optional link for painted cells.
§Returns
The cursor position immediately after the last written cell, or where painting stopped.
§Errors and panics
This method does not return errors and does not intentionally panic.
Source§fn set_str_wrap(
&mut self,
pos: impl Into<Position>,
s: &str,
wrap: WrapMode,
pen: impl Into<Pen>,
) -> Position
fn set_str_wrap( &mut self, pos: impl Into<Position>, s: &str, wrap: WrapMode, pen: impl Into<Pen>, ) -> Position
Paint s starting at pos with explicit wrapping behavior.
The target bounds are the clipping rectangle. WrapMode::Truncate
drops the rest of the row at the right edge and resumes on the next
row; WrapMode::Wrap continues on the next row
at the bounds’ left edge until the bottom edge is reached.
§Parameters
pos— starting cell position.s— UTF-8 input string.wrap— right-edge behavior for non-zero-width clusters.pen— base visual style and optional link for this call.
§Returns
The cursor position immediately after the last written cell, or where painting stopped.
§Errors and panics
This method does not return errors and does not intentionally panic.
Source§fn set_str_rect(
&mut self,
rect: impl Into<Rect>,
s: &str,
pen: impl Into<Pen>,
) -> Position
fn set_str_rect( &mut self, rect: impl Into<Rect>, s: &str, pen: impl Into<Pen>, ) -> Position
Paint s into rect, clipped to rect ∩ target.bounds().
Painting starts at rect’s top-left. Newline and carriage return use
rect’s left edge as the return column. Right-edge behavior is
WrapMode::Truncate.
§Parameters
rect— origin and clipping rectangle.s— UTF-8 input string.pen— base visual style and optional link for this call.
§Returns
The cursor position immediately after the last written cell, or where painting stopped.
§Errors and panics
This method does not return errors and does not intentionally panic.
Source§fn set_str_rect_wrap(
&mut self,
rect: impl Into<Rect>,
s: &str,
wrap: WrapMode,
pen: impl Into<Pen>,
) -> Position
fn set_str_rect_wrap( &mut self, rect: impl Into<Rect>, s: &str, wrap: WrapMode, pen: impl Into<Pen>, ) -> Position
Paint s into rect with explicit wrapping behavior.
The clipping rectangle is rect ∩ target.bounds(). WrapMode::Wrap
flows down inside rect; WrapMode::Truncate stops at rect’s
right edge.
§Parameters
rect— origin and clipping rectangle.s— UTF-8 input string.wrap— right-edge behavior for non-zero-width clusters.pen— base visual style and optional link for this call.
§Returns
The cursor position immediately after the last written cell, or where painting stopped.
§Errors and panics
This method does not return errors and does not intentionally panic.
Source§fn set_str_truncate(
&mut self,
pos: impl Into<Position>,
s: &str,
s_pen: impl Into<Pen>,
tail: &str,
tail_pen: impl Into<Pen>,
) -> Position
fn set_str_truncate( &mut self, pos: impl Into<Position>, s: &str, s_pen: impl Into<Pen>, tail: &str, tail_pen: impl Into<Pen>, ) -> Position
Paint s starting at pos, truncating with a tail indicator.
Text is painted across the target bounds. When a non-zero-width cluster
would cross the right edge, the rest of that row is dropped and tail
is stamped over its trailing columns so it ends exactly at the right
edge. Painting resumes on the next row if the text continues past a
newline, so a multi-line s can stamp one tail per overflowing row.
The tail appears only on rows that actually overflow; a row that fits
is left untouched.
tail is painted with tail_pen and may carry
its own inline escape sequences, so it can be a single glyph ("…"), a
word (" more"), or a multi-style span. If the tail is wider than the
available space, it is dropped and the text is hard-truncated instead.
§Parameters
pos— starting cell position.s— UTF-8 string to paint.s_pen— base pen for the main text; inline escapes can change it.tail— truncation indicator, painted whensoverflows.tail_pen— base pen for the tail.
§Returns
The cursor position immediately after the last written cell, or where painting stopped.
§Errors and panics
This method does not return errors and does not intentionally panic.
Source§fn set_str_rect_truncate(
&mut self,
rect: impl Into<Rect>,
s: &str,
s_pen: impl Into<Pen>,
tail: &str,
tail_pen: impl Into<Pen>,
) -> Position
fn set_str_rect_truncate( &mut self, rect: impl Into<Rect>, s: &str, s_pen: impl Into<Pen>, tail: &str, tail_pen: impl Into<Pen>, ) -> Position
Paint s inside rect, truncating with a tail indicator.
This is the rectangular form of
set_str_truncate: the clip rectangle is
rect ∩ target.bounds(), and a tail is stamped at rect’s right
edge on each row that overflows it.
§Parameters
rect— clipping rectangle and starting origin.s— UTF-8 string to paint.s_pen— base pen for the main text; inline escapes can change it.tail— truncation indicator, painted whensoverflows.tail_pen— base pen for the tail.
§Returns
The cursor position immediately after the last written cell, or where painting stopped.
§Errors and panics
This method does not return errors and does not intentionally panic.
Source§fn width_mode(&self) -> WidthMode
fn width_mode(&self) -> WidthMode
Source§fn eaw_wide(&self) -> bool
fn eaw_wide(&self) -> bool
Auto Trait Implementations§
impl<'s, S> !UnwindSafe for Painter<'s, S>
impl<'s, S> Freeze for Painter<'s, S>where
S: ?Sized,
impl<'s, S> RefUnwindSafe for Painter<'s, S>where
S: RefUnwindSafe + ?Sized,
impl<'s, S> Send for Painter<'s, S>
impl<'s, S> Sync for Painter<'s, S>
impl<'s, S> Unpin for Painter<'s, S>where
S: ?Sized,
impl<'s, S> UnsafeUnpin for Painter<'s, S>where
S: ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<S> Encode for S
impl<S> Encode for S
Source§fn encode<W: Write>(&self, w: &mut W) -> Result<()>
fn encode<W: Write>(&self, w: &mut W) -> Result<()>
w as escape sequences and text. Read more