updating option "-k" to show current brightness: asusctl -k

This commit is contained in:
Asere
2020-10-13 17:31:30 +02:00
parent a23c51e5db
commit d36ac44603
5 changed files with 102 additions and 16 deletions
+24 -7
View File
@@ -5,10 +5,14 @@ use std::str::FromStr;
#[derive(Options)]
pub struct LedBrightness {
level: u8,
level: Option<u8>,
}
impl LedBrightness {
pub fn level(&self) -> u8 {
pub fn new(level: Option<u8>) -> Self {
LedBrightness { level }
}
pub fn level(&self) -> Option<u8> {
self.level
}
}
@@ -18,17 +22,30 @@ impl FromStr for LedBrightness {
fn from_str(s: &str) -> Result<Self, Self::Err> {
let s = s.to_lowercase();
match s.as_str() {
"off" => Ok(LedBrightness { level: 0x00 }),
"low" => Ok(LedBrightness { level: 0x01 }),
"med" => Ok(LedBrightness { level: 0x02 }),
"high" => Ok(LedBrightness { level: 0x03 }),
"off" => Ok(LedBrightness { level: Some(0x00) }),
"low" => Ok(LedBrightness { level: Some(0x01) }),
"med" => Ok(LedBrightness { level: Some(0x02) }),
"high" => Ok(LedBrightness { level: Some(0x03) }),
_ => {
println!("Missing required argument, must be one of:\noff,low,med,high\n");
print!("{}\n{}\n",
"Invalid argument, must be one of:",
"off, low, med, high");
Err(AuraError::ParseBrightness)
}
}
}
}
impl ToString for LedBrightness {
fn to_string(&self) -> String {
let s = match self.level {
Some(0x00) => "low",
Some(0x01) => "med",
Some(0x02) => "high",
_ => "unknown",
};
s.to_string()
}
}
#[derive(Deserialize, Serialize)]
pub struct Colour(pub u8, pub u8, pub u8);