Rework theme2 with new theme structure (#3194)

This PR reworks the theme definition in the `theme2` crate to be based
off of the new theme work that @iamnbutler has been working on.

We're still developing the new theme system, but it is complete enough
that we can now load the default theme and use it to theme the storybook
(albeit with some further refining of the color palette required).

---------

Co-authored-by: Nate Butler <iamnbutler@gmail.com>
Co-authored-by: Marshall Bowers <marshall@zed.dev>
This commit is contained in:
Marshall Bowers 2023-11-01 03:23:00 +01:00 committed by GitHub
parent ed5f1d3bdd
commit 18431051d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
51 changed files with 1615 additions and 494 deletions

View file

@ -1,12 +1,12 @@
use std::path::PathBuf;
use std::str::FromStr;
use gpui2::ViewContext;
use gpui2::{AppContext, ViewContext};
use rand::Rng;
use theme2::Theme;
use theme2::ActiveTheme;
use crate::{
theme, Buffer, BufferRow, BufferRows, Button, EditorPane, FileSystemStatus, GitStatus,
Buffer, BufferRow, BufferRows, Button, EditorPane, FileSystemStatus, GitStatus,
HighlightedLine, Icon, Keybinding, Label, LabelColor, ListEntry, ListEntrySize, ListItem,
Livestream, MicStatus, ModifierKeys, PaletteItem, Player, PlayerCallStatus,
PlayerWithCallStatus, ScreenShareStatus, Symbol, Tab, ToggleState, VideoStatus,
@ -643,8 +643,6 @@ pub fn empty_buffer_example() -> Buffer {
}
pub fn hello_world_rust_editor_example(cx: &mut ViewContext<EditorPane>) -> EditorPane {
let theme = theme(cx);
EditorPane::new(
cx,
static_tabs_example(),
@ -652,29 +650,29 @@ pub fn hello_world_rust_editor_example(cx: &mut ViewContext<EditorPane>) -> Edit
vec![Symbol(vec![
HighlightedText {
text: "fn ".to_string(),
color: theme.syntax.color("keyword"),
color: cx.theme().syntax_color("keyword"),
},
HighlightedText {
text: "main".to_string(),
color: theme.syntax.color("function"),
color: cx.theme().syntax_color("function"),
},
])],
hello_world_rust_buffer_example(&theme),
hello_world_rust_buffer_example(cx),
)
}
pub fn hello_world_rust_buffer_example(theme: &Theme) -> Buffer {
pub fn hello_world_rust_buffer_example(cx: &AppContext) -> Buffer {
Buffer::new("hello-world-rust-buffer")
.set_title("hello_world.rs".to_string())
.set_path("src/hello_world.rs".to_string())
.set_language("rust".to_string())
.set_rows(Some(BufferRows {
show_line_numbers: true,
rows: hello_world_rust_buffer_rows(theme),
rows: hello_world_rust_buffer_rows(cx),
}))
}
pub fn hello_world_rust_buffer_rows(theme: &Theme) -> Vec<BufferRow> {
pub fn hello_world_rust_buffer_rows(cx: &AppContext) -> Vec<BufferRow> {
let show_line_number = true;
vec![
@ -686,15 +684,15 @@ pub fn hello_world_rust_buffer_rows(theme: &Theme) -> Vec<BufferRow> {
highlighted_texts: vec![
HighlightedText {
text: "fn ".to_string(),
color: theme.syntax.color("keyword"),
color: cx.theme().syntax_color("keyword"),
},
HighlightedText {
text: "main".to_string(),
color: theme.syntax.color("function"),
color: cx.theme().syntax_color("function"),
},
HighlightedText {
text: "() {".to_string(),
color: theme.text,
color: cx.theme().colors().text,
},
],
}),
@ -710,7 +708,7 @@ pub fn hello_world_rust_buffer_rows(theme: &Theme) -> Vec<BufferRow> {
highlighted_texts: vec![HighlightedText {
text: " // Statements here are executed when the compiled binary is called."
.to_string(),
color: theme.syntax.color("comment"),
color: cx.theme().syntax_color("comment"),
}],
}),
cursors: None,
@ -733,7 +731,7 @@ pub fn hello_world_rust_buffer_rows(theme: &Theme) -> Vec<BufferRow> {
line: Some(HighlightedLine {
highlighted_texts: vec![HighlightedText {
text: " // Print text to the console.".to_string(),
color: theme.syntax.color("comment"),
color: cx.theme().syntax_color("comment"),
}],
}),
cursors: None,
@ -748,15 +746,15 @@ pub fn hello_world_rust_buffer_rows(theme: &Theme) -> Vec<BufferRow> {
highlighted_texts: vec![
HighlightedText {
text: " println!(".to_string(),
color: theme.text,
color: cx.theme().colors().text,
},
HighlightedText {
text: "\"Hello, world!\"".to_string(),
color: theme.syntax.color("string"),
color: cx.theme().syntax_color("string"),
},
HighlightedText {
text: ");".to_string(),
color: theme.text,
color: cx.theme().colors().text,
},
],
}),
@ -771,7 +769,7 @@ pub fn hello_world_rust_buffer_rows(theme: &Theme) -> Vec<BufferRow> {
line: Some(HighlightedLine {
highlighted_texts: vec![HighlightedText {
text: "}".to_string(),
color: theme.text,
color: cx.theme().colors().text,
}],
}),
cursors: None,
@ -782,8 +780,6 @@ pub fn hello_world_rust_buffer_rows(theme: &Theme) -> Vec<BufferRow> {
}
pub fn hello_world_rust_editor_with_status_example(cx: &mut ViewContext<EditorPane>) -> EditorPane {
let theme = theme(cx);
EditorPane::new(
cx,
static_tabs_example(),
@ -791,29 +787,29 @@ pub fn hello_world_rust_editor_with_status_example(cx: &mut ViewContext<EditorPa
vec![Symbol(vec![
HighlightedText {
text: "fn ".to_string(),
color: theme.syntax.color("keyword"),
color: cx.theme().syntax_color("keyword"),
},
HighlightedText {
text: "main".to_string(),
color: theme.syntax.color("function"),
color: cx.theme().syntax_color("function"),
},
])],
hello_world_rust_buffer_with_status_example(&theme),
hello_world_rust_buffer_with_status_example(cx),
)
}
pub fn hello_world_rust_buffer_with_status_example(theme: &Theme) -> Buffer {
pub fn hello_world_rust_buffer_with_status_example(cx: &AppContext) -> Buffer {
Buffer::new("hello-world-rust-buffer-with-status")
.set_title("hello_world.rs".to_string())
.set_path("src/hello_world.rs".to_string())
.set_language("rust".to_string())
.set_rows(Some(BufferRows {
show_line_numbers: true,
rows: hello_world_rust_with_status_buffer_rows(theme),
rows: hello_world_rust_with_status_buffer_rows(cx),
}))
}
pub fn hello_world_rust_with_status_buffer_rows(theme: &Theme) -> Vec<BufferRow> {
pub fn hello_world_rust_with_status_buffer_rows(cx: &AppContext) -> Vec<BufferRow> {
let show_line_number = true;
vec![
@ -825,15 +821,15 @@ pub fn hello_world_rust_with_status_buffer_rows(theme: &Theme) -> Vec<BufferRow>
highlighted_texts: vec![
HighlightedText {
text: "fn ".to_string(),
color: theme.syntax.color("keyword"),
color: cx.theme().syntax_color("keyword"),
},
HighlightedText {
text: "main".to_string(),
color: theme.syntax.color("function"),
color: cx.theme().syntax_color("function"),
},
HighlightedText {
text: "() {".to_string(),
color: theme.text,
color: cx.theme().colors().text,
},
],
}),
@ -849,7 +845,7 @@ pub fn hello_world_rust_with_status_buffer_rows(theme: &Theme) -> Vec<BufferRow>
highlighted_texts: vec![HighlightedText {
text: "// Statements here are executed when the compiled binary is called."
.to_string(),
color: theme.syntax.color("comment"),
color: cx.theme().syntax_color("comment"),
}],
}),
cursors: None,
@ -872,7 +868,7 @@ pub fn hello_world_rust_with_status_buffer_rows(theme: &Theme) -> Vec<BufferRow>
line: Some(HighlightedLine {
highlighted_texts: vec![HighlightedText {
text: " // Print text to the console.".to_string(),
color: theme.syntax.color("comment"),
color: cx.theme().syntax_color("comment"),
}],
}),
cursors: None,
@ -887,15 +883,15 @@ pub fn hello_world_rust_with_status_buffer_rows(theme: &Theme) -> Vec<BufferRow>
highlighted_texts: vec![
HighlightedText {
text: " println!(".to_string(),
color: theme.text,
color: cx.theme().colors().text,
},
HighlightedText {
text: "\"Hello, world!\"".to_string(),
color: theme.syntax.color("string"),
color: cx.theme().syntax_color("string"),
},
HighlightedText {
text: ");".to_string(),
color: theme.text,
color: cx.theme().colors().text,
},
],
}),
@ -910,7 +906,7 @@ pub fn hello_world_rust_with_status_buffer_rows(theme: &Theme) -> Vec<BufferRow>
line: Some(HighlightedLine {
highlighted_texts: vec![HighlightedText {
text: "}".to_string(),
color: theme.text,
color: cx.theme().colors().text,
}],
}),
cursors: None,
@ -924,7 +920,7 @@ pub fn hello_world_rust_with_status_buffer_rows(theme: &Theme) -> Vec<BufferRow>
line: Some(HighlightedLine {
highlighted_texts: vec![HighlightedText {
text: "".to_string(),
color: theme.text,
color: cx.theme().colors().text,
}],
}),
cursors: None,
@ -938,7 +934,7 @@ pub fn hello_world_rust_with_status_buffer_rows(theme: &Theme) -> Vec<BufferRow>
line: Some(HighlightedLine {
highlighted_texts: vec![HighlightedText {
text: "// Marshall and Nate were here".to_string(),
color: theme.syntax.color("comment"),
color: cx.theme().syntax_color("comment"),
}],
}),
cursors: None,
@ -948,16 +944,16 @@ pub fn hello_world_rust_with_status_buffer_rows(theme: &Theme) -> Vec<BufferRow>
]
}
pub fn terminal_buffer(theme: &Theme) -> Buffer {
pub fn terminal_buffer(cx: &AppContext) -> Buffer {
Buffer::new("terminal")
.set_title("zed — fish".to_string())
.set_rows(Some(BufferRows {
show_line_numbers: false,
rows: terminal_buffer_rows(theme),
rows: terminal_buffer_rows(cx),
}))
}
pub fn terminal_buffer_rows(theme: &Theme) -> Vec<BufferRow> {
pub fn terminal_buffer_rows(cx: &AppContext) -> Vec<BufferRow> {
let show_line_number = false;
vec![
@ -969,31 +965,31 @@ pub fn terminal_buffer_rows(theme: &Theme) -> Vec<BufferRow> {
highlighted_texts: vec![
HighlightedText {
text: "maxdeviant ".to_string(),
color: theme.syntax.color("keyword"),
color: cx.theme().syntax_color("keyword"),
},
HighlightedText {
text: "in ".to_string(),
color: theme.text,
color: cx.theme().colors().text,
},
HighlightedText {
text: "profaned-capital ".to_string(),
color: theme.syntax.color("function"),
color: cx.theme().syntax_color("function"),
},
HighlightedText {
text: "in ".to_string(),
color: theme.text,
color: cx.theme().colors().text,
},
HighlightedText {
text: "~/p/zed ".to_string(),
color: theme.syntax.color("function"),
color: cx.theme().syntax_color("function"),
},
HighlightedText {
text: "on ".to_string(),
color: theme.text,
color: cx.theme().colors().text,
},
HighlightedText {
text: " gpui2-ui ".to_string(),
color: theme.syntax.color("keyword"),
color: cx.theme().syntax_color("keyword"),
},
],
}),
@ -1008,7 +1004,7 @@ pub fn terminal_buffer_rows(theme: &Theme) -> Vec<BufferRow> {
line: Some(HighlightedLine {
highlighted_texts: vec![HighlightedText {
text: "λ ".to_string(),
color: theme.syntax.color("string"),
color: cx.theme().syntax_color("string"),
}],
}),
cursors: None,