repl: Create better terminal output for REPL stdio (#15715)
Rely on our implementation of a GPUI powered alacritty terminal to render stdout & stderr from the repl. Release Notes: - Fixed ANSI escape code and carriage return handling in repl outputs (https://github.com/zed-industries/zed/issues/15640, https://github.com/zed-industries/zed/issues/14855) https://github.com/user-attachments/assets/bd3f1584-863a-4afa-b60b-9d222a830ff8 --------- Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
parent
b6a3556a32
commit
4528e9d582
9 changed files with 168 additions and 398 deletions
|
@ -73,8 +73,8 @@ impl DisplayCursor {
|
|||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct LayoutCell {
|
||||
point: AlacPoint<i32, i32>,
|
||||
pub struct LayoutCell {
|
||||
pub point: AlacPoint<i32, i32>,
|
||||
text: gpui::ShapedLine,
|
||||
}
|
||||
|
||||
|
@ -83,10 +83,10 @@ impl LayoutCell {
|
|||
LayoutCell { point, text }
|
||||
}
|
||||
|
||||
fn paint(
|
||||
pub fn paint(
|
||||
&self,
|
||||
origin: Point<Pixels>,
|
||||
layout: &LayoutState,
|
||||
dimensions: &TerminalSize,
|
||||
_visible_bounds: Bounds<Pixels>,
|
||||
cx: &mut WindowContext,
|
||||
) {
|
||||
|
@ -94,17 +94,17 @@ impl LayoutCell {
|
|||
let point = self.point;
|
||||
|
||||
Point::new(
|
||||
(origin.x + point.column as f32 * layout.dimensions.cell_width).floor(),
|
||||
origin.y + point.line as f32 * layout.dimensions.line_height,
|
||||
(origin.x + point.column as f32 * dimensions.cell_width).floor(),
|
||||
origin.y + point.line as f32 * dimensions.line_height,
|
||||
)
|
||||
};
|
||||
|
||||
self.text.paint(pos, layout.dimensions.line_height, cx).ok();
|
||||
self.text.paint(pos, dimensions.line_height, cx).ok();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
struct LayoutRect {
|
||||
pub struct LayoutRect {
|
||||
point: AlacPoint<i32, i32>,
|
||||
num_of_cells: usize,
|
||||
color: Hsla,
|
||||
|
@ -127,17 +127,17 @@ impl LayoutRect {
|
|||
}
|
||||
}
|
||||
|
||||
fn paint(&self, origin: Point<Pixels>, layout: &LayoutState, cx: &mut WindowContext) {
|
||||
pub fn paint(&self, origin: Point<Pixels>, dimensions: &TerminalSize, cx: &mut WindowContext) {
|
||||
let position = {
|
||||
let alac_point = self.point;
|
||||
point(
|
||||
(origin.x + alac_point.column as f32 * layout.dimensions.cell_width).floor(),
|
||||
origin.y + alac_point.line as f32 * layout.dimensions.line_height,
|
||||
(origin.x + alac_point.column as f32 * dimensions.cell_width).floor(),
|
||||
origin.y + alac_point.line as f32 * dimensions.line_height,
|
||||
)
|
||||
};
|
||||
let size = point(
|
||||
(layout.dimensions.cell_width * self.num_of_cells as f32).ceil(),
|
||||
layout.dimensions.line_height,
|
||||
(dimensions.cell_width * self.num_of_cells as f32).ceil(),
|
||||
dimensions.line_height,
|
||||
)
|
||||
.into();
|
||||
|
||||
|
@ -196,8 +196,8 @@ impl TerminalElement {
|
|||
|
||||
//Vec<Range<AlacPoint>> -> Clip out the parts of the ranges
|
||||
|
||||
fn layout_grid(
|
||||
grid: &Vec<IndexedCell>,
|
||||
pub fn layout_grid(
|
||||
grid: impl Iterator<Item = IndexedCell>,
|
||||
text_style: &TextStyle,
|
||||
// terminal_theme: &TerminalStyle,
|
||||
text_system: &WindowTextSystem,
|
||||
|
@ -755,7 +755,7 @@ impl Element for TerminalElement {
|
|||
// then have that representation be converted to the appropriate highlight data structure
|
||||
|
||||
let (cells, rects) = TerminalElement::layout_grid(
|
||||
cells,
|
||||
cells.iter().cloned(),
|
||||
&text_style,
|
||||
&cx.text_system(),
|
||||
last_hovered_word
|
||||
|
@ -918,7 +918,7 @@ impl Element for TerminalElement {
|
|||
});
|
||||
|
||||
for rect in &layout.rects {
|
||||
rect.paint(origin, &layout, cx);
|
||||
rect.paint(origin, &layout.dimensions, cx);
|
||||
}
|
||||
|
||||
for (relative_highlighted_range, color) in
|
||||
|
@ -939,7 +939,7 @@ impl Element for TerminalElement {
|
|||
}
|
||||
|
||||
for cell in &layout.cells {
|
||||
cell.paint(origin, &layout, bounds, cx);
|
||||
cell.paint(origin, &layout.dimensions, bounds, cx);
|
||||
}
|
||||
|
||||
if self.cursor_visible {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue