ed

[hare] The standard editor
Log | Files | Refs | README | LICENSE

commit 5008232d82dc0c154e00ff60085d35fcfb2c4bb1
parent 473245f0a1963396ae069fd167f707a42fa3600e
Author: Byron Torres <b@torresjrjr.com>
Date:   Mon, 20 May 2024 00:55:59 +0100

handle signals

Diffstat:
Minteraction.ha | 8++++++++
Mmain.ha | 7++++++-
2 files changed, 14 insertions(+), 1 deletion(-)

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);