pub struct TerminalRenderer {
pub font_family: String,
pub font_size: Pixels,
pub cell_width: Pixels,
pub cell_height: Pixels,
pub line_height_multiplier: f32,
pub palette: ColorPalette,
}Expand description
Terminal renderer with font settings and cell dimensions.
This struct manages the rendering of terminal content, including text,
backgrounds, and cursor. It maintains font metrics and provides the
paint method for drawing the terminal grid.
§Font Metrics
Cell dimensions are calculated from actual font measurements via
measure_cell. This ensures accurate character
positioning regardless of the font used.
§Usage
The renderer is typically used internally by TerminalView,
but can also be used directly for custom rendering:
// Measure cell dimensions (call once per font change)
renderer.measure_cell(window);
// Paint the terminal grid
renderer.paint(bounds, padding, &term, window, cx);§Performance
For optimal performance:
- Call
measure_cellonly when font settings change - The
paintmethod is designed to be called every frame - Background and text batching minimize GPU draw calls
Fields§
§font_family: StringFont family name (e.g., “Fira Code”, “Menlo”)
font_size: PixelsFont size in pixels
cell_width: PixelsWidth of a single character cell
cell_height: PixelsHeight of a single character cell (line height)
line_height_multiplier: f32Multiplier for line height to accommodate tall glyphs
palette: ColorPaletteColor palette for resolving terminal colors
Implementations§
Source§impl TerminalRenderer
impl TerminalRenderer
Sourcepub fn new(
font_family: String,
font_size: Pixels,
line_height_multiplier: f32,
palette: ColorPalette,
) -> Self
pub fn new( font_family: String, font_size: Pixels, line_height_multiplier: f32, palette: ColorPalette, ) -> Self
Creates a new terminal renderer with the given font settings and color palette.
§Arguments
font_family- The name of the font family to usefont_size- The font size in pixelsline_height_multiplier- Multiplier for line height (e.g., 1.2 for 20% extra)palette- The color palette to use for terminal colors
§Returns
A new TerminalRenderer instance with default cell dimensions.
§Examples
use gpui::px;
use gpui_terminal::render::TerminalRenderer;
use gpui_terminal::ColorPalette;
let renderer = TerminalRenderer::new("Fira Code".to_string(), px(14.0), 1.2, ColorPalette::default());Sourcepub fn measure_cell(&mut self, window: &mut Window)
pub fn measure_cell(&mut self, window: &mut Window)
Measure cell dimensions based on actual font metrics.
This method measures the actual width and height of characters using the GPUI text system.
§Arguments
window- The GPUI window for text system access
Sourcepub fn layout_row(
&self,
row: usize,
cells: impl Iterator<Item = (usize, Cell)>,
colors: &Colors,
) -> (Vec<BackgroundRect>, Vec<BatchedTextRun>)
pub fn layout_row( &self, row: usize, cells: impl Iterator<Item = (usize, Cell)>, colors: &Colors, ) -> (Vec<BackgroundRect>, Vec<BatchedTextRun>)
Layout cells into batched text runs and background rects for a single row.
This method processes a row of terminal cells and groups adjacent cells with identical styling into batched runs. It also collects background rectangles that need to be painted.
§Arguments
row- The row numbercells- Iterator over (column, Cell) pairscolors- Terminal color configuration
§Returns
A tuple of (backgrounds, text_runs) where:
backgroundsis a vector of merged background rectanglestext_runsis a vector of batched text runs
Sourcepub fn paint(
&self,
bounds: Bounds<Pixels>,
padding: Edges<Pixels>,
term: &Term<GpuiEventProxy>,
window: &mut Window,
_cx: &mut App,
)
pub fn paint( &self, bounds: Bounds<Pixels>, padding: Edges<Pixels>, term: &Term<GpuiEventProxy>, window: &mut Window, _cx: &mut App, )
Paint terminal content to the window.
This is the main rendering method that draws the terminal grid, including backgrounds, text, and cursor.
§Arguments
bounds- The bounding box to render withinpadding- Padding around the terminal contentterm- The terminal statewindow- The GPUI windowcx- The application context
Trait Implementations§
Source§impl Clone for TerminalRenderer
impl Clone for TerminalRenderer
Source§fn clone(&self) -> TerminalRenderer
fn clone(&self) -> TerminalRenderer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for TerminalRenderer
impl RefUnwindSafe for TerminalRenderer
impl Send for TerminalRenderer
impl Sync for TerminalRenderer
impl Unpin for TerminalRenderer
impl UnwindSafe for TerminalRenderer
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more