Cargo.lock 🔗
@@ -7775,6 +7775,7 @@ dependencies = [
"schemars",
"serde",
"serde_derive",
+ "serde_json",
"settings",
"shellexpand",
"smallvec",
Piotr Osiewicz created
Cargo.lock | 1
crates/terminal/Cargo.toml | 1
crates/terminal/src/terminal_settings.rs | 41 +++++++++++++++++++++++++
crates/theme/src/settings.rs | 4 ++
4 files changed, 46 insertions(+), 1 deletion(-)
@@ -7775,6 +7775,7 @@ dependencies = [
"schemars",
"serde",
"serde_derive",
+ "serde_json",
"settings",
"shellexpand",
"smallvec",
@@ -33,6 +33,7 @@ thiserror.workspace = true
lazy_static.workspace = true
serde.workspace = true
serde_derive.workspace = true
+serde_json.workspace = true
[dev-dependencies]
rand.workspace = true
@@ -1,6 +1,12 @@
use gpui::{px, AbsoluteLength, AppContext, FontFeatures, Pixels};
-use schemars::JsonSchema;
+use schemars::{
+ gen::SchemaGenerator,
+ schema::{InstanceType, RootSchema, Schema, SchemaObject},
+ JsonSchema,
+};
use serde_derive::{Deserialize, Serialize};
+use serde_json::Value;
+use settings::SettingsJsonSchemaParams;
use std::{collections::HashMap, path::PathBuf};
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
@@ -153,6 +159,39 @@ impl settings::Settings for TerminalSettings {
) -> anyhow::Result<Self> {
Self::load_via_json_merge(default_value, user_values)
}
+ fn json_schema(
+ generator: &mut SchemaGenerator,
+ _: &SettingsJsonSchemaParams,
+ cx: &AppContext,
+ ) -> RootSchema {
+ let mut root_schema = generator.root_schema_for::<Self::FileContent>();
+ let available_fonts = cx
+ .text_system()
+ .all_font_names()
+ .into_iter()
+ .map(Value::String)
+ .collect();
+ let fonts_schema = SchemaObject {
+ instance_type: Some(InstanceType::String.into()),
+ enum_values: Some(available_fonts),
+ ..Default::default()
+ };
+ root_schema
+ .definitions
+ .extend([("FontFamilies".into(), fonts_schema.into())]);
+ root_schema
+ .schema
+ .object
+ .as_mut()
+ .unwrap()
+ .properties
+ .extend([(
+ "font_family".to_owned(),
+ Schema::new_ref("#/definitions/FontFamilies".into()),
+ )]);
+
+ root_schema
+ }
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, Default)]
@@ -234,6 +234,10 @@ impl settings::Settings for ThemeSettings {
"buffer_font_family".to_owned(),
Schema::new_ref("#/definitions/FontFamilies".into()),
),
+ (
+ "ui_font_family".to_owned(),
+ Schema::new_ref("#/definitions/FontFamilies".into()),
+ ),
]);
root_schema