diff options
-rw-r--r-- | src/vtcol.rs | 40 |
1 files changed, 38 insertions, 2 deletions
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<String>, 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<String>, 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<String>, 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!( |