diff options
author | Philipp Gesang <phg@phi-gamma.net> | 2021-11-24 20:45:52 +0100 |
---|---|---|
committer | Philipp Gesang <phg@phi-gamma.net> | 2021-11-24 20:45:52 +0100 |
commit | fab3a5aea7107688b957ffc2502ed1539c7fad70 (patch) | |
tree | ba82f8e0f5c911ee1ad1ac1183a09dbd3b0663eb /src | |
parent | fc6cec72aead59c1d45044e8945c5b8119eab823 (diff) | |
download | vtcol-fab3a5aea7107688b957ffc2502ed1539c7fad70.tar.gz |
add base64 output for ‘get’
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 6 | ||||
-rw-r--r-- | src/vtcol.rs | 24 |
2 files changed, 24 insertions, 6 deletions
@@ -569,7 +569,11 @@ impl Palette /* Parse scheme file */ Self::from_buffered_reader(&mut reader) - } /* [Palette::from_stdin] */ + } + + /* [Palette::from_stdin] */ + + pub fn base64(&self) -> String { base64::encode(&self.0) } } /* [impl Palette] */ impl fmt::Display for Palette diff --git a/src/vtcol.rs b/src/vtcol.rs index e3ab5f2..0a198e6 100644 --- a/src/vtcol.rs +++ b/src/vtcol.rs @@ -30,7 +30,7 @@ enum Job /** Switch to color scheme. */ Set(Scheme), /** Get currently active scheme. */ - Get, + Get(bool), /** Toggle between two schemes. */ Toggle(Scheme, Scheme), /** Fade from current scheme to another. */ @@ -79,7 +79,16 @@ impl<'a> Job ), ) .subcommand( - SubCommand::with_name("get").about("get current color scheme"), + SubCommand::with_name("get") + .about("get current color scheme") + .arg( + Arg::with_name("base64") + .short("b") + .long("base64") + .help("base64 encoded binary output") + .required(false) + .takes_value(false), + ), ) .subcommand( SubCommand::with_name("toggle") @@ -185,7 +194,7 @@ impl<'a> Job }; Ok(Self::Set(scheme)) }, - ("get", _) => Ok(Self::Get), + ("get", Some(subm)) => Ok(Self::Get(subm.is_present("base64"))), ("toggle", Some(subm)) => { match (subm.value_of("one"), subm.value_of("two")) { (Some(one), Some(two)) => { @@ -287,7 +296,7 @@ impl<'a> Job Self::Dump(scm) => Self::dump(scm)?, Self::List => Self::list_schemes(), Self::Set(scm) => Self::set_scheme(scm)?, - Self::Get => Self::get_scheme()?, + Self::Get(b64) => Self::get_scheme(b64)?, Self::Toggle(one, two) => Self::toggle_scheme(one, two)?, Self::Fade(from, to, ms, hz, clear) => Self::fade(from, to, ms, hz, clear)?, @@ -309,11 +318,16 @@ impl<'a> Job Ok(()) } - fn get_scheme() -> Result<()> + fn get_scheme(b64: bool) -> Result<()> { let fd = Console::current()?; vrb!("console fd: {}", fd); + if b64 { + let pal = fd.current_palette()?; + println!("{}", pal.base64()); + } + let scm = fd.current_scheme()?; vrb!("active scheme:"); |