diff options
-rw-r--r-- | src/vtcol.rs | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/src/vtcol.rs b/src/vtcol.rs index 93cece2..8b86e07 100644 --- a/src/vtcol.rs +++ b/src/vtcol.rs @@ -129,6 +129,14 @@ impl LedJob } /* [impl LedJob] */ #[derive(Debug)] +enum FlagTarget +{ + Current, + Default, + Both, +} + +#[derive(Debug)] enum FlagJob { /** Get keyboard flags. */ @@ -136,7 +144,7 @@ enum FlagJob /** Set all keyboard flags at once. */ Set(KbLedFlags), /** Set keyboard LED state of individual LEDs. */ - SetIndividual(bool, Option<bool>, Option<bool>, Option<bool>), + SetIndividual(FlagTarget, Option<bool>, Option<bool>, Option<bool>), } impl FlagJob @@ -173,7 +181,7 @@ impl FlagJob /** Set / unset keyboard flags using the current as base. */ fn set_individual( con: Option<String>, - dflt: bool, + target: FlagTarget, cap: Option<bool>, num: Option<bool>, scr: Option<bool>, @@ -184,11 +192,13 @@ impl FlagJob let mut st = KbLedFlags::get(&fd)?; - if dflt { + if matches!(target, FlagTarget::Default | FlagTarget::Both) { cap.map(|b| st.set_default_cap(b)); num.map(|b| st.set_default_num(b)); scr.map(|b| st.set_default_scr(b)); - } else { + } + + if matches!(target, FlagTarget::Current | FlagTarget::Both) { cap.map(|b| st.set_cap(b)); num.map(|b| st.set_num(b)); scr.map(|b| st.set_scr(b)); @@ -699,6 +709,17 @@ impl<'a> Job "operate on defaults, not the \ current state", ) + .conflicts_with("both") + .takes_value(false), + ) + .arg( + Arg::with_name("both") + .short("b") + .long("both") + .help( + "operate on both defaults and \ + current state", + ) .takes_value(false), ) .arg( @@ -934,7 +955,15 @@ impl<'a> Job )); } - let dflt = subm.is_present("dflt"); + let target = + if subm.is_present("both") { + FlagTarget::Both + } else if subm.is_present("dflt") { + FlagTarget::Default + } else { + FlagTarget::Current + }; + let cap = subm.value_of("caps").map(|a| a == "on"); let num = @@ -945,7 +974,7 @@ impl<'a> Job con, Subcmd::Kb(KbJob::Flags( FlagJob::SetIndividual( - dflt, cap, num, scr, + target, cap, num, scr, ), )), )) |