summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2021-12-12 00:56:26 +0100
committerPhilipp Gesang <phg@phi-gamma.net>2021-12-12 01:14:54 +0100
commit11156b67778ce87a24611b918b60fe970b979755 (patch)
tree5943313f938e7bbfc44e909627efdf4913b73c78
parent951df26618973a74d8c68a80634f965c23ba0734 (diff)
downloadvtcol-11156b67778ce87a24611b918b60fe970b979755.tar.gz
bin: implement led revert
Command: $ vtcol leds set --revert Implementing this detail of KDSETLED: [I]f a higher order bit is set, the LEDs revert to normal: displaying the state of the keyboard functions of caps lock, num lock, and scroll lock.
-rw-r--r--src/lib.rs3
-rw-r--r--src/vtcol.rs30
2 files changed, 26 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 6193277..0669b87 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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(())
}