Add readme
This commit is contained in:
parent
087a0658fd
commit
a8930c7fb6
13
README.md
Normal file
13
README.md
Normal file
@ -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 <value>` anywhere in your terminal to adjust the backlight on the fly
|
||||||
|
6. Take a swig of taquila
|
15
src/main.rs
15
src/main.rs
@ -3,23 +3,30 @@ use std::fs;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
|
if args.len() < 2 {
|
||||||
|
println!("ERR: Must provide an argument");
|
||||||
|
return;
|
||||||
|
}
|
||||||
let value = &args[1];
|
let value = &args[1];
|
||||||
let parsed = value.trim().parse::<i32>();
|
let parsed = value.trim().parse::<i32>();
|
||||||
|
|
||||||
if parsed.is_err() {
|
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();
|
let parsed_value = parsed.unwrap();
|
||||||
|
|
||||||
if parsed_value > 255 {
|
if parsed_value > 255 {
|
||||||
panic!("value entered ({}) must be <= 255", value);
|
println!("ERR: value entered ({}) must be <= 255", value);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if parsed_value < 0 {
|
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)
|
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")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user