Add more terminal colors to the theme (#4168)

This PR adds more terminal colors that were present in the Zed1 themes
to the Zed2 theme.

Namely, we now have the `dim_` variants for the various ANSI colors and
various `foreground` colors.

Release Notes:

- Improved terminal colors.
This commit is contained in:
Marshall Bowers 2024-01-19 14:22:53 -05:00 committed by GitHub
parent 1cc7f66f86
commit df2b0f6d2e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 926 additions and 419 deletions

View file

@ -52,9 +52,9 @@ use std::{
use thiserror::Error;
use gpui::{
actions, black, px, red, AnyWindowHandle, AppContext, Bounds, ClipboardItem, EventEmitter,
Hsla, Keystroke, ModelContext, Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent,
MouseUpEvent, Pixels, Point, Rgba, ScrollWheelEvent, Size, Task, TouchPhase,
actions, black, px, AnyWindowHandle, AppContext, Bounds, ClipboardItem, EventEmitter, Hsla,
Keystroke, ModelContext, Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent,
Pixels, Point, Rgba, ScrollWheelEvent, Size, Task, TouchPhase,
};
use crate::mappings::{colors::to_alac_rgb, keys::to_esc_str};
@ -1380,7 +1380,7 @@ 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-15 are the same as the named colors above
0 => colors.terminal_ansi_black,
1 => colors.terminal_ansi_red,
2 => colors.terminal_ansi_green,
@ -1397,34 +1397,32 @@ pub fn get_color_at_index(index: usize, theme: &Theme) -> Hsla {
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 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
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 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
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
// 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
259 => colors.terminal_ansi_dim_black,
260 => colors.terminal_ansi_dim_red,
261 => colors.terminal_ansi_dim_green,
262 => colors.terminal_ansi_dim_yellow,
263 => colors.terminal_ansi_dim_blue,
264 => colors.terminal_ansi_dim_magenta,
265 => colors.terminal_ansi_dim_cyan,
266 => colors.terminal_ansi_dim_white,
267 => colors.terminal_bright_foreground,
268 => colors.terminal_ansi_black, // 'Dim Background', non-standard color
_ => black(),
}