~smlavine/onclick

0260850464751a99cb2573cb751975babeb705ef — Sebastian LaVine 2 months ago 8289aae master
Handle potential exec errors
1 files changed, 12 insertions(+), 6 deletions(-)

M main.ha
M main.ha => main.ha +12 -6
@@ 74,7 74,9 @@ fn _cleanup(s: signal::sig, i: *signal::siginfo, u: *opaque) void = {
};

// Waits for mouse click input, then runs the provided command.
fn wait_then_run_command(in: io::handle, cmdargs: []str, cmdstr: str) void = {
fn wait_then_run_command(
	in: io::handle, cmdargs: []str, cmdstr: str,
) (void | exec::error) = {
	for (let sm: *states::state = &states::start; sm != &states::end) {
		// We have to keep an eye on loop because it could be modified
		// by the termination signals. We can't have this check in


@@ 122,8 124,8 @@ fn wait_then_run_command(in: io::handle, cmdargs: []str, cmdstr: str) void = {
	// Prints the command in bold.
	fmt::printfln("{}>> {}{}", "\x1B[1m", cmdstr, "\x1B[0m")!;

	let process = exec::start(&cmd)!;
	exec::wait(&process)!;
	let process = exec::start(&cmd)?;
	exec::wait(&process)?;

	// Aaand we're back. Our terminal now.
	prepare();


@@ 179,9 181,13 @@ export fn main() void = {

	prepare();

	defer cleanup();

	for (loop) {
		wait_then_run_command(tty, cli.args, cmdstr);
		match (wait_then_run_command(tty, cli.args, cmdstr)) {
		case void => void;
		case let e: exec::error =>
			fmt::fatal("Process error:", exec::strerror(e));
		};
	};

	cleanup();
};