From 352cda3be3ef5b1969b26428f31d717d7746add8 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 10:00:38 -0700 Subject: [PATCH] refactor(bar): print --schema through the platform view Both bars now print `schema.bar.json` as the view of the generated union schema (komorebi_bar_core::schema::generated_text): Windows through the Windows view (the identity), macOS through the macOS view. The sources of both bars are still separate, so the generated text is what it was and the macOS changes set what is already there (they are idempotent); this is the switch that lets the next revisions move code that differs only in schema text into the core in the Windows spelling. Verified: out-of-tree schema harness (S/bar2/regen.sh, real sources, bins updated to call generated_text): macOS byte-identical to komorebi-for-mac/schema.bar.json (3,774 lines), Windows byte-identical to schema.bar.json (9,091 lines). Native bar-core tests 3+5 passed, Windows clippy -D warnings clean, macOS fake-CC check 0 errors. The binaries were not run (cannot on Linux). --- crates/komorebi-bar-core/src/schema/mod.rs | 8 ++++++++ komorebi-bar/src/main.rs | 10 ++++++---- komorebi-for-mac/komorebi-bar/src/main.rs | 10 ++++++---- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/crates/komorebi-bar-core/src/schema/mod.rs b/crates/komorebi-bar-core/src/schema/mod.rs index b22c3982..ee284574 100644 --- a/crates/komorebi-bar-core/src/schema/mod.rs +++ b/crates/komorebi-bar-core/src/schema/mod.rs @@ -118,3 +118,11 @@ fn collect_refs(value: &Value, found: &mut Vec) { _ => {} } } + +/// The text `--schema` prints for the bar configuration type `T`, as `platform` checks it in. +#[cfg(feature = "schemars")] +#[must_use] +pub fn generated_text(platform: SchemaPlatform) -> String { + let union = serde_json::to_value(schemars::schema_for!(T)).expect("a schema is JSON"); + view_text(union, platform) +} diff --git a/komorebi-bar/src/main.rs b/komorebi-bar/src/main.rs index 89b25c77..b76e22a3 100644 --- a/komorebi-bar/src/main.rs +++ b/komorebi-bar/src/main.rs @@ -106,10 +106,12 @@ fn main() -> color_eyre::Result<()> { #[cfg(feature = "schemars")] if opts.schema { - let bar_config = schemars::schema_for!(KomobarConfig); - let schema = serde_json::to_string_pretty(&bar_config)?; - - println!("{schema}"); + print!( + "{}", + komorebi_bar_core::schema::generated_text::( + komorebi_bar_core::schema::SchemaPlatform::Windows + ) + ); std::process::exit(0); } diff --git a/komorebi-for-mac/komorebi-bar/src/main.rs b/komorebi-for-mac/komorebi-bar/src/main.rs index c08f444c..57e31bea 100644 --- a/komorebi-for-mac/komorebi-bar/src/main.rs +++ b/komorebi-for-mac/komorebi-bar/src/main.rs @@ -71,10 +71,12 @@ fn main() -> eyre::Result<()> { #[cfg(feature = "schemars")] if opts.schema { - let bar_config = schemars::schema_for!(KomobarConfig); - let schema = serde_json::to_string_pretty(&bar_config)?; - - println!("{schema}"); + print!( + "{}", + komorebi_bar_core::schema::generated_text::( + komorebi_bar_core::schema::SchemaPlatform::MacOs + ) + ); std::process::exit(0); }