From f87a4df1bc8d1b4be67046ab5672bb866737081f Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 22 Dec 2021 15:47:07 +0100 Subject: bin: add switch for flag defaults --- src/vtcol.rs | 53 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/src/vtcol.rs b/src/vtcol.rs index a3ff57b..183da18 100644 --- a/src/vtcol.rs +++ b/src/vtcol.rs @@ -134,7 +134,7 @@ enum FlagJob /** Set all keyboard flags at once. */ Set(KbLedFlags), /** Set keyboard LED state of individual LEDs. */ - SetIndividual(Option, Option, Option), + SetIndividual(bool, Option, Option, Option), } impl FlagJob @@ -171,6 +171,7 @@ impl FlagJob /** Set / unset keyboard flags using the current as base. */ fn set_individual( con: Option, + dflt: bool, cap: Option, num: Option, scr: Option, @@ -181,9 +182,15 @@ impl FlagJob let mut st = KbLedFlags::get(&fd)?; - cap.map(|b| st.set_cap(b)); - num.map(|b| st.set_num(b)); - scr.map(|b| st.set_scr(b)); + if dflt { + 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 { + cap.map(|b| st.set_cap(b)); + num.map(|b| st.set_num(b)); + scr.map(|b| st.set_scr(b)); + } st.set(&fd)?; vrb!("applied"); @@ -199,8 +206,8 @@ impl Run for FlagJob match self { Self::Get(raw) => Self::get(console, raw), Self::Set(flags) => Self::set(console, flags), - Self::SetIndividual(c, n, s) => - Self::set_individual(console, c, n, s), + Self::SetIndividual(dflt, c, n, s) => + Self::set_individual(console, dflt, c, n, s), } } } /* [impl Run for FlagJob] */ @@ -675,15 +682,23 @@ impl<'a> Job ) .takes_value(true) .required_unless_one(&[ - "revert", "caps", "num", - "scroll", + "caps", "num", "scroll", ]) .conflicts_with_all(&[ - "revert", "caps", "num", - "scroll", + "dflt", "caps", "num", "scroll", ]) .value_name("STATE"), ) + .arg( + Arg::with_name("dflt") + .short("d") + .long("default") + .help( + "operate on defaults, not the \ + current state", + ) + .takes_value(false), + ) .arg( Arg::with_name("caps") .short("c") @@ -691,9 +706,7 @@ impl<'a> Job .help("[de]activate Caps Lock flag") .takes_value(true) .possible_values(&["on", "off"]) - .conflicts_with_all(&[ - "revert", "u8", - ]) + .conflicts_with("u8") .value_name("STATE"), ) .arg( @@ -703,9 +716,7 @@ impl<'a> Job .help("[de]activate Num Lock flag") .takes_value(true) .possible_values(&["on", "off"]) - .conflicts_with_all(&[ - "revert", "u8", - ]) + .conflicts_with("u8") .value_name("STATE"), ) .arg( @@ -717,9 +728,7 @@ impl<'a> Job ) .takes_value(true) .possible_values(&["on", "off"]) - .conflicts_with_all(&[ - "revert", "u8", - ]) + .conflicts_with("u8") .value_name("STATE"), ), ), @@ -922,6 +931,8 @@ impl<'a> Job ))), )); } + + let dflt = subm.is_present("dflt"); let cap = subm.value_of("caps").map(|a| a == "on"); let num = @@ -931,7 +942,9 @@ impl<'a> Job Ok(Self( con, Subcmd::Kb(KbJob::Flags( - FlagJob::SetIndividual(cap, num, scr), + FlagJob::SetIndividual( + dflt, cap, num, scr, + ), )), )) }, -- cgit v1.2.3