Framebuffer

Struct Framebuffer 

Source
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

Source

pub fn new() -> Self

Creates a new framebuffer.

Source

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.

Source

pub fn flip(&mut self, size: Size)

Begins a new frame with the given size.

Source

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.

Source

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

pub fn indexed(&self, index: IndexedColor) -> u32

Source

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

Source

pub fn contrasted(&self, color: u32) -> u32

Returns a color opposite to the brightness of the given color.

Source

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.

Source

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.

Source

pub fn reverse(&mut self, target: Rect)

Reverses the foreground and background colors in the given rectangle.

Source

pub fn replace_attr(&mut self, target: Rect, mask: Attributes, attr: Attributes)

Replaces VT attributes in the given rectangle.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.