Prevent output of brightness/sleep command showing on screen (fixing #695) (#699)

* Prevent output of brightness cmds showing on screen (fixing #695)

* Prevent output of sleep cmd showing on screen
This commit is contained in:
Moritz 2024-10-01 20:32:30 +02:00 committed by GitHub
parent 215ca5edc7
commit aea95b7724
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 19 additions and 7 deletions

View File

@ -580,14 +580,26 @@ pub fn main() !void {
} else if (pressed_key == sleep_key) {
if (config.sleep_cmd) |sleep_cmd| {
var sleep = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", sleep_cmd }, allocator);
_ = sleep.spawnAndWait() catch .{};
sleep.stdout_behavior = .Ignore;
sleep.stderr_behavior = .Ignore;
_ = sleep.spawnAndWait() catch {};
}
} else if (pressed_key == brightness_down_key or pressed_key == brightness_up_key) {
const cmd = if (pressed_key == brightness_down_key) config.brightness_down_cmd else config.brightness_up_cmd;
var brightness = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", cmd }, allocator);
brightness.stdout_behavior = .Ignore;
brightness.stderr_behavior = .Ignore;
handle_brightness_cmd: {
const process_result = brightness.spawnAndWait() catch {
break :handle_brightness_cmd;
};
if (process_result.Exited != 0) {
try info_line.addMessage(lang.err_brightness_change, config.error_bg, config.error_fg);
}
}
} else if (pressed_key == brightness_down_key) {
var brightness = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", config.brightness_down_cmd }, allocator);
_ = brightness.spawnAndWait() catch .{};
} else if (pressed_key == brightness_up_key) {
var brightness = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", config.brightness_up_cmd }, allocator);
_ = brightness.spawnAndWait() catch .{};
}
},
termbox.TB_KEY_CTRL_C => run = false,