Skip to content

Instantly share code, notes, and snippets.

@hmble
Last active March 16, 2020 06:48
Show Gist options
  • Save hmble/4b67d241156bfd14a39a3f653edaed49 to your computer and use it in GitHub Desktop.
Save hmble/4b67d241156bfd14a39a3f653edaed49 to your computer and use it in GitHub Desktop.
run this file with sudo
use std::env;
use std::fs;
fn main() {
let max_brightness: i32 = 800;
let args: Vec<String> = env::args().collect();
let path = "/sys/class/backlight/intel_backlight/brightness";
//let content = &args[1].as_bytes();
let mut str = "down";
if args.len() == 2 {
str = &args[1].trim();
}
let data = fs::read_to_string(path).expect("Error in reading data");
let mut current_brightness: i32 = data.trim().parse().unwrap();
let step = 40;
match &str[..] {
"up" => current_brightness += step,
"down" => current_brightness -= step,
_ => current_brightness = 100,
}
if current_brightness > max_brightness {
current_brightness = max_brightness;
}
if current_brightness < 50 {
current_brightness = 50;
}
let br = current_brightness.to_string();
fs::write(path, br.as_bytes()).expect("Unable to write data to brightness");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment