feat: --get
flag
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
parent
5419c2a93a
commit
d6ed51acbb
2 changed files with 14 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-FileCopyrightText: 2023 Christina Sørensen
|
// SPDX-FileCopyrightText: 2023-2024 Christina Sørensen
|
||||||
// SPDX-FileContributor: Christina Sørensen
|
// SPDX-FileContributor: Christina Sørensen
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
@ -26,4 +26,5 @@ pub fn build_cli() -> Command {
|
||||||
.allow_hyphen_values(true)
|
.allow_hyphen_values(true)
|
||||||
.value_parser(value_parser!(i32)),
|
.value_parser(value_parser!(i32)),
|
||||||
)
|
)
|
||||||
|
.arg(arg!(get: --get "Get current brightness.").required(false))
|
||||||
}
|
}
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -37,6 +37,13 @@ fn get_current_brightness() -> std::io::Result<i32> {
|
||||||
.expect("max brightnesss does not cleanly parse as i32"))
|
.expect("max brightnesss does not cleanly parse as i32"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_current_brightness_percentage() -> std::io::Result<f32> {
|
||||||
|
let max_brightness = get_max_brightness()?;
|
||||||
|
let current_brightness = get_current_brightness()?;
|
||||||
|
|
||||||
|
Ok((current_brightness as f32 / max_brightness as f32) * 100.)
|
||||||
|
}
|
||||||
|
|
||||||
fn set_brightness_percentage(brightness: i32) -> std::io::Result<()> {
|
fn set_brightness_percentage(brightness: i32) -> std::io::Result<()> {
|
||||||
let percentage = (get_max_brightness().expect("max brightnesss does not cleanly parse as i32")
|
let percentage = (get_max_brightness().expect("max brightnesss does not cleanly parse as i32")
|
||||||
/ 100)
|
/ 100)
|
||||||
|
@ -83,6 +90,11 @@ fn main() -> std::io::Result<()> {
|
||||||
set_brightness_percentage(*brightness)?;
|
set_brightness_percentage(*brightness)?;
|
||||||
} else if let Some(brightness) = matches.get_one::<i32>("change") {
|
} else if let Some(brightness) = matches.get_one::<i32>("change") {
|
||||||
change_brightness_percentage(*brightness)?;
|
change_brightness_percentage(*brightness)?;
|
||||||
|
} else if matches.get_flag("get") {
|
||||||
|
println!(
|
||||||
|
"{}%",
|
||||||
|
get_current_brightness_percentage().expect("failed to get current brightness") as i32
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
set_brightness_percentage(
|
set_brightness_percentage(
|
||||||
get_max_brightness().expect("max brightnesss does not cleanly parse as i32"),
|
get_max_brightness().expect("max brightnesss does not cleanly parse as i32"),
|
||||||
|
|
Loading…
Reference in a new issue