add an example to setControlCHook (#19416)

* add an example to setControlCHook

* [skip CI] format example for setControlCHook

Co-authored-by: Nathan Blaxall <nathan.blaxall@actionstep.com>
This commit is contained in:
nblaxall 2022-01-20 00:25:21 +13:00 • committed by GitHub
commit 23c4bbedcb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2319,6 +2319,15 @@ when notJSnotNims:
proc setControlCHook*(hook: proc () {.noconv.}) proc setControlCHook*(hook: proc () {.noconv.})
## Allows you to override the behaviour of your application when CTRL+C ## Allows you to override the behaviour of your application when CTRL+C
## is pressed. Only one such hook is supported. ## is pressed. Only one such hook is supported.
## Example:
##
## .. code-block:: Nim
## proc ctrlc() {.noconv.} =
## echo "Ctrl+C fired!"
## # do clean up stuff
## quit()
##
## setControlCHook(ctrlc)
when not defined(noSignalHandler) and not defined(useNimRtl): when not defined(noSignalHandler) and not defined(useNimRtl):
proc unsetControlCHook*() proc unsetControlCHook*()