mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-12 05:15:00 +00:00
commit
f34d686aa5
2 changed files with 63 additions and 19 deletions
|
@ -30,7 +30,8 @@
|
||||||
"cmd-m": "zed::Minimize",
|
"cmd-m": "zed::Minimize",
|
||||||
"cmd-n": "workspace::NewFile",
|
"cmd-n": "workspace::NewFile",
|
||||||
"cmd-shift-n": "workspace::NewWindow",
|
"cmd-shift-n": "workspace::NewWindow",
|
||||||
"cmd-o": "workspace::Open"
|
"cmd-o": "workspace::Open",
|
||||||
|
"ctrl-`": "terminal::Deploy"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use alacritty_terminal::{
|
use alacritty_terminal::{
|
||||||
ansi::{Color::Named, NamedColor},
|
ansi::{Color as AnsiColor, Color::Named, NamedColor},
|
||||||
grid::{Dimensions, Scroll},
|
grid::{Dimensions, Scroll},
|
||||||
index::{Column as GridCol, Line as GridLine, Point, Side},
|
index::{Column as GridCol, Line as GridLine, Point, Side},
|
||||||
selection::SelectionRange,
|
selection::SelectionRange,
|
||||||
|
@ -9,7 +9,7 @@ use editor::{Cursor, CursorShape, HighlightedRange, HighlightedRangeLine};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
color::Color,
|
color::Color,
|
||||||
elements::*,
|
elements::*,
|
||||||
fonts::{TextStyle, Underline},
|
fonts::{Properties, Style::Italic, TextStyle, Underline, Weight},
|
||||||
geometry::{
|
geometry::{
|
||||||
rect::RectF,
|
rect::RectF,
|
||||||
vector::{vec2f, Vector2F},
|
vector::{vec2f, Vector2F},
|
||||||
|
@ -27,6 +27,7 @@ use util::ResultExt;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
cmp::min,
|
cmp::min,
|
||||||
|
mem,
|
||||||
ops::{Deref, Range},
|
ops::{Deref, Range},
|
||||||
};
|
};
|
||||||
use std::{fmt::Debug, ops::Sub};
|
use std::{fmt::Debug, ops::Sub};
|
||||||
|
@ -211,6 +212,7 @@ impl TerminalEl {
|
||||||
text_style: &TextStyle,
|
text_style: &TextStyle,
|
||||||
terminal_theme: &TerminalStyle,
|
terminal_theme: &TerminalStyle,
|
||||||
text_layout_cache: &TextLayoutCache,
|
text_layout_cache: &TextLayoutCache,
|
||||||
|
font_cache: &FontCache,
|
||||||
modal: bool,
|
modal: bool,
|
||||||
selection_range: Option<SelectionRange>,
|
selection_range: Option<SelectionRange>,
|
||||||
) -> (
|
) -> (
|
||||||
|
@ -229,6 +231,12 @@ impl TerminalEl {
|
||||||
let linegroups = grid.into_iter().group_by(|i| i.point.line);
|
let linegroups = grid.into_iter().group_by(|i| i.point.line);
|
||||||
for (line_index, (_, line)) in linegroups.into_iter().enumerate() {
|
for (line_index, (_, line)) in linegroups.into_iter().enumerate() {
|
||||||
for (x_index, cell) in line.enumerate() {
|
for (x_index, cell) in line.enumerate() {
|
||||||
|
let mut fg = cell.fg;
|
||||||
|
let mut bg = cell.bg;
|
||||||
|
if cell.flags.contains(Flags::INVERSE) {
|
||||||
|
mem::swap(&mut fg, &mut bg);
|
||||||
|
}
|
||||||
|
|
||||||
//Increase selection range
|
//Increase selection range
|
||||||
{
|
{
|
||||||
if selection_range
|
if selection_range
|
||||||
|
@ -243,7 +251,7 @@ impl TerminalEl {
|
||||||
|
|
||||||
//Expand background rect range
|
//Expand background rect range
|
||||||
{
|
{
|
||||||
if matches!(cell.bg, Named(NamedColor::Background)) {
|
if matches!(bg, Named(NamedColor::Background)) {
|
||||||
//Continue to next cell, resetting variables if nescessary
|
//Continue to next cell, resetting variables if nescessary
|
||||||
cur_alac_color = None;
|
cur_alac_color = None;
|
||||||
if let Some(rect) = cur_rect {
|
if let Some(rect) = cur_rect {
|
||||||
|
@ -253,26 +261,26 @@ impl TerminalEl {
|
||||||
} else {
|
} else {
|
||||||
match cur_alac_color {
|
match cur_alac_color {
|
||||||
Some(cur_color) => {
|
Some(cur_color) => {
|
||||||
if cell.cell.bg == cur_color {
|
if bg == cur_color {
|
||||||
cur_rect = cur_rect.take().map(|rect| rect.extend());
|
cur_rect = cur_rect.take().map(|rect| rect.extend());
|
||||||
} else {
|
} else {
|
||||||
cur_alac_color = Some(cell.bg);
|
cur_alac_color = Some(bg);
|
||||||
if let Some(_) = cur_rect {
|
if let Some(_) = cur_rect {
|
||||||
rects.push(cur_rect.take().unwrap());
|
rects.push(cur_rect.take().unwrap());
|
||||||
}
|
}
|
||||||
cur_rect = Some(LayoutRect::new(
|
cur_rect = Some(LayoutRect::new(
|
||||||
Point::new(line_index as i32, cell.point.column.0 as i32),
|
Point::new(line_index as i32, cell.point.column.0 as i32),
|
||||||
1,
|
1,
|
||||||
convert_color(&cell.bg, &terminal_theme.colors, modal),
|
convert_color(&bg, &terminal_theme.colors, modal),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
cur_alac_color = Some(cell.bg);
|
cur_alac_color = Some(bg);
|
||||||
cur_rect = Some(LayoutRect::new(
|
cur_rect = Some(LayoutRect::new(
|
||||||
Point::new(line_index as i32, cell.point.column.0 as i32),
|
Point::new(line_index as i32, cell.point.column.0 as i32),
|
||||||
1,
|
1,
|
||||||
convert_color(&cell.bg, &terminal_theme.colors, modal),
|
convert_color(&bg, &terminal_theme.colors, modal),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,8 +291,14 @@ impl TerminalEl {
|
||||||
{
|
{
|
||||||
let cell_text = &cell.c.to_string();
|
let cell_text = &cell.c.to_string();
|
||||||
if cell_text != " " {
|
if cell_text != " " {
|
||||||
let cell_style =
|
let cell_style = TerminalEl::cell_style(
|
||||||
TerminalEl::cell_style(&cell, terminal_theme, text_style, modal);
|
&cell,
|
||||||
|
fg,
|
||||||
|
terminal_theme,
|
||||||
|
text_style,
|
||||||
|
font_cache,
|
||||||
|
modal,
|
||||||
|
);
|
||||||
|
|
||||||
let layout_cell = text_layout_cache.layout_str(
|
let layout_cell = text_layout_cache.layout_str(
|
||||||
cell_text,
|
cell_text,
|
||||||
|
@ -344,25 +358,42 @@ impl TerminalEl {
|
||||||
///Convert the Alacritty cell styles to GPUI text styles and background color
|
///Convert the Alacritty cell styles to GPUI text styles and background color
|
||||||
fn cell_style(
|
fn cell_style(
|
||||||
indexed: &IndexedCell,
|
indexed: &IndexedCell,
|
||||||
|
fg: AnsiColor,
|
||||||
style: &TerminalStyle,
|
style: &TerminalStyle,
|
||||||
text_style: &TextStyle,
|
text_style: &TextStyle,
|
||||||
|
font_cache: &FontCache,
|
||||||
modal: bool,
|
modal: bool,
|
||||||
) -> RunStyle {
|
) -> RunStyle {
|
||||||
let flags = indexed.cell.flags;
|
let flags = indexed.cell.flags;
|
||||||
let fg = convert_color(&indexed.cell.fg, &style.colors, modal);
|
let fg = convert_color(&fg, &style.colors, modal);
|
||||||
|
|
||||||
let underline = flags
|
let underline = flags
|
||||||
.contains(Flags::UNDERLINE)
|
.intersects(Flags::ALL_UNDERLINES)
|
||||||
.then(|| Underline {
|
.then(|| Underline {
|
||||||
color: Some(fg),
|
color: Some(fg),
|
||||||
squiggly: false,
|
squiggly: flags.contains(Flags::UNDERCURL),
|
||||||
thickness: OrderedFloat(1.),
|
thickness: OrderedFloat(1.),
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
let mut properties = Properties::new();
|
||||||
|
if indexed
|
||||||
|
.flags
|
||||||
|
.intersects(Flags::BOLD | Flags::BOLD_ITALIC | Flags::DIM_BOLD)
|
||||||
|
{
|
||||||
|
properties = *properties.weight(Weight::BOLD);
|
||||||
|
}
|
||||||
|
if indexed.flags.intersects(Flags::ITALIC | Flags::BOLD_ITALIC) {
|
||||||
|
properties = *properties.style(Italic);
|
||||||
|
}
|
||||||
|
|
||||||
|
let font_id = font_cache
|
||||||
|
.select_font(text_style.font_family_id, &properties)
|
||||||
|
.unwrap_or(text_style.font_id);
|
||||||
|
|
||||||
RunStyle {
|
RunStyle {
|
||||||
color: fg,
|
color: fg,
|
||||||
font_id: text_style.font_id,
|
font_id: font_id,
|
||||||
underline,
|
underline,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -557,10 +588,21 @@ impl Element for TerminalEl {
|
||||||
terminal.set_size(dimensions);
|
terminal.set_size(dimensions);
|
||||||
terminal.render_lock(mcx, |content, cursor_text| {
|
terminal.render_lock(mcx, |content, cursor_text| {
|
||||||
let mut cells = vec![];
|
let mut cells = vec![];
|
||||||
cells.extend(content.display_iter.map(|ic| IndexedCell {
|
cells.extend(
|
||||||
point: ic.point.clone(),
|
content
|
||||||
cell: ic.cell.clone(),
|
.display_iter
|
||||||
}));
|
//TODO: Add this once there's a way to retain empty lines
|
||||||
|
// .filter(|ic| {
|
||||||
|
// !ic.flags.contains(Flags::HIDDEN)
|
||||||
|
// && !(ic.bg == Named(NamedColor::Background)
|
||||||
|
// && ic.c == ' '
|
||||||
|
// && !ic.flags.contains(Flags::INVERSE))
|
||||||
|
// })
|
||||||
|
.map(|ic| IndexedCell {
|
||||||
|
point: ic.point.clone(),
|
||||||
|
cell: ic.cell.clone(),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
(
|
(
|
||||||
cells,
|
cells,
|
||||||
|
@ -577,6 +619,7 @@ impl Element for TerminalEl {
|
||||||
&text_style,
|
&text_style,
|
||||||
&terminal_theme,
|
&terminal_theme,
|
||||||
cx.text_layout_cache,
|
cx.text_layout_cache,
|
||||||
|
cx.font_cache(),
|
||||||
self.modal,
|
self.modal,
|
||||||
selection,
|
selection,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue