mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-21 03:18:47 +03:00
Extract theme
into its own crate
This commit is contained in:
parent
0022c6b828
commit
2087c4731f
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -5259,6 +5259,21 @@ dependencies = [
|
|||||||
"unicode-width",
|
"unicode-width",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "theme"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"editor",
|
||||||
|
"gpui",
|
||||||
|
"indexmap",
|
||||||
|
"parking_lot",
|
||||||
|
"serde 1.0.125",
|
||||||
|
"serde_json 1.0.64",
|
||||||
|
"serde_path_to_error",
|
||||||
|
"toml 0.5.8",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "1.0.29"
|
version = "1.0.29"
|
||||||
@ -6097,6 +6112,7 @@ dependencies = [
|
|||||||
"sum_tree",
|
"sum_tree",
|
||||||
"surf",
|
"surf",
|
||||||
"tempdir",
|
"tempdir",
|
||||||
|
"theme",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"time 0.3.2",
|
"time 0.3.2",
|
||||||
"tiny_http",
|
"tiny_http",
|
||||||
|
15
crates/theme/Cargo.toml
Normal file
15
crates/theme/Cargo.toml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
[package]
|
||||||
|
name = "theme"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
editor = { path = "../editor" }
|
||||||
|
gpui = { path = "../gpui" }
|
||||||
|
anyhow = "1.0.38"
|
||||||
|
indexmap = "1.6.2"
|
||||||
|
parking_lot = "0.11.1"
|
||||||
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
serde_json = { version = "1.0.64", features = ["preserve_order"] }
|
||||||
|
serde_path_to_error = "0.1.4"
|
||||||
|
toml = "0.5"
|
@ -1,12 +1,10 @@
|
|||||||
use super::resolution::resolve_references;
|
use crate::{resolution::resolve_references, Theme};
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use gpui::{fonts, AssetSource, FontCache};
|
use gpui::{fonts, AssetSource, FontCache};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use serde_json::{Map, Value};
|
use serde_json::{Map, Value};
|
||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
use super::Theme;
|
|
||||||
|
|
||||||
pub struct ThemeRegistry {
|
pub struct ThemeRegistry {
|
||||||
assets: Box<dyn AssetSource>,
|
assets: Box<dyn AssetSource>,
|
||||||
themes: Mutex<HashMap<String, Arc<Theme>>>,
|
themes: Mutex<HashMap<String, Arc<Theme>>>,
|
||||||
@ -122,24 +120,9 @@ fn deep_merge_json(base: &mut Map<String, Value>, extension: Map<String, Value>)
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{test::test_app_state, theme::DEFAULT_THEME_NAME};
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use gpui::MutableAppContext;
|
use gpui::MutableAppContext;
|
||||||
|
|
||||||
#[gpui::test]
|
|
||||||
fn test_bundled_themes(cx: &mut MutableAppContext) {
|
|
||||||
let app_state = test_app_state(cx);
|
|
||||||
let mut has_default_theme = false;
|
|
||||||
for theme_name in app_state.themes.list() {
|
|
||||||
let theme = app_state.themes.get(&theme_name).unwrap();
|
|
||||||
if theme.name == DEFAULT_THEME_NAME {
|
|
||||||
has_default_theme = true;
|
|
||||||
}
|
|
||||||
assert_eq!(theme.name, theme_name);
|
|
||||||
}
|
|
||||||
assert!(has_default_theme);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
fn test_theme_extension(cx: &mut MutableAppContext) {
|
fn test_theme_extension(cx: &mut MutableAppContext) {
|
||||||
let assets = TestAssets(&[
|
let assets = TestAssets(&[
|
@ -34,8 +34,8 @@ gpui = { path = "../gpui" }
|
|||||||
project = { path = "../project" }
|
project = { path = "../project" }
|
||||||
rpc = { path = "../rpc" }
|
rpc = { path = "../rpc" }
|
||||||
sum_tree = { path = "../sum_tree" }
|
sum_tree = { path = "../sum_tree" }
|
||||||
|
theme = { path = "../theme" }
|
||||||
util = { path = "../util" }
|
util = { path = "../util" }
|
||||||
|
|
||||||
anyhow = "1.0.38"
|
anyhow = "1.0.38"
|
||||||
async-recursion = "0.3"
|
async-recursion = "0.3"
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
@ -83,7 +83,6 @@ project = { path = "../project", features = ["test-support"] }
|
|||||||
rpc = { path = "../rpc", features = ["test-support"] }
|
rpc = { path = "../rpc", features = ["test-support"] }
|
||||||
client = { path = "../client", features = ["test-support"] }
|
client = { path = "../client", features = ["test-support"] }
|
||||||
util = { path = "../util", features = ["test-support"] }
|
util = { path = "../util", features = ["test-support"] }
|
||||||
|
|
||||||
cargo-bundle = "0.5.0"
|
cargo-bundle = "0.5.0"
|
||||||
env_logger = "0.8"
|
env_logger = "0.8"
|
||||||
serde_json = { version = "1.0.64", features = ["preserve_order"] }
|
serde_json = { version = "1.0.64", features = ["preserve_order"] }
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::{theme, Settings};
|
use crate::Settings;
|
||||||
use client::{
|
use client::{
|
||||||
channel::{Channel, ChannelEvent, ChannelList, ChannelMessage},
|
channel::{Channel, ChannelEvent, ChannelList, ChannelMessage},
|
||||||
Client,
|
Client,
|
||||||
|
@ -8,7 +8,6 @@ pub mod project_panel;
|
|||||||
pub mod settings;
|
pub mod settings;
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub mod test;
|
pub mod test;
|
||||||
pub mod theme;
|
|
||||||
pub mod theme_selector;
|
pub mod theme_selector;
|
||||||
pub mod workspace;
|
pub mod workspace;
|
||||||
|
|
||||||
@ -31,6 +30,7 @@ pub use project::{self, fs};
|
|||||||
use project_panel::ProjectPanel;
|
use project_panel::ProjectPanel;
|
||||||
pub use settings::Settings;
|
pub use settings::Settings;
|
||||||
use std::{path::PathBuf, sync::Arc};
|
use std::{path::PathBuf, sync::Arc};
|
||||||
|
use theme::ThemeRegistry;
|
||||||
use util::TryFutureExt;
|
use util::TryFutureExt;
|
||||||
|
|
||||||
use crate::workspace::Workspace;
|
use crate::workspace::Workspace;
|
||||||
@ -48,7 +48,7 @@ pub struct AppState {
|
|||||||
pub settings_tx: Arc<Mutex<watch::Sender<Settings>>>,
|
pub settings_tx: Arc<Mutex<watch::Sender<Settings>>>,
|
||||||
pub settings: watch::Receiver<Settings>,
|
pub settings: watch::Receiver<Settings>,
|
||||||
pub languages: Arc<LanguageRegistry>,
|
pub languages: Arc<LanguageRegistry>,
|
||||||
pub themes: Arc<settings::ThemeRegistry>,
|
pub themes: Arc<ThemeRegistry>,
|
||||||
pub client: Arc<client::Client>,
|
pub client: Arc<client::Client>,
|
||||||
pub user_store: ModelHandle<client::UserStore>,
|
pub user_store: ModelHandle<client::UserStore>,
|
||||||
pub fs: Arc<dyn fs::Fs>,
|
pub fs: Arc<dyn fs::Fs>,
|
||||||
@ -198,6 +198,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::{test::test_app_state, workspace::ItemView};
|
use crate::{test::test_app_state, workspace::ItemView};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
use theme::DEFAULT_THEME_NAME;
|
||||||
use util::test::temp_tree;
|
use util::test::temp_tree;
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
@ -299,4 +300,18 @@ mod tests {
|
|||||||
assert!(!editor.is_dirty(cx));
|
assert!(!editor.is_dirty(cx));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
fn test_bundled_themes(cx: &mut MutableAppContext) {
|
||||||
|
let app_state = test_app_state(cx);
|
||||||
|
let mut has_default_theme = false;
|
||||||
|
for theme_name in app_state.themes.list() {
|
||||||
|
let theme = app_state.themes.get(&theme_name).unwrap();
|
||||||
|
if theme.name == DEFAULT_THEME_NAME {
|
||||||
|
has_default_theme = true;
|
||||||
|
}
|
||||||
|
assert_eq!(theme.name, theme_name);
|
||||||
|
}
|
||||||
|
assert!(has_default_theme);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ use log::LevelFilter;
|
|||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use simplelog::SimpleLogger;
|
use simplelog::SimpleLogger;
|
||||||
use std::{fs, path::PathBuf, sync::Arc};
|
use std::{fs, path::PathBuf, sync::Arc};
|
||||||
|
use theme::ThemeRegistry;
|
||||||
use zed::{
|
use zed::{
|
||||||
self,
|
self,
|
||||||
assets::Assets,
|
assets::Assets,
|
||||||
@ -30,7 +31,7 @@ fn main() {
|
|||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
app.platform().fonts().add_fonts(&embedded_fonts).unwrap();
|
app.platform().fonts().add_fonts(&embedded_fonts).unwrap();
|
||||||
|
|
||||||
let themes = settings::ThemeRegistry::new(Assets, app.font_cache());
|
let themes = ThemeRegistry::new(Assets, app.font_cache());
|
||||||
let (settings_tx, settings) =
|
let (settings_tx, settings) =
|
||||||
settings::channel("Inconsolata", &app.font_cache(), &themes).unwrap();
|
settings::channel("Inconsolata", &app.font_cache(), &themes).unwrap();
|
||||||
let languages = Arc::new(language::build_language_registry());
|
let languages = Arc::new(language::build_language_registry());
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::{theme::Theme, workspace::Workspace, Settings};
|
use crate::{workspace::Workspace, Settings};
|
||||||
use client::{Collaborator, UserStore};
|
use client::{Collaborator, UserStore};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
action,
|
action,
|
||||||
@ -9,6 +9,7 @@ use gpui::{
|
|||||||
Subscription, View, ViewContext,
|
Subscription, View, ViewContext,
|
||||||
};
|
};
|
||||||
use postage::watch;
|
use postage::watch;
|
||||||
|
use theme::Theme;
|
||||||
|
|
||||||
action!(JoinWorktree, u64);
|
action!(JoinWorktree, u64);
|
||||||
action!(LeaveWorktree, u64);
|
action!(LeaveWorktree, u64);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
project::{self, Project, ProjectEntry, ProjectPath},
|
project::{self, Project, ProjectEntry, ProjectPath},
|
||||||
theme,
|
|
||||||
workspace::Workspace,
|
workspace::Workspace,
|
||||||
Settings,
|
Settings,
|
||||||
};
|
};
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
use crate::theme::{self, DEFAULT_THEME_NAME};
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use gpui::font_cache::{FamilyId, FontCache};
|
use gpui::font_cache::{FamilyId, FontCache};
|
||||||
use postage::watch;
|
use postage::watch;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
pub use theme::{Theme, ThemeRegistry};
|
use theme::{Theme, ThemeRegistry, DEFAULT_THEME_NAME};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
use crate::{
|
use crate::{assets::Assets, language, settings::Settings, AppState};
|
||||||
assets::Assets,
|
|
||||||
language,
|
|
||||||
settings::Settings,
|
|
||||||
theme::{Theme, ThemeRegistry, DEFAULT_THEME_NAME},
|
|
||||||
AppState,
|
|
||||||
};
|
|
||||||
use buffer::LanguageRegistry;
|
use buffer::LanguageRegistry;
|
||||||
use client::{http::ServerResponse, test::FakeHttpClient, ChannelList, Client, UserStore};
|
use client::{http::ServerResponse, test::FakeHttpClient, ChannelList, Client, UserStore};
|
||||||
use gpui::{AssetSource, MutableAppContext};
|
use gpui::{AssetSource, MutableAppContext};
|
||||||
@ -12,6 +6,7 @@ use parking_lot::Mutex;
|
|||||||
use postage::watch;
|
use postage::watch;
|
||||||
use project::fs::FakeFs;
|
use project::fs::FakeFs;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use theme::{Theme, ThemeRegistry, DEFAULT_THEME_NAME};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[ctor::ctor]
|
#[ctor::ctor]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::{settings::ThemeRegistry, workspace::Workspace, AppState, Settings};
|
use crate::{workspace::Workspace, AppState, Settings};
|
||||||
use editor::{Editor, EditorSettings};
|
use editor::{Editor, EditorSettings};
|
||||||
use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
|
use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
@ -11,6 +11,7 @@ use gpui::{
|
|||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use postage::watch;
|
use postage::watch;
|
||||||
use std::{cmp, sync::Arc};
|
use std::{cmp, sync::Arc};
|
||||||
|
use theme::ThemeRegistry;
|
||||||
|
|
||||||
pub struct ThemeSelector {
|
pub struct ThemeSelector {
|
||||||
settings_tx: Arc<Mutex<watch::Sender<Settings>>>,
|
settings_tx: Arc<Mutex<watch::Sender<Settings>>>,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::theme::Theme;
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use gpui::{elements::*, Axis};
|
use gpui::{elements::*, Axis};
|
||||||
|
use theme::Theme;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
pub struct PaneGroup {
|
pub struct PaneGroup {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use super::Workspace;
|
use super::Workspace;
|
||||||
use crate::{theme, Settings};
|
use crate::Settings;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
action, elements::*, platform::CursorStyle, AnyViewHandle, MutableAppContext, RenderContext,
|
action, elements::*, platform::CursorStyle, AnyViewHandle, MutableAppContext, RenderContext,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user