repl: Scale the text_style font_size and line_height (#16308)

Replaces #16273.

Release Notes:

- repl: Fixed scaling of stdout/stderr line heights

---------

Co-authored-by: Mikayla <mikayla@zed.dev>
Co-authored-by: Nate Butler <iamnbutler@gmail.com>
This commit is contained in:
Kyle Kelley
2024-08-15 18:46:36 -05:00
committed by GitHub
co-authored by Mikayla Nate Butler
parent 0b407164d0
commit da2bfbd29f
3 changed files with 84 additions and 54 deletions
+40 -9
View File
@@ -1,9 +1,11 @@
use crate::outputs::ExecutionView;
use alacritty_terminal::{term::Config, vte::ansi::Processor};
use gpui::{canvas, size, AnyElement};
use gpui::{canvas, size, AnyElement, FontStyle, TextStyle, WhiteSpace};
use settings::Settings as _;
use std::mem;
use terminal::ZedListener;
use terminal_view::terminal_element::TerminalElement;
use theme::ThemeSettings;
use ui::{prelude::*, IntoElement, ViewContext};
/// Implements the most basic of terminal output for use by Jupyter outputs
@@ -22,8 +24,38 @@ pub struct TerminalOutput {
const DEFAULT_NUM_LINES: usize = 32;
const DEFAULT_NUM_COLUMNS: usize = 128;
pub fn text_style(cx: &mut WindowContext) -> TextStyle {
let settings = ThemeSettings::get_global(cx).clone();
let font_family = settings.buffer_font.family;
let font_features = settings.buffer_font.features;
let font_weight = settings.buffer_font.weight;
let font_fallbacks = settings.buffer_font.fallbacks;
let theme = cx.theme();
let text_style = TextStyle {
font_family,
font_features,
font_weight,
font_fallbacks,
font_size: theme::get_buffer_font_size(cx).into(),
font_style: FontStyle::Normal,
// todo
line_height: cx.line_height().into(),
background_color: Some(theme.colors().terminal_background),
white_space: WhiteSpace::Normal,
// These are going to be overridden per-cell
underline: None,
strikethrough: None,
color: theme.colors().terminal_foreground,
};
text_style
}
pub fn terminal_size(cx: &mut WindowContext) -> terminal::TerminalSize {
let text_style = cx.text_style();
let text_style = text_style(cx);
let text_system = cx.text_system();
let line_height = cx.line_height();
@@ -86,8 +118,8 @@ impl TerminalOutput {
}
}
pub fn render(&self, cx: &ViewContext<ExecutionView>) -> AnyElement {
let text_style = cx.text_style();
pub fn render(&self, cx: &mut ViewContext<ExecutionView>) -> AnyElement {
let text_style = text_style(cx);
let text_system = cx.text_system();
let grid = self
@@ -101,10 +133,9 @@ impl TerminalOutput {
let (cells, rects) = TerminalElement::layout_grid(grid, &text_style, text_system, None, cx);
// lines are 0-indexed, so we must add 1 to get the number of lines
let text_line_height = text_style.line_height_in_pixels(cx.rem_size());
let num_lines = cells.iter().map(|c| c.point.line).max().unwrap_or(0) + 1;
let height = num_lines as f32 * cx.line_height();
let line_height = cx.line_height();
let height = num_lines as f32 * text_line_height;
let font_pixels = text_style.font_size.to_pixels(cx.rem_size());
let font_id = text_system.resolve_font(&text_style.font());
@@ -124,7 +155,7 @@ impl TerminalOutput {
bounds.origin,
&terminal::TerminalSize {
cell_width,
line_height,
line_height: text_line_height,
size: bounds.size,
},
cx,
@@ -136,7 +167,7 @@ impl TerminalOutput {
bounds.origin,
&terminal::TerminalSize {
cell_width,
line_height,
line_height: text_line_height,
size: bounds.size,
},
bounds,