diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 3 | ||||
-rw-r--r-- | src/vtcol.rs | 30 |
2 files changed, 26 insertions, 7 deletions
@@ -186,6 +186,9 @@ impl KbLedState } #[inline] + pub fn revert(con: &Console) -> io::Result<()> { ioctl::kdsetled(con, None) } + + #[inline] pub fn cap(&self) -> bool { (self.0 & 0x4) != 0 } #[inline] diff --git a/src/vtcol.rs b/src/vtcol.rs index 2fdec10..738a622 100644 --- a/src/vtcol.rs +++ b/src/vtcol.rs @@ -23,8 +23,8 @@ enum LedJob { /** Get keyboard LED state. */ Get(bool), - /** Set keyboard LED state. */ - Set(KbLedState), + /** Set keyboard LED state; ``None`` indicates revert. */ + Set(Option<KbLedState>), } #[derive(Debug)] @@ -230,8 +230,16 @@ impl<'a> Job .long("u8") .help("provide desired state as integer") .takes_value(true) - .required(true) + .required_unless_one(&["revert"]) .value_name("STATE"), + ) + .arg( + Arg::with_name("revert") + .short("r") + .long("revert") + .help("revert LED state to normal") + .takes_value(false) + .conflicts_with("u8"), ), ), ); @@ -349,9 +357,12 @@ impl<'a> Job Ok(Self::Leds(LedJob::Get(raw))) }, ("set", Some(subm)) => { + if subm.is_present("revert") { + return Ok(Self::Leds(LedJob::Set(None))); + } let st: u8 = subm.value_of("u8").unwrap().parse()?; let st = KbLedState::try_from(st)?; - Ok(Self::Leds(LedJob::Set(st))) + Ok(Self::Leds(LedJob::Set(Some(st)))) }, (junk, _) => Err(anyhow!( @@ -525,13 +536,18 @@ impl<'a> Job } /** Set the keyboard LED state. */ - fn set_leds(st: KbLedState) -> Result<()> + fn set_leds(st: Option<KbLedState>) -> Result<()> { let fd = Console::current()?; vrb!("console fd: {}", fd); - st.set(&fd)?; - vrb!("applied"); + if let Some(st) = st { + st.set(&fd)?; + vrb!("applied"); + } else { + KbLedState::revert(&fd)?; + vrb!("reverted"); + } Ok(()) } |