2021-08-24 23:33:56 +00:00
|
|
|
mod highlight_map;
|
|
|
|
mod theme_registry;
|
|
|
|
|
|
|
|
use anyhow::Result;
|
2021-08-04 00:51:06 +00:00
|
|
|
use gpui::{
|
|
|
|
color::Color,
|
|
|
|
elements::{ContainerStyle, LabelStyle},
|
2021-08-04 21:07:19 +00:00
|
|
|
fonts::TextStyle,
|
2021-08-04 00:51:06 +00:00
|
|
|
};
|
2021-08-04 21:07:19 +00:00
|
|
|
use serde::{Deserialize, Deserializer};
|
2021-08-24 23:33:56 +00:00
|
|
|
use std::collections::HashMap;
|
2021-08-04 01:42:39 +00:00
|
|
|
|
2021-08-24 23:33:56 +00:00
|
|
|
pub use highlight_map::*;
|
|
|
|
pub use theme_registry::*;
|
2021-08-04 01:42:39 +00:00
|
|
|
|
2021-08-24 23:33:56 +00:00
|
|
|
pub const DEFAULT_THEME_NAME: &'static str = "dark";
|
2021-08-04 01:42:39 +00:00
|
|
|
|
2021-08-04 01:35:15 +00:00
|
|
|
#[derive(Debug, Default, Deserialize)]
|
2021-08-03 20:36:58 +00:00
|
|
|
pub struct Theme {
|
2021-08-04 21:16:28 +00:00
|
|
|
#[serde(default)]
|
|
|
|
pub name: String,
|
2021-08-20 16:44:34 +00:00
|
|
|
pub workspace: Workspace,
|
2021-08-24 23:46:23 +00:00
|
|
|
pub chat_panel: ChatPanel,
|
2021-08-20 16:44:34 +00:00
|
|
|
pub selector: Selector,
|
2021-08-03 20:36:58 +00:00
|
|
|
pub editor: Editor,
|
2021-08-04 01:35:15 +00:00
|
|
|
#[serde(deserialize_with = "deserialize_syntax_theme")]
|
2021-08-04 21:07:19 +00:00
|
|
|
pub syntax: Vec<(String, TextStyle)>,
|
2021-08-03 20:36:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default, Deserialize)]
|
2021-08-20 16:44:34 +00:00
|
|
|
pub struct Workspace {
|
2021-08-03 20:36:58 +00:00
|
|
|
pub background: Color,
|
2021-08-24 23:38:26 +00:00
|
|
|
pub tab: Tab,
|
|
|
|
pub active_tab: Tab,
|
|
|
|
pub sidebar: ContainerStyle,
|
|
|
|
pub sidebar_icon: SidebarIcon,
|
|
|
|
pub active_sidebar_icon: SidebarIcon,
|
2021-08-03 20:36:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default, Deserialize)]
|
|
|
|
pub struct Tab {
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub container: ContainerStyle,
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub label: LabelStyle,
|
|
|
|
pub icon_close: Color,
|
|
|
|
pub icon_dirty: Color,
|
|
|
|
pub icon_conflict: Color,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default, Deserialize)]
|
2021-08-20 20:51:52 +00:00
|
|
|
pub struct SidebarIcon {
|
|
|
|
pub color: Color,
|
|
|
|
}
|
|
|
|
|
2021-08-24 23:46:23 +00:00
|
|
|
#[derive(Debug, Default, Deserialize)]
|
|
|
|
pub struct ChatPanel {
|
2021-08-25 22:22:14 +00:00
|
|
|
#[serde(flatten)]
|
|
|
|
pub container: ContainerStyle,
|
2021-08-24 23:46:23 +00:00
|
|
|
pub message: ChatMessage,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default, Deserialize)]
|
|
|
|
pub struct ChatMessage {
|
2021-08-25 14:42:35 +00:00
|
|
|
pub body: TextStyle,
|
2021-08-25 22:22:14 +00:00
|
|
|
pub sender: ContainedLabel,
|
|
|
|
pub timestamp: ContainedLabel,
|
2021-08-24 23:46:23 +00:00
|
|
|
}
|
|
|
|
|
2021-08-20 20:51:52 +00:00
|
|
|
#[derive(Debug, Default, Deserialize)]
|
2021-08-03 20:36:58 +00:00
|
|
|
pub struct Selector {
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub container: ContainerStyle,
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub label: LabelStyle,
|
|
|
|
|
2021-08-25 22:22:14 +00:00
|
|
|
pub item: ContainedLabel,
|
|
|
|
pub active_item: ContainedLabel,
|
2021-08-03 20:36:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default, Deserialize)]
|
2021-08-25 22:22:14 +00:00
|
|
|
pub struct ContainedLabel {
|
2021-08-03 20:36:58 +00:00
|
|
|
#[serde(flatten)]
|
|
|
|
pub container: ContainerStyle,
|
|
|
|
#[serde(flatten)]
|
|
|
|
pub label: LabelStyle,
|
|
|
|
}
|
|
|
|
|
2021-08-24 23:39:56 +00:00
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
pub struct Editor {
|
|
|
|
pub background: Color,
|
|
|
|
pub gutter_background: Color,
|
|
|
|
pub active_line_background: Color,
|
|
|
|
pub line_number: Color,
|
|
|
|
pub line_number_active: Color,
|
|
|
|
pub text: Color,
|
|
|
|
pub replicas: Vec<Replica>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Default, Deserialize)]
|
|
|
|
pub struct Replica {
|
|
|
|
pub cursor: Color,
|
|
|
|
pub selection: Color,
|
2021-08-03 20:36:58 +00:00
|
|
|
}
|
2021-08-04 00:51:06 +00:00
|
|
|
|
2021-08-04 01:42:39 +00:00
|
|
|
impl Theme {
|
2021-08-04 21:07:19 +00:00
|
|
|
pub fn highlight_style(&self, id: HighlightId) -> TextStyle {
|
2021-08-04 01:42:39 +00:00
|
|
|
self.syntax
|
|
|
|
.get(id.0 as usize)
|
2021-08-04 21:07:19 +00:00
|
|
|
.map(|entry| entry.1.clone())
|
|
|
|
.unwrap_or_else(|| TextStyle {
|
|
|
|
color: self.editor.text,
|
|
|
|
font_properties: Default::default(),
|
2021-08-04 01:42:39 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2021-08-04 21:07:19 +00:00
|
|
|
pub fn highlight_name(&self, id: HighlightId) -> Option<&str> {
|
2021-08-04 01:42:39 +00:00
|
|
|
self.syntax.get(id.0 as usize).map(|e| e.0.as_str())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-24 23:39:56 +00:00
|
|
|
impl Default for Editor {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
background: Default::default(),
|
|
|
|
gutter_background: Default::default(),
|
|
|
|
active_line_background: Default::default(),
|
|
|
|
line_number: Default::default(),
|
|
|
|
line_number_active: Default::default(),
|
|
|
|
text: Default::default(),
|
|
|
|
replicas: vec![Replica::default()],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-04 01:35:15 +00:00
|
|
|
pub fn deserialize_syntax_theme<'de, D>(
|
|
|
|
deserializer: D,
|
2021-08-04 21:07:19 +00:00
|
|
|
) -> Result<Vec<(String, TextStyle)>, D::Error>
|
2021-08-04 01:35:15 +00:00
|
|
|
where
|
|
|
|
D: Deserializer<'de>,
|
|
|
|
{
|
2021-08-04 21:07:19 +00:00
|
|
|
let mut result = Vec::<(String, TextStyle)>::new();
|
2021-08-04 01:35:15 +00:00
|
|
|
|
2021-08-04 21:07:19 +00:00
|
|
|
let syntax_data: HashMap<String, TextStyle> = Deserialize::deserialize(deserializer)?;
|
2021-08-04 01:35:15 +00:00
|
|
|
for (key, style) in syntax_data {
|
2021-08-04 21:07:19 +00:00
|
|
|
match result.binary_search_by(|(needle, _)| needle.cmp(&key)) {
|
2021-08-04 01:35:15 +00:00
|
|
|
Ok(i) | Err(i) => {
|
2021-08-04 21:07:19 +00:00
|
|
|
result.insert(i, (key, style));
|
2021-08-04 01:35:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(result)
|
|
|
|
}
|