summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2021-12-08 19:55:20 +0100
committerPhilipp Gesang <phg@phi-gamma.net>2021-12-08 19:49:22 +0100
commit2bb98ae1f837f4d09f282886b5d6d184e8726207 (patch)
treef76624793c62a3c47ef21d9ffc08c90696d1fd03 /src/lib.rs
parent480435ff68a910eabc011e44f5a63b43536a4d02 (diff)
downloadvtcol-2bb98ae1f837f4d09f282886b5d6d184e8726207.tar.gz
add KDGETLED subcommand to vtcol-bin
Actually we add both subcommand and sub-subcommand. Example: [*] 15:52:40 phg@acheron vtcol $ vtcol leds get Caps: false, Num: true, Scroll: false
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 681177c..2ef43e8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -165,7 +165,7 @@ pub struct KbLedState(u8);
impl KbLedState
{
- fn new(cap: bool, num: bool, scr: bool) -> Self
+ pub fn new(cap: bool, num: bool, scr: bool) -> Self
{
let mut state = 0u8;
@@ -175,6 +175,32 @@ impl KbLedState
Self(state)
}
+
+ #[inline]
+ pub fn get(con: &Console) -> io::Result<Self> { ioctl::kdgetled(con) }
+
+ #[inline]
+ pub fn cap(&self) -> bool { (self.0 & 0x4) != 0 }
+
+ #[inline]
+ pub fn num(&self) -> bool { (self.0 & 0x2) != 0 }
+
+ #[inline]
+ pub fn scr(&self) -> bool { (self.0 & 0x1) != 0 }
+}
+
+impl fmt::Display for KbLedState
+{
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
+ {
+ write!(
+ f,
+ "caps: {}, num: {}, scroll: {}",
+ self.cap(),
+ self.num(),
+ self.scr()
+ )
+ }
}
impl From<libc::c_char> for KbLedState