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 pen over the base style it is
given, parses the input’s inline SGR and OSC 8 sequences into that pen, and
writes each cell as the pen inherited onto the base. 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,
style: impl Into<Style>,
) -> Position
fn set_str( &mut self, pos: impl Into<Position>, s: &str, style: impl Into<Style>, ) -> Position
Paint s starting at pos, clipped to the target bounds.
The painter’s running Style takes precedence and inherits any unset
fields from style, so the running style carries across calls and
style only fills in what it has not set. Inline SGR and OSC 8 sequences
then update the running style as the input is processed. 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.style— base style the running style inherits unset fields from.
§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,
style: impl Into<Style>,
) -> Position
fn set_str_wrap( &mut self, pos: impl Into<Position>, s: &str, wrap: WrapMode, style: impl Into<Style>, ) -> Position
Paint s starting at pos with explicit wrapping behavior.
The target bounds are the clipping rectangle. WrapMode::Truncate
stops at the right edge; 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.style— initial style 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,
style: impl Into<Style>,
) -> Position
fn set_str_rect( &mut self, rect: impl Into<Rect>, s: &str, style: impl Into<Style>, ) -> 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.style— initial style 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,
style: impl Into<Style>,
) -> Position
fn set_str_rect_wrap( &mut self, rect: impl Into<Rect>, s: &str, wrap: WrapMode, style: impl Into<Style>, ) -> 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.style— initial style 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,
tail: &str,
tail_style: impl Into<Style>,
) -> Position
fn set_str_truncate( &mut self, pos: impl Into<Position>, s: &str, tail: &str, tail_style: impl Into<Style>, ) -> 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, painting stops and tail is stamped over
the trailing columns so it ends exactly at the right edge. The tail
appears only when the text actually overflows; text that fits is left
untouched.
tail is painted with tail_style as its starting style 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.tail— truncation indicator, painted whensoverflows.tail_style— starting style 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,
tail: &str,
tail_style: impl Into<Style>,
) -> Position
fn set_str_rect_truncate( &mut self, rect: impl Into<Rect>, s: &str, tail: &str, tail_style: impl Into<Style>, ) -> 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 the tail is stamped at rect’s right
edge when the text overflows it.
§Parameters
rect— clipping rectangle and starting origin.s— UTF-8 string to paint.tail— truncation indicator, painted whensoverflows.tail_style— starting style 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> 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,
impl<'s, S> !UnwindSafe for Painter<'s, S>
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