From a8930c7fb69792b096222aae2947fb6a683af5d1 Mon Sep 17 00:00:00 2001 From: Triston Armstrong Date: Fri, 11 Aug 2023 23:21:48 -0500 Subject: [PATCH] Add readme --- README.md | 13 +++++++++++++ src/main.rs | 15 +++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..3606c3b --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Keyboard Backlight CLI +This essentially is just a CLI that you can install via `cargo` so you can quickly adjust the keyboard backlight of your mac + +## Target OS +I build this for me to use in Asahi linux on the mac because i, for the life of me, couldnt find a ui control for the keyboard backlight. + +## How To Use +1. Download this repo +2. Go to the directory +3. Run `cargo build` +4. Then Run `cargo install --path .` +5. Run `sudo kbd-bl ` anywhere in your terminal to adjust the backlight on the fly +6. Take a swig of taquila \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 7028d69..3ee31cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,23 +3,30 @@ use std::fs; fn main() { let args: Vec = env::args().collect(); + if args.len() < 2 { + println!("ERR: Must provide an argument"); + return; + } let value = &args[1]; let parsed = value.trim().parse::(); if parsed.is_err() { - panic!("Value entered ({}) is not number", value); + println!("ERR: Value entered ({}) is not number", value); + return; } let parsed_value = parsed.unwrap(); if parsed_value > 255 { - panic!("value entered ({}) must be <= 255", value); + println!("ERR: value entered ({}) must be <= 255", value); + return; } if parsed_value < 0 { - panic!("value entered ({}) must be >= 0", value); + println!("ERR: value entered ({}) must be >= 0", value); + return; } fs::write("/sys/class/leds/kbd_backlight/brightness", value) - .expect("Something went wrong writing to file") + .expect("Something went wrong writing to file - you may not have elevated privs aka sudo") }