如何在 nim 中处理 Ctrl-C 中断?

Cof*_*tle 6 nim-lang

如果我在程序运行时按 Ctrl-C,它会退出并打印SIGINT: Interrupted by Ctrl-C.

如何在 Linux 上的 Nim 中忽略 Ctrl-C 中断?提前致谢。

xbe*_*llo 7

您可以Ctrl+C使用setControlCHook控制行为:

proc ctrlc() {.noconv.} =
  echo "Ctrl+C fired!"

setControlCHook(ctrlc)
Run Code Online (Sandbox Code Playgroud)

现在CtrlC调用ctrlc程序。忽略 SIGINT 或清理房子并退出退出取决于该过程。