1pub mod patch;
8pub use patch::{Patch, PatchError};
9
10use std::collections::BTreeMap;
11
12#[cfg(feature = "schema")]
13use schemars::JsonSchema;
14use serde::{Deserialize, Serialize};
15
16pub const SPEC_VERSION: u32 = 1;
23
24#[derive(Clone, Debug, Serialize, Deserialize)]
26#[cfg_attr(feature = "schema", derive(JsonSchema))]
27#[serde(default)]
28#[non_exhaustive]
29#[cfg_attr(feature = "schema", schemars(description = "A complete application description."))]
35pub struct HostSpec {
36 pub version: u32,
38 pub window: WindowSpec,
40 pub theme: ThemeSpec,
42 pub commands: Vec<CommandSpec>,
44 pub menus: Vec<MenuSpec>,
46 pub explorer: Vec<TreeSpec>,
48 pub layout: LayoutSpec,
50 pub panels: PanelsSpec,
52 pub status: StatusSpec,
54 pub widgets: Vec<WidgetSpec>,
56 pub dialogs: Vec<DialogSpec>,
58 pub toasts: Vec<ToastSpec>,
60 pub metadata: BTreeMap<String, String>,
62}
63
64impl Default for HostSpec {
65 fn default() -> Self {
66 Self {
67 version: SPEC_VERSION,
68 window: WindowSpec::default(),
69 theme: ThemeSpec::default(),
70 commands: Vec::new(),
71 menus: Vec::new(),
72 explorer: Vec::new(),
73 layout: LayoutSpec::default(),
74 panels: PanelsSpec::default(),
75 status: StatusSpec::default(),
76 widgets: vec![WidgetSpec::Label {
77 text: "Hello from crisol-host".to_owned(),
78 size: 13.0,
79 tone: "default".to_owned(),
80 strong: false,
81 }],
82 dialogs: Vec::new(),
83 toasts: Vec::new(),
84 metadata: BTreeMap::new(),
85 }
86 }
87}
88
89impl HostSpec {
90 #[cfg(feature = "schema")]
92 pub fn schema() -> serde_json::Value {
93 serde_json::to_value(schemars::schema_for!(HostSpec)).unwrap_or(serde_json::Value::Null)
94 }
95
96 pub fn from_json(json: &str) -> Result<Self, String> {
101 let spec: Self = serde_json::from_str(json).map_err(|error| error.to_string())?;
102 if spec.version > SPEC_VERSION {
103 return Err(format!("unsupported spec version {}", spec.version));
104 }
105 Ok(spec)
106 }
107}
108
109#[derive(Clone, Debug, Serialize, Deserialize)]
111#[cfg_attr(feature = "schema", derive(JsonSchema))]
112#[serde(default)]
113#[non_exhaustive]
114#[cfg_attr(feature = "schema", schemars(description = "Window title and size."))]
120pub struct WindowSpec {
121 pub title: String,
123 pub width: f32,
125 pub height: f32,
127 pub resizable: bool,
129 pub custom_title_bar: bool,
131}
132
133impl Default for WindowSpec {
134 fn default() -> Self {
135 Self {
136 title: "Workbench".to_owned(),
137 width: 980.0,
138 height: 720.0,
139 resizable: true,
140 custom_title_bar: true,
141 }
142 }
143}
144
145#[derive(Clone, Debug, Serialize, Deserialize)]
147#[cfg_attr(feature = "schema", derive(JsonSchema))]
148#[serde(default)]
149#[non_exhaustive]
150#[cfg_attr(feature = "schema", schemars(description = "Theme preferences."))]
156pub struct ThemeSpec {
157 pub id: String,
159 pub follow_system: bool,
161 pub reduced_motion: bool,
163}
164
165impl Default for ThemeSpec {
166 fn default() -> Self {
167 Self {
168 id: "github-dark".to_owned(),
169 follow_system: false,
170 reduced_motion: false,
171 }
172 }
173}
174
175#[cfg_attr(feature = "schema", derive(JsonSchema))]
177#[derive(Clone, Debug, Default, Serialize, Deserialize)]
178#[serde(default)]
179#[non_exhaustive]
180#[cfg_attr(feature = "schema", schemars(description = "One command."))]
186pub struct CommandSpec {
187 pub id: String,
189 pub title: String,
191 pub category: String,
193 pub shortcut: Option<String>,
195 pub when: Option<String>,
197 pub enabled: bool,
199 pub checked: bool,
201}
202
203#[cfg_attr(feature = "schema", derive(JsonSchema))]
205#[derive(Clone, Debug, Default, Serialize, Deserialize)]
206#[serde(default)]
207#[non_exhaustive]
208#[cfg_attr(feature = "schema", schemars(description = "One top-level menu."))]
214pub struct MenuSpec {
215 pub title: String,
217 pub items: Vec<MenuItemSpec>,
219}
220
221#[cfg_attr(feature = "schema", derive(JsonSchema))]
223#[derive(Clone, Debug, Default, Serialize, Deserialize)]
224#[serde(default)]
225#[non_exhaustive]
226#[cfg_attr(feature = "schema", schemars(description = "One menu row."))]
232pub struct MenuItemSpec {
233 pub label: String,
235 pub command: Option<String>,
237 pub separator: bool,
239}
240
241#[cfg_attr(feature = "schema", derive(JsonSchema))]
243#[derive(Clone, Debug, Default, Serialize, Deserialize)]
244#[serde(default)]
245#[non_exhaustive]
246#[cfg_attr(feature = "schema", schemars(description = "One explorer node."))]
247pub struct TreeSpec {
253 pub key: String,
255 pub label: String,
257 pub icon: Option<String>,
259 pub expanded: bool,
261 pub children: Vec<TreeSpec>,
263}
264
265#[derive(Clone, Debug, Serialize, Deserialize)]
267#[cfg_attr(feature = "schema", derive(JsonSchema))]
268#[serde(default)]
269#[non_exhaustive]
270#[cfg_attr(feature = "schema", schemars(description = "Editor groups and tabs."))]
276pub struct LayoutSpec {
277 pub groups: Vec<GroupSpec>,
279 pub active: usize,
281 pub direction: String,
283}
284
285impl Default for LayoutSpec {
286 fn default() -> Self {
287 Self {
288 groups: vec![GroupSpec::default()],
289 active: 0,
290 direction: "horizontal".to_owned(),
291 }
292 }
293}
294
295#[cfg_attr(feature = "schema", derive(JsonSchema))]
297#[derive(Clone, Debug, Default, Serialize, Deserialize)]
298#[serde(default)]
299#[non_exhaustive]
300#[cfg_attr(feature = "schema", schemars(description = "One editor group."))]
306pub struct GroupSpec {
307 pub id: String,
309 pub tabs: Vec<TabSpec>,
311 pub active: usize,
313}
314
315#[cfg_attr(feature = "schema", derive(JsonSchema))]
317#[derive(Clone, Debug, Default, Serialize, Deserialize)]
318#[serde(default)]
319#[non_exhaustive]
320#[cfg_attr(feature = "schema", schemars(description = "One editor tab."))]
321pub struct TabSpec {
327 pub id: String,
329 pub title: String,
331 pub pinned: bool,
333}
334
335#[derive(Clone, Debug, Serialize, Deserialize)]
337#[cfg_attr(feature = "schema", derive(JsonSchema))]
338#[serde(default)]
339#[non_exhaustive]
340#[cfg_attr(feature = "schema", schemars(description = "Visible panels."))]
346pub struct PanelsSpec {
347 pub sidebar: bool,
349 pub inspector: bool,
351 pub bottom: bool,
353 pub status: bool,
355}
356
357impl Default for PanelsSpec {
358 fn default() -> Self {
359 Self {
360 sidebar: true,
361 inspector: false,
362 bottom: false,
363 status: true,
364 }
365 }
366}
367
368#[cfg_attr(feature = "schema", derive(JsonSchema))]
370#[derive(Clone, Debug, Default, Serialize, Deserialize)]
371#[serde(default)]
372#[non_exhaustive]
373#[cfg_attr(feature = "schema", schemars(description = "Status bar items."))]
379pub struct StatusSpec {
380 pub left: Vec<String>,
382 pub right: Vec<String>,
384}
385
386mod widget;
388pub use widget::WidgetSpec;
389
390#[cfg_attr(feature = "schema", derive(JsonSchema))]
392#[derive(Clone, Debug, Default, Serialize, Deserialize)]
393#[serde(default)]
394#[non_exhaustive]
395#[cfg_attr(feature = "schema", schemars(description = "A plot series in a spec."))]
401pub struct SeriesSpec {
402 pub name: String,
404 pub style: String,
406 pub points: Vec<[f64; 2]>,
408 pub dataset: Option<String>,
410 pub x: Option<String>,
412 pub y: Option<String>,
414 pub color: Option<String>,
416 pub width: Option<f32>,
418}
419
420#[cfg_attr(feature = "schema", derive(JsonSchema))]
422#[derive(Clone, Debug, Default, Serialize, Deserialize)]
423#[serde(default)]
424#[non_exhaustive]
425#[cfg_attr(feature = "schema", schemars(description = "A dialog declaration."))]
431pub struct DialogSpec {
432 pub id: String,
434 pub title: String,
436 pub message: String,
438 pub confirm: String,
440 pub cancel: String,
442 pub open: bool,
444}
445
446#[cfg_attr(feature = "schema", derive(JsonSchema))]
448#[derive(Clone, Debug, Default, Serialize, Deserialize)]
449#[serde(default)]
450#[non_exhaustive]
451#[cfg_attr(feature = "schema", schemars(description = "A toast declaration."))]
457pub struct ToastSpec {
458 pub kind: String,
460 pub title: String,
462 pub description: Option<String>,
464}