Get terminal turning on

This commit is contained in:
Mikayla 2023-12-01 17:01:57 -08:00
parent 6730ff3624
commit fe83919746
No known key found for this signature in database
5 changed files with 223 additions and 241 deletions

View File

@ -350,7 +350,6 @@ impl Telemetry {
milliseconds_since_first_event: self.milliseconds_since_first_event(), milliseconds_since_first_event: self.milliseconds_since_first_event(),
}; };
dbg!(telemetry_settings);
self.report_clickhouse_event(event, telemetry_settings, true) self.report_clickhouse_event(event, telemetry_settings, true)
} }

View File

@ -1,118 +1,5 @@
// todo!()
use alacritty_terminal::term::color::Rgb as AlacRgb; use alacritty_terminal::term::color::Rgb as AlacRgb;
// use gpui::color::Color;
// use theme2::TerminalStyle;
///Converts a 2, 8, or 24 bit color ANSI color to the GPUI equivalent
// pub fn convert_color(alac_color: &AnsiColor, style: &TerminalStyle) -> Color {
// match alac_color {
// //Named and theme defined colors
// alacritty_terminal::ansi::Color::Named(n) => match n {
// alacritty_terminal::ansi::NamedColor::Black => style.black,
// alacritty_terminal::ansi::NamedColor::Red => style.red,
// alacritty_terminal::ansi::NamedColor::Green => style.green,
// alacritty_terminal::ansi::NamedColor::Yellow => style.yellow,
// alacritty_terminal::ansi::NamedColor::Blue => style.blue,
// alacritty_terminal::ansi::NamedColor::Magenta => style.magenta,
// alacritty_terminal::ansi::NamedColor::Cyan => style.cyan,
// alacritty_terminal::ansi::NamedColor::White => style.white,
// alacritty_terminal::ansi::NamedColor::BrightBlack => style.bright_black,
// alacritty_terminal::ansi::NamedColor::BrightRed => style.bright_red,
// alacritty_terminal::ansi::NamedColor::BrightGreen => style.bright_green,
// alacritty_terminal::ansi::NamedColor::BrightYellow => style.bright_yellow,
// alacritty_terminal::ansi::NamedColor::BrightBlue => style.bright_blue,
// alacritty_terminal::ansi::NamedColor::BrightMagenta => style.bright_magenta,
// alacritty_terminal::ansi::NamedColor::BrightCyan => style.bright_cyan,
// alacritty_terminal::ansi::NamedColor::BrightWhite => style.bright_white,
// alacritty_terminal::ansi::NamedColor::Foreground => style.foreground,
// alacritty_terminal::ansi::NamedColor::Background => style.background,
// alacritty_terminal::ansi::NamedColor::Cursor => style.cursor,
// alacritty_terminal::ansi::NamedColor::DimBlack => style.dim_black,
// alacritty_terminal::ansi::NamedColor::DimRed => style.dim_red,
// alacritty_terminal::ansi::NamedColor::DimGreen => style.dim_green,
// alacritty_terminal::ansi::NamedColor::DimYellow => style.dim_yellow,
// alacritty_terminal::ansi::NamedColor::DimBlue => style.dim_blue,
// alacritty_terminal::ansi::NamedColor::DimMagenta => style.dim_magenta,
// alacritty_terminal::ansi::NamedColor::DimCyan => style.dim_cyan,
// alacritty_terminal::ansi::NamedColor::DimWhite => style.dim_white,
// alacritty_terminal::ansi::NamedColor::BrightForeground => style.bright_foreground,
// alacritty_terminal::ansi::NamedColor::DimForeground => style.dim_foreground,
// },
// //'True' colors
// alacritty_terminal::ansi::Color::Spec(rgb) => Color::new(rgb.r, rgb.g, rgb.b, u8::MAX),
// //8 bit, indexed colors
// alacritty_terminal::ansi::Color::Indexed(i) => get_color_at_index(&(*i as usize), style),
// }
// }
/// TODO: Move this
///Converts an 8 bit ANSI color to it's GPUI equivalent.
///Accepts usize for compatibility with the alacritty::Colors interface,
///Other than that use case, should only be called with values in the [0,255] range
// pub fn get_color_at_index(index: &usize, style: &TerminalStyle) -> Color {
// match index {
// //0-15 are the same as the named colors above
// 0 => style.black,
// 1 => style.red,
// 2 => style.green,
// 3 => style.yellow,
// 4 => style.blue,
// 5 => style.magenta,
// 6 => style.cyan,
// 7 => style.white,
// 8 => style.bright_black,
// 9 => style.bright_red,
// 10 => style.bright_green,
// 11 => style.bright_yellow,
// 12 => style.bright_blue,
// 13 => style.bright_magenta,
// 14 => style.bright_cyan,
// 15 => style.bright_white,
// //16-231 are mapped to their RGB colors on a 0-5 range per channel
// 16..=231 => {
// let (r, g, b) = rgb_for_index(&(*index as u8)); //Split the index into it's ANSI-RGB components
// let step = (u8::MAX as f32 / 5.).floor() as u8; //Split the RGB range into 5 chunks, with floor so no overflow
// Color::new(r * step, g * step, b * step, u8::MAX) //Map the ANSI-RGB components to an RGB color
// }
// //232-255 are a 24 step grayscale from black to white
// 232..=255 => {
// let i = *index as u8 - 232; //Align index to 0..24
// let step = (u8::MAX as f32 / 24.).floor() as u8; //Split the RGB grayscale values into 24 chunks
// Color::new(i * step, i * step, i * step, u8::MAX) //Map the ANSI-grayscale components to the RGB-grayscale
// }
// //For compatibility with the alacritty::Colors interface
// 256 => style.foreground,
// 257 => style.background,
// 258 => style.cursor,
// 259 => style.dim_black,
// 260 => style.dim_red,
// 261 => style.dim_green,
// 262 => style.dim_yellow,
// 263 => style.dim_blue,
// 264 => style.dim_magenta,
// 265 => style.dim_cyan,
// 266 => style.dim_white,
// 267 => style.bright_foreground,
// 268 => style.black, //'Dim Background', non-standard color
// _ => Color::new(0, 0, 0, 255),
// }
// }
///Generates the rgb channels in [0, 5] for a given index into the 6x6x6 ANSI color cube
///See: [8 bit ansi color](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit).
///
///Wikipedia gives a formula for calculating the index for a given color:
///
///index = 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5)
///
///This function does the reverse, calculating the r, g, and b components from a given index.
// fn rgb_for_index(i: &u8) -> (u8, u8, u8) {
// debug_assert!((&16..=&231).contains(&i));
// let i = i - 16;
// let r = (i - (i % 36)) / 36;
// let g = ((i % 36) - (i % 6)) / 6;
// let b = (i % 36) % 6;
// (r, g, b)
// }
use gpui::Rgba; use gpui::Rgba;
//Convenience method to convert from a GPUI color to an alacritty Rgb //Convenience method to convert from a GPUI color to an alacritty Rgb
@ -123,15 +10,3 @@ pub fn to_alac_rgb(color: impl Into<Rgba>) -> AlacRgb {
let b = ((color.b * color.a) * 255.) as u8; let b = ((color.b * color.a) * 255.) as u8;
AlacRgb::new(r, g, b) AlacRgb::new(r, g, b)
} }
// #[cfg(test)]
// mod tests {
// #[test]
// fn test_rgb_for_index() {
// //Test every possible value in the color cube
// for i in 16..=231 {
// let (r, g, b) = crate::mappings::colors::rgb_for_index(&(i as u8));
// assert_eq!(i, 16 + 36 * r + 6 * g + b);
// }
// }
// }

View File

@ -976,6 +976,7 @@ impl Terminal {
} }
pub fn try_sync(&mut self, cx: &mut ModelContext<Self>) { pub fn try_sync(&mut self, cx: &mut ModelContext<Self>) {
println!("trying to sync");
let term = self.term.clone(); let term = self.term.clone();
let mut terminal = if let Some(term) = term.try_lock_unfair() { let mut terminal = if let Some(term) = term.try_lock_unfair() {

View File

@ -1,18 +1,17 @@
use editor::{Cursor, HighlightedRange, HighlightedRangeLine}; use editor::{Cursor, HighlightedRange, HighlightedRangeLine};
use gpui::{ use gpui::{
point, px, relative, rems, transparent_black, AnyElement, AppContext, Bounds, Component, black, point, px, red, relative, transparent_black, AnyElement, Bounds, Element, ElementId,
CursorStyle, Element, ElementId, FontStyle, FontWeight, HighlightStyle, Hsla, IntoElement, Font, FontStyle, FontWeight, HighlightStyle, Hsla, IntoElement, LayoutId, Pixels, Point, Rgba,
IsZero, LayoutId, ModelContext, Overlay, Pixels, Point, Quad, ShapedLine, SharedString, Style, ShapedLine, Style, TextRun, TextStyle, TextSystem, UnderlineStyle, ViewContext, WeakModel,
Styled, TextRun, TextStyle, TextSystem, Underline, UnderlineStyle, ViewContext, WeakModel,
WhiteSpace, WindowContext, WhiteSpace, WindowContext,
}; };
use itertools::Itertools; use itertools::Itertools;
use language::CursorShape; use language::CursorShape;
use ordered_float::OrderedFloat;
use settings::Settings; use settings::Settings;
use terminal::{ use terminal::{
alacritty_terminal::ansi::NamedColor,
alacritty_terminal::{ alacritty_terminal::{
ansi::{Color as AnsiColor, Color::Named, CursorShape as AlacCursorShape, NamedColor}, ansi::{Color as AnsiColor, Color::Named, CursorShape as AlacCursorShape},
grid::Dimensions, grid::Dimensions,
index::Point as AlacPoint, index::Point as AlacPoint,
term::{cell::Flags, TermMode}, term::{cell::Flags, TermMode},
@ -20,7 +19,7 @@ use terminal::{
terminal_settings::TerminalSettings, terminal_settings::TerminalSettings,
IndexedCell, Terminal, TerminalContent, TerminalSize, IndexedCell, Terminal, TerminalContent, TerminalSize,
}; };
use theme::{ActiveTheme, ThemeColors, ThemeSettings}; use theme::{ActiveTheme, Theme, ThemeSettings};
use std::mem; use std::mem;
use std::{fmt::Debug, ops::RangeInclusive}; use std::{fmt::Debug, ops::RangeInclusive};
@ -80,7 +79,6 @@ impl LayoutCell {
origin: Point<Pixels>, origin: Point<Pixels>,
layout: &LayoutState, layout: &LayoutState,
_visible_bounds: Bounds<Pixels>, _visible_bounds: Bounds<Pixels>,
_view: &mut TerminalView,
cx: &mut WindowContext, cx: &mut WindowContext,
) { ) {
let pos = { let pos = {
@ -92,7 +90,7 @@ impl LayoutCell {
) )
}; };
self.text.paint(pos, layout.size.line_height, cx); self.text.paint(pos, layout.size.line_height, cx).ok();
} }
} }
@ -120,13 +118,7 @@ impl LayoutRect {
} }
} }
fn paint( fn paint(&self, origin: Point<Pixels>, layout: &LayoutState, cx: &mut WindowContext) {
&self,
origin: Point<Pixels>,
layout: &LayoutState,
_view: &mut TerminalView,
cx: &mut ViewContext<TerminalView>,
) {
let position = { let position = {
let alac_point = self.point; let alac_point = self.point;
point( point(
@ -184,7 +176,7 @@ impl TerminalElement {
hyperlink: Option<(HighlightStyle, &RangeInclusive<AlacPoint>)>, hyperlink: Option<(HighlightStyle, &RangeInclusive<AlacPoint>)>,
cx: &WindowContext<'_>, cx: &WindowContext<'_>,
) -> (Vec<LayoutCell>, Vec<LayoutRect>) { ) -> (Vec<LayoutCell>, Vec<LayoutRect>) {
let theme_colors = cx.theme().colors(); let theme = cx.theme();
let mut cells = vec![]; let mut cells = vec![];
let mut rects = vec![]; let mut rects = vec![];
@ -225,7 +217,7 @@ impl TerminalElement {
cell.point.column.0 as i32, cell.point.column.0 as i32,
), ),
1, 1,
convert_color(&bg, theme_colors), convert_color(&bg, theme),
)); ));
} }
} }
@ -234,7 +226,7 @@ impl TerminalElement {
cur_rect = Some(LayoutRect::new( cur_rect = Some(LayoutRect::new(
AlacPoint::new(line_index as i32, cell.point.column.0 as i32), AlacPoint::new(line_index as i32, cell.point.column.0 as i32),
1, 1,
convert_color(&bg, &theme_colors), convert_color(&bg, &theme),
)); ));
} }
} }
@ -249,7 +241,7 @@ impl TerminalElement {
&cell, &cell,
fg, fg,
bg, bg,
theme_colors, theme,
text_style, text_style,
text_system, text_system,
hyperlink, hyperlink,
@ -312,7 +304,7 @@ impl TerminalElement {
indexed: &IndexedCell, indexed: &IndexedCell,
fg: terminal::alacritty_terminal::ansi::Color, fg: terminal::alacritty_terminal::ansi::Color,
bg: terminal::alacritty_terminal::ansi::Color, bg: terminal::alacritty_terminal::ansi::Color,
colors: &ThemeColors, colors: &Theme,
text_style: &TextStyle, text_style: &TextStyle,
text_system: &TextSystem, text_system: &TextSystem,
hyperlink: Option<(HighlightStyle, &RangeInclusive<AlacPoint>)>, hyperlink: Option<(HighlightStyle, &RangeInclusive<AlacPoint>)>,
@ -321,7 +313,7 @@ impl TerminalElement {
let fg = convert_color(&fg, &colors); let fg = convert_color(&fg, &colors);
let bg = convert_color(&bg, &colors); let bg = convert_color(&bg, &colors);
let mut underline = (flags.intersects(Flags::ALL_UNDERLINES) let underline = (flags.intersects(Flags::ALL_UNDERLINES)
|| indexed.cell.hyperlink().is_some()) || indexed.cell.hyperlink().is_some())
.then(|| UnderlineStyle { .then(|| UnderlineStyle {
color: Some(fg), color: Some(fg),
@ -329,20 +321,27 @@ impl TerminalElement {
wavy: flags.contains(Flags::UNDERCURL), wavy: flags.contains(Flags::UNDERCURL),
}); });
//todo!(support bold and italic) let weight = if flags.intersects(Flags::BOLD | Flags::DIM_BOLD) {
// let mut properties = Properties::new(); FontWeight::BOLD
// if indexed.flags.intersects(Flags::BOLD | Flags::DIM_BOLD) { } else {
// properties = *properties.weight(FontWeight::BOLD); FontWeight::NORMAL
// } };
// if indexed.flags.intersects(Flags::ITALIC) {
// properties = *properties.style(FontStyle::Italic); let style = if flags.intersects(Flags::ITALIC) {
// } FontStyle::Italic
} else {
FontStyle::Normal
};
let mut result = TextRun { let mut result = TextRun {
len: indexed.c.len_utf8() as usize, len: indexed.c.len_utf8() as usize,
color: fg, color: fg,
background_color: Some(bg), background_color: Some(bg),
font: text_style.font(), font: Font {
weight,
style,
..text_style.font()
},
underline, underline,
}; };
@ -498,7 +497,6 @@ impl TerminalElement {
let (cells, rects) = TerminalElement::layout_grid( let (cells, rects) = TerminalElement::layout_grid(
cells, cells,
&text_style, &text_style,
// &terminal_theme,
&cx.text_system(), &cx.text_system(),
// todo!(Terminal tooltips) // todo!(Terminal tooltips)
last_hovered_word, last_hovered_word,
@ -752,84 +750,54 @@ impl Element for TerminalElement {
fn paint(self, bounds: Bounds<Pixels>, _: &mut Self::State, cx: &mut WindowContext<'_>) { fn paint(self, bounds: Bounds<Pixels>, _: &mut Self::State, cx: &mut WindowContext<'_>) {
let layout = self.compute_layout(bounds, cx); let layout = self.compute_layout(bounds, cx);
// todo!()
// let visible_bounds = bounds.intersection(visible_bounds).unwrap_or_default();
// //Setup element stuff let theme = cx.theme();
// let clip_bounds = Some(visible_bounds); cx.paint_quad(
bounds,
Default::default(),
theme.colors().editor_background,
Default::default(),
Hsla::default(),
);
let origin = bounds.origin + Point::new(layout.gutter, px(0.));
// cx.paint_layer(clip_bounds, |cx| { for rect in &layout.rects {
// let origin = bounds.origin + point(element_state.gutter, 0.); rect.paint(origin, &layout, cx);
}
// // Elements are ephemeral, only at paint time do we know what could be clicked by a mouse cx.with_z_index(1, |cx| {
// self.attach_mouse_handlers(origin, visible_bounds, element_state.mode, cx); for (relative_highlighted_range, color) in layout.relative_highlighted_ranges.iter() {
if let Some((start_y, highlighted_range_lines)) =
to_highlighted_range_lines(relative_highlighted_range, &layout, origin)
{
let hr = HighlightedRange {
start_y, //Need to change this
line_height: layout.size.line_height,
lines: highlighted_range_lines,
color: color.clone(),
//Copied from editor. TODO: move to theme or something
corner_radius: 0.15 * layout.size.line_height,
};
hr.paint(bounds, cx);
}
}
});
// cx.scene().push_cursor_region(gpui::CursorRegion { cx.with_z_index(2, |cx| {
// bounds, for cell in &layout.cells {
// style: if element_state.hyperlink_tooltip.is_some() { cell.paint(origin, &layout, bounds, cx);
// CursorStyle::AlacPointingHand }
// } else { });
// CursorStyle::IBeam
// },
// });
// cx.paint_layer(clip_bounds, |cx| { cx.with_z_index(3, |cx| {
// //Start with a background color if let Some(cursor) = &layout.cursor {
// cx.scene().push_quad(Quad { cursor.paint(origin, cx);
// bounds, }
// background: Some(element_state.background_color), });
// border: Default::default(),
// corner_radii: Default::default(),
// });
// for rect in &element_state.rects {
// rect.paint(origin, element_state, view_state, cx);
// }
// });
// //Draw Highlighted Backgrounds
// cx.paint_layer(clip_bounds, |cx| {
// for (relative_highlighted_range, color) in
// element_state.relative_highlighted_ranges.iter()
// {
// if let Some((start_y, highlighted_range_lines)) = to_highlighted_range_lines(
// relative_highlighted_range,
// element_state,
// origin,
// ) {
// let hr = HighlightedRange {
// start_y, //Need to change this
// line_height: element_state.size.line_height,
// lines: highlighted_range_lines,
// color: color.clone(),
// //Copied from editor. TODO: move to theme or something
// corner_radius: 0.15 * element_state.size.line_height,
// };
// hr.paint(bounds, cx);
// }
// }
// });
// //Draw the text cells
// cx.paint_layer(clip_bounds, |cx| {
// for cell in &element_state.cells {
// cell.paint(origin, element_state, visible_bounds, view_state, cx);
// }
// });
// //Draw cursor
// if self.cursor_visible {
// if let Some(cursor) = &element_state.cursor {
// cx.paint_layer(clip_bounds, |cx| {
// cursor.paint(origin, cx);
// })
// }
// }
// if let Some(element) = &mut element_state.hyperlink_tooltip { // if let Some(element) = &mut element_state.hyperlink_tooltip {
// element.paint(origin, visible_bounds, view_state, cx) // element.paint(origin, visible_bounds, view_state, cx)
// } // }
// });
} }
// todo!() remove? // todo!() remove?
@ -877,7 +845,7 @@ impl IntoElement for TerminalElement {
type Element = Self; type Element = Self;
fn element_id(&self) -> Option<ElementId> { fn element_id(&self) -> Option<ElementId> {
todo!() Some("terminal".into())
} }
fn into_element(self) -> Self::Element { fn into_element(self) -> Self::Element {
@ -971,7 +939,147 @@ fn to_highlighted_range_lines(
Some((start_y, highlighted_range_lines)) Some((start_y, highlighted_range_lines))
} }
// mappings::colors::convert_color ///Converts a 2, 8, or 24 bit color ANSI color to the GPUI equivalent
fn convert_color(fg: &terminal::alacritty_terminal::ansi::Color, colors: &ThemeColors) -> Hsla { fn convert_color(fg: &terminal::alacritty_terminal::ansi::Color, theme: &Theme) -> Hsla {
todo!() let colors = theme.colors();
match fg {
//Named and theme defined colors
terminal::alacritty_terminal::ansi::Color::Named(n) => match n {
NamedColor::Black => colors.terminal_ansi_black,
NamedColor::Red => colors.terminal_ansi_red,
NamedColor::Green => colors.terminal_ansi_green,
NamedColor::Yellow => colors.terminal_ansi_yellow,
NamedColor::Blue => colors.terminal_ansi_blue,
NamedColor::Magenta => colors.terminal_ansi_magenta,
NamedColor::Cyan => colors.terminal_ansi_cyan,
NamedColor::White => colors.terminal_ansi_white,
NamedColor::BrightBlack => colors.terminal_ansi_bright_black,
NamedColor::BrightRed => colors.terminal_ansi_bright_red,
NamedColor::BrightGreen => colors.terminal_ansi_bright_green,
NamedColor::BrightYellow => colors.terminal_ansi_bright_yellow,
NamedColor::BrightBlue => colors.terminal_ansi_bright_blue,
NamedColor::BrightMagenta => colors.terminal_ansi_bright_magenta,
NamedColor::BrightCyan => colors.terminal_ansi_bright_cyan,
NamedColor::BrightWhite => colors.terminal_ansi_bright_white,
NamedColor::Foreground => colors.text,
NamedColor::Background => colors.background,
NamedColor::Cursor => theme.players().local().cursor,
// todo!(more colors)
NamedColor::DimBlack => red(),
NamedColor::DimRed => red(),
NamedColor::DimGreen => red(),
NamedColor::DimYellow => red(),
NamedColor::DimBlue => red(),
NamedColor::DimMagenta => red(),
NamedColor::DimCyan => red(),
NamedColor::DimWhite => red(),
NamedColor::BrightForeground => red(),
NamedColor::DimForeground => red(),
},
//'True' colors
terminal::alacritty_terminal::ansi::Color::Spec(rgb) => rgba_color(rgb.r, rgb.g, rgb.b),
//8 bit, indexed colors
terminal::alacritty_terminal::ansi::Color::Indexed(i) => {
get_color_at_index(&(*i as usize), theme)
}
}
}
///Converts an 8 bit ANSI color to it's GPUI equivalent.
///Accepts usize for compatibility with the alacritty::Colors interface,
///Other than that use case, should only be called with values in the [0,255] range
pub fn get_color_at_index(index: &usize, theme: &Theme) -> Hsla {
let colors = theme.colors();
match index {
//0-15 are the same as the named colors above
0 => colors.terminal_ansi_black,
1 => colors.terminal_ansi_red,
2 => colors.terminal_ansi_green,
3 => colors.terminal_ansi_yellow,
4 => colors.terminal_ansi_blue,
5 => colors.terminal_ansi_magenta,
6 => colors.terminal_ansi_cyan,
7 => colors.terminal_ansi_white,
8 => colors.terminal_ansi_bright_black,
9 => colors.terminal_ansi_bright_red,
10 => colors.terminal_ansi_bright_green,
11 => colors.terminal_ansi_bright_yellow,
12 => colors.terminal_ansi_bright_blue,
13 => colors.terminal_ansi_bright_magenta,
14 => colors.terminal_ansi_bright_cyan,
15 => colors.terminal_ansi_bright_white,
//16-231 are mapped to their RGB colors on a 0-5 range per channel
16..=231 => {
let (r, g, b) = rgb_for_index(&(*index as u8)); //Split the index into it's ANSI-RGB components
let step = (u8::MAX as f32 / 5.).floor() as u8; //Split the RGB range into 5 chunks, with floor so no overflow
rgba_color(r * step, g * step, b * step) //Map the ANSI-RGB components to an RGB color
}
//232-255 are a 24 step grayscale from black to white
232..=255 => {
let i = *index as u8 - 232; //Align index to 0..24
let step = (u8::MAX as f32 / 24.).floor() as u8; //Split the RGB grayscale values into 24 chunks
rgba_color(i * step, i * step, i * step) //Map the ANSI-grayscale components to the RGB-grayscale
}
//For compatibility with the alacritty::Colors interface
256 => colors.text,
257 => colors.background,
258 => theme.players().local().cursor,
// todo!(more colors)
259 => red(), //style.dim_black,
260 => red(), //style.dim_red,
261 => red(), //style.dim_green,
262 => red(), //style.dim_yellow,
263 => red(), //style.dim_blue,
264 => red(), //style.dim_magenta,
265 => red(), //style.dim_cyan,
266 => red(), //style.dim_white,
267 => red(), //style.bright_foreground,
268 => colors.terminal_ansi_black, //'Dim Background', non-standard color
_ => black(),
}
}
///Generates the rgb channels in [0, 5] for a given index into the 6x6x6 ANSI color cube
///See: [8 bit ansi color](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit).
///
///Wikipedia gives a formula for calculating the index for a given color:
///
///index = 16 + 36 × r + 6 × g + b (0 ≤ r, g, b ≤ 5)
///
///This function does the reverse, calculating the r, g, and b components from a given index.
fn rgb_for_index(i: &u8) -> (u8, u8, u8) {
debug_assert!((&16..=&231).contains(&i));
let i = i - 16;
let r = (i - (i % 36)) / 36;
let g = ((i % 36) - (i % 6)) / 6;
let b = (i % 36) % 6;
(r, g, b)
}
fn rgba_color(r: u8, g: u8, b: u8) -> Hsla {
Rgba {
r: (r as f32 / 255.) as f32,
g: (g as f32 / 255.) as f32,
b: (b as f32 / 255.) as f32,
a: 1.,
}
.into()
}
#[cfg(test)]
mod tests {
use crate::terminal_element::rgb_for_index;
#[test]
fn test_rgb_for_index() {
//Test every possible value in the color cube
for i in 16..=231 {
let (r, g, b) = rgb_for_index(&(i as u8));
assert_eq!(i, 16 + 36 * r + 6 * g + b);
}
}
} }

View File

@ -25,6 +25,7 @@ use terminal::{
terminal_settings::{TerminalBlink, TerminalSettings, WorkingDirectory}, terminal_settings::{TerminalBlink, TerminalSettings, WorkingDirectory},
Event, MaybeNavigationTarget, Terminal, Event, MaybeNavigationTarget, Terminal,
}; };
use terminal_element::TerminalElement;
use util::{paths::PathLikeWithPosition, ResultExt}; use util::{paths::PathLikeWithPosition, ResultExt};
use workspace::{ use workspace::{
item::{BreadcrumbText, Item, ItemEvent}, item::{BreadcrumbText, Item, ItemEvent},
@ -305,7 +306,6 @@ impl TerminalView {
cx, cx,
) )
})); }));
dbg!(&position);
// todo!() // todo!()
// self.context_menu // self.context_menu
// .show(position, AnchorCorner::TopLeft, menu_entries, cx); // .show(position, AnchorCorner::TopLeft, menu_entries, cx);
@ -541,11 +541,13 @@ impl Render for TerminalView {
let focused = self.focus_handle.is_focused(cx); let focused = self.focus_handle.is_focused(cx);
div() div()
.size_full()
.relative() .relative()
.child( .child(
div() div()
.z_index(0) .z_index(0)
.absolute() .absolute()
.size_full()
.on_key_down(cx.listener(Self::key_down)) .on_key_down(cx.listener(Self::key_down))
.on_action(cx.listener(TerminalView::send_text)) .on_action(cx.listener(TerminalView::send_text))
.on_action(cx.listener(TerminalView::send_keystroke)) .on_action(cx.listener(TerminalView::send_keystroke))
@ -554,15 +556,12 @@ impl Render for TerminalView {
.on_action(cx.listener(TerminalView::clear)) .on_action(cx.listener(TerminalView::clear))
.on_action(cx.listener(TerminalView::show_character_palette)) .on_action(cx.listener(TerminalView::show_character_palette))
.on_action(cx.listener(TerminalView::select_all)) .on_action(cx.listener(TerminalView::select_all))
// todo!() .child(TerminalElement::new(
.child( terminal_handle,
"TERMINAL HERE", // TerminalElement::new( focused,
// terminal_handle, self.should_show_cursor(focused, cx),
// focused, self.can_navigate_to_selected_word,
// self.should_show_cursor(focused, cx), ))
// self.can_navigate_to_selected_word,
// )
)
.on_mouse_down( .on_mouse_down(
MouseButton::Right, MouseButton::Right,
cx.listener(|this, event: &MouseDownEvent, cx| { cx.listener(|this, event: &MouseDownEvent, cx| {