From 3f394af544db5075a8042cf6a45ba4ead85b1601 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 8 Aug 2022 23:02:40 +0200 Subject: lib: rework caps flag handling --- src/vtcol.rs | 41 +++++++++++++++++++++++++++++++++++------ 1 file 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 @@ -128,6 +128,14 @@ impl LedJob } } /* [impl LedJob] */ +#[derive(Debug)] +enum FlagTarget +{ + Current, + Default, + Both, +} + #[derive(Debug)] enum FlagJob { @@ -136,7 +144,7 @@ enum FlagJob /** Set all keyboard flags at once. */ Set(KbLedFlags), /** Set keyboard LED state of individual LEDs. */ - SetIndividual(bool, Option, Option, Option), + SetIndividual(FlagTarget, Option, Option, Option), } impl FlagJob @@ -173,7 +181,7 @@ impl FlagJob /** Set / unset keyboard flags using the current as base. */ fn set_individual( con: Option, - dflt: bool, + target: FlagTarget, cap: Option, num: Option, scr: Option, @@ -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, ), )), )) -- cgit v1.2.3