summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml1
-rw-r--r--src/lib.rs6
-rw-r--r--src/vtcol.rs24
3 files changed, 25 insertions, 6 deletions
diff --git a/Cargo.toml b/Cargo.toml
index d1483dc..d743b4f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,6 +17,7 @@ edition = "2021"
libc = "0.2"
clap = { version = "2.33", optional = true }
anyhow = { version = "1.0", optional = true }
+base64 = "0.13"
[features]
vtcol-bin = [ "anyhow", "clap" ]
diff --git a/src/lib.rs b/src/lib.rs
index fd2d4f2..9914f77 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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:");