Extend UserSyntax to allow font_style and font_weight to be specified

Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com>
This commit is contained in:
Nate Butler 2023-11-09 13:46:08 -05:00
parent 978cff8095
commit ff053890cf
11 changed files with 111 additions and 15 deletions

View file

@ -364,19 +364,33 @@ pub struct UserHighlightStylePrinter<'a>(&'a UserHighlightStyle);
impl<'a> Debug for UserHighlightStylePrinter<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let fields = vec![("color", self.0.color)];
f.write_str("UserHighlightStyle {")?;
for (field_name, value) in fields {
if let Some(color) = value {
f.write_str(field_name)?;
f.write_str(": ")?;
f.write_str("Some(")?;
HslaPrinter(color).fmt(f)?;
f.write_str(")")?;
f.write_str(",")?;
}
if let Some(color) = self.0.color {
f.write_str("color")?;
f.write_str(": ")?;
f.write_str("Some(")?;
HslaPrinter(color).fmt(f)?;
f.write_str(")")?;
f.write_str(",")?;
}
if let Some(font_style) = self.0.font_style {
f.write_str("font_style")?;
f.write_str(": ")?;
f.write_str("Some(")?;
write!(f, "UserFontStyle::{:?}", font_style)?;
f.write_str(")")?;
f.write_str(",")?;
}
if let Some(font_weight) = self.0.font_weight.as_ref() {
f.write_str("font_weight")?;
f.write_str(": ")?;
f.write_str("Some(")?;
write!(f, "UserFontWeight({:?})", font_weight.0)?;
f.write_str(")")?;
f.write_str(",")?;
}
f.write_str("..Default::default()")?;

View file

@ -2,8 +2,8 @@ use anyhow::Result;
use gpui::{Hsla, Rgba};
use indexmap::IndexMap;
use theme::{
StatusColorsRefinement, ThemeColorsRefinement, UserSyntaxTheme, UserTheme,
UserThemeStylesRefinement,
StatusColorsRefinement, ThemeColorsRefinement, UserFontStyle, UserFontWeight, UserSyntaxTheme,
UserTheme, UserThemeStylesRefinement,
};
use crate::util::Traverse;
@ -14,6 +14,21 @@ pub(crate) fn try_parse_color(color: &str) -> Result<Hsla> {
Ok(Rgba::try_from(color)?.into())
}
pub(crate) fn try_parse_font_weight(font_style: &str) -> Option<UserFontWeight> {
match font_style {
style if style.contains("bold") => Some(UserFontWeight::BOLD),
_ => None,
}
}
pub(crate) fn try_parse_font_style(font_style: &str) -> Option<UserFontStyle> {
match font_style {
style if style.contains("italic") => Some(UserFontStyle::Italic),
style if style.contains("oblique") => Some(UserFontStyle::Oblique),
_ => None,
}
}
pub struct VsCodeThemeConverter {
theme: VsCodeTheme,
theme_metadata: ThemeMetadata,

View file

@ -8,7 +8,7 @@ use serde::Deserialize;
use theme::UserHighlightStyle;
use crate::util::Traverse;
use crate::vscode::try_parse_color;
use crate::vscode::{try_parse_color, try_parse_font_style, try_parse_font_weight};
#[derive(Debug, Deserialize)]
#[serde(untagged)]
@ -52,6 +52,16 @@ impl VsCodeTokenColor {
.foreground
.as_ref()
.traverse(|color| try_parse_color(&color))?,
font_style: self
.settings
.font_style
.as_ref()
.and_then(|style| try_parse_font_style(&style)),
font_weight: self
.settings
.font_style
.as_ref()
.and_then(|style| try_parse_font_weight(&style)),
};
if highlight_style.is_empty() {