commit fa9f7450158f7688a6bdb521848bd83e97924d42
parent 473245f0a1963396ae069fd167f707a42fa3600e
Author: Byron Torres <b@torresjrjr.com>
Date: Mon, 20 May 2024 00:55:59 +0100
handle signals
Diffstat:
3 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/global.ha b/global.ha
@@ -93,8 +93,6 @@ fn global(s: *Session, cmd: *Command, matched: bool) (void | Error) = {
s.buf.cursor = n;
let line = s.buf.lines[n];
- // TODO: handle termination by SIGINT signal
-
for (let i = 0z; i < len(subcmds); i += 1) {
let subcmd = subcmds[i];
//debug("cmd_global() for :marks execute()ing");
@@ -143,8 +141,6 @@ fn global_ia(s: *Session, cmd: *Command, matched: bool) (void | Error) = {
fmt::println(line.text)!;
- // TODO: handle termination by SIGINT signal
-
// TODO: handle mem
// TODO: just use 'parse()?' when compiler allows
//let subcmd = parse(s.input)?;
diff --git a/interaction.ha b/interaction.ha
@@ -4,6 +4,7 @@ use io;
use os;
use strings;
use types;
+use unix::signal;
type InteractionError = !(
Quit
@@ -25,3 +26,10 @@ fn scanline(s: *Session) (str | InteractionError) = {
return UnexpectedEOF;
};
};
+
+fn handle_signals() void = {
+ signal::handle(signal::sig::INT, &sig_ignore);
+ signal::handle(signal::sig::QUIT, &sig_ignore);
+};
+
+fn sig_ignore(s: signal::sig, i: *signal::siginfo, u: *opaque) void = void;
diff --git a/main.ha b/main.ha
@@ -87,6 +87,8 @@ export fn main() void = {
...
}): void;
+ handle_signals();
+
for (true) :repl {
if (s.promptmode)
fmt::error(s.prompt)!;
@@ -97,7 +99,10 @@ export fn main() void = {
case io::EOF =>
yield Command{ name = 'q', ... };
case let e: ParseError =>
- errormsg(&s, strerror(e));
+ errormsg(&s, e);
+ continue;
+ case let e: InteractionError =>
+ errormsg(&s, e);
continue;
};
defer command_finish(&cmd);