diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/vtcol.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/vtcol.rs b/src/vtcol.rs index 45cbbd4..81f586f 100644 --- a/src/vtcol.rs +++ b/src/vtcol.rs @@ -185,6 +185,8 @@ enum Job Set(Scheme), /** Get currently active scheme. */ Get, + /** Toggle between two schemes. */ + Toggle(Scheme, Scheme), } impl<'a> Job @@ -231,6 +233,22 @@ impl<'a> Job .subcommand( SubCommand::with_name("get").about("get current color scheme"), ) + .subcommand( + SubCommand::with_name("toggle") + .about("toggle between two schemes") + .arg( + Arg::with_name("one") + .value_name("NAME1") + .help("predefined color scheme") + .takes_value(true), + ) + .arg( + Arg::with_name("two") + .value_name("NAME2") + .help("predefined color scheme") + .takes_value(true), + ), + ) .arg( Arg::with_name("verbose") .short("v") @@ -276,6 +294,18 @@ impl<'a> Job Ok(Self::Set(scheme)) }, ("get", _) => Ok(Self::Get), + ("toggle", Some(subm)) => { + match (subm.value_of("one"), subm.value_of("two")) { + (Some(one), Some(two)) => { + vrb!("toggle schemes [{}] and [{}]", one, two); + Ok(Self::Toggle(Scheme::from(one), Scheme::from(two))) + }, + _ => + Err(anyhow!( + "please supply two schemes to toggle between" + )), + } + }, (junk, _) => Err(anyhow!( "invalid subcommand [{}]; try ``{} --help``", @@ -323,6 +353,7 @@ impl<'a> Job Self::List => Self::schemes(), Self::Set(scm) => Self::set_scheme(scm)?, Self::Get => Self::get_scheme()?, + Self::Toggle(one, two) => Self::toggle_scheme(one, two)?, } Ok(()) @@ -357,6 +388,23 @@ impl<'a> Job Ok(()) } + + /** Toggle between two schemes. Defaults to ``one`` in case neither scheme + is active. + */ + fn toggle_scheme(one: Scheme, two: Scheme) -> Result<()> + { + let fd = get_console_fd()?; + vrb!("console fd: {}", fd); + + let pal = ioctl_gio_cmap(fd)?; + + if pal == Palette::from(&one) { + Self::set_scheme(two) + } else { + Self::set_scheme(one) + } + } } /* [impl Job] */ /* Rust appears to come with two wrappers for ``ioctl(2)``, but neither can be utilized for our |