pub struct Framebuffer { /* private fields */ }Expand description
A shoddy framebuffer for terminal applications.
The idea is that you create a Framebuffer, draw a bunch of text and
colors into it, and it takes care of figuring out what changed since the
last rendering and sending the differences as VT to the terminal.
This is an improvement over how many other terminal applications work,
as they fail to accurately track what changed. If you watch the output
of vim for instance, you’ll notice that it redraws unrelated parts of
the screen all the time.
Implementations§
Source§impl Framebuffer
impl Framebuffer
Sourcepub fn set_indexed_colors(&mut self, colors: [u32; 18])
pub fn set_indexed_colors(&mut self, colors: [u32; 18])
Sets the base color palette.
If you call this method, Framebuffer expects that you
successfully detect the light/dark mode of the terminal.
Sourcepub fn replace_text(
&mut self,
y: CoordType,
origin_x: CoordType,
clip_right: CoordType,
text: &str,
)
pub fn replace_text( &mut self, y: CoordType, origin_x: CoordType, clip_right: CoordType, text: &str, )
Replaces text contents in a single line of the framebuffer. All coordinates are in viewport coordinates. Assumes that control characters have been replaced or escaped.
Sourcepub fn draw_scrollbar(
&mut self,
clip_rect: Rect,
track: Rect,
content_offset: CoordType,
content_height: CoordType,
) -> CoordType
pub fn draw_scrollbar( &mut self, clip_rect: Rect, track: Rect, content_offset: CoordType, content_height: CoordType, ) -> CoordType
Draws a scrollbar in the given track rectangle.
Not entirely sure why I put it here instead of elsewhere.
§Parameters
clip_rect: Clips the rendering to this rectangle. This is relevant when you have scrollareas inside scrollareas.track: The rectangle in which to draw the scrollbar. In absolute viewport coordinates.content_offset: The current offset of the scrollarea.content_height: The height of the scrollarea content.
pub fn indexed(&self, index: IndexedColor) -> u32
Sourcepub fn indexed_alpha(
&self,
index: IndexedColor,
numerator: u32,
denominator: u32,
) -> u32
pub fn indexed_alpha( &self, index: IndexedColor, numerator: u32, denominator: u32, ) -> u32
Returns a color from the palette.
To facilitate constant folding by the compiler,
alpha is given as a fraction (numerator / denominator).
Sourcepub fn contrasted(&self, color: u32) -> u32
pub fn contrasted(&self, color: u32) -> u32
Returns a color opposite to the brightness of the given color.
Sourcepub fn blend_bg(&mut self, target: Rect, bg: u32)
pub fn blend_bg(&mut self, target: Rect, bg: u32)
Blends the given sRGB color onto the background bitmap.
TODO: The current approach blends foreground/background independently,
but ideally blend_bg with semi-transparent dark should also darken text below it.
Sourcepub fn blend_fg(&mut self, target: Rect, fg: u32)
pub fn blend_fg(&mut self, target: Rect, fg: u32)
Blends the given sRGB color onto the foreground bitmap.
TODO: The current approach blends foreground/background independently,
but ideally blend_fg should blend with the background color below it.
Sourcepub fn reverse(&mut self, target: Rect)
pub fn reverse(&mut self, target: Rect)
Reverses the foreground and background colors in the given rectangle.
Sourcepub fn replace_attr(&mut self, target: Rect, mask: Attributes, attr: Attributes)
pub fn replace_attr(&mut self, target: Rect, mask: Attributes, attr: Attributes)
Replaces VT attributes in the given rectangle.
Sourcepub fn set_cursor(&mut self, pos: Point, overtype: bool)
pub fn set_cursor(&mut self, pos: Point, overtype: bool)
Sets the current visible cursor position and type.
Call this when focus is inside an editable area and you want to show the cursor.
Sourcepub fn render<'a>(&mut self, arena: &'a Arena) -> ArenaString<'a>
pub fn render<'a>(&mut self, arena: &'a Arena) -> ArenaString<'a>
Renders the framebuffer contents accumulated since the
last call to flip() and returns them serialized as VT.