From 48342e5bc46380d977edf178e31ad518eac7bd20 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 7 Aug 2022 09:25:07 +0200 Subject: edit: set up a rudimentary 60fps window Not much to see yet. --- src/vtcol.rs | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/vtcol.rs b/src/vtcol.rs index 122b471..f12af09 100644 --- a/src/vtcol.rs +++ b/src/vtcol.rs @@ -2,6 +2,8 @@ pub mod lib; +#[cfg(feature = "gui")] pub mod edit; + use vtcol::{Console, Fade, KbLedFlags, KbLedState, Palette, Scheme}; use anyhow::{anyhow, Result}; @@ -251,6 +253,8 @@ enum ColorJob List, /** Dump a scheme. */ Dump(Scheme), + /** Launch scheme editor. */ + Edit(Option, Scheme), /** Switch to color scheme. */ Set(Scheme), /** Get currently active scheme. */ @@ -267,6 +271,7 @@ impl Run for ColorJob { match self { Self::Dump(scm) => Self::dump(scm), + Self::Edit(name, scm) => Self::edit(name, scm), Self::List => Self::list(), Self::Set(scm) => Self::set(console, scm), Self::Get(b64) => Self::get(console, b64), @@ -321,6 +326,25 @@ impl ColorJob } } + #[cfg(feature = "gui")] + fn edit(name: Option, scm: Scheme) -> Result<()> + { + vrb!("Launching color scheme editor for scheme {}", scm); + let editor = crate::edit::Edit::new(); + + editor.run(name, scm) + } + + #[cfg(not(feature = "gui"))] + fn edit(scm: Scheme) -> Result<()> + { + eprintln!( + "scheme editor not available; try recompiling vtcol with \ + --features=gui!" + ); + Err(anyhow!("editor not available")) + } + fn set(con: Option, scheme: Scheme) -> Result<()> { let fd = open_console(con.as_deref())?; @@ -801,9 +825,21 @@ impl<'a> Job #[cfg(feature = "gui")] if let Some(name) = subm.value_of("scheme") { let scm = Scheme::from(name); - Ok(Self(con, Subcmd::Colors(ColorJob::Dump(scm)))) + Ok(Self( + con, + Subcmd::Colors(ColorJob::Edit( + Some(name.to_string()), + scm, + )), + )) } else { - todo!() /* generate generic name */ + Ok(Self( + con, + Subcmd::Colors(ColorJob::Edit( + None, + Scheme::from("default"), + )), + )) } #[cfg(not(feature = "gui"))] Err(anyhow!( -- cgit v1.2.3