addQuitProc => addExitProc (#16765)

This commit is contained in:
Timothee Cour 2021-01-22 10:51:11 -08:00 • committed by GitHub
commit 18b983d7e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 12 deletions

View file

@ -222,8 +222,9 @@ proc enableProfiling*() =
system.profilingRequestedHook = requestedHook system.profilingRequestedHook = requestedHook
when declared(system.StackTrace): when declared(system.StackTrace):
import std/exitprocs
system.profilingRequestedHook = requestedHook system.profilingRequestedHook = requestedHook
system.profilerHook = hook system.profilerHook = hook
addQuitProc(writeProfile) addExitProc(writeProfile)
{.pop.} {.pop.}

View file

@ -12,7 +12,7 @@
## sequences and does not depend on any other module, on Windows it uses the ## sequences and does not depend on any other module, on Windows it uses the
## Windows API. ## Windows API.
## Changing the style is permanent even after program termination! Use the ## Changing the style is permanent even after program termination! Use the
## code ``system.addQuitProc(resetAttributes)`` to restore the defaults. ## code `exitprocs.addExitProc(resetAttributes)` to restore the defaults.
## Similarly, if you hide the cursor, make sure to unhide it with ## Similarly, if you hide the cursor, make sure to unhide it with
## ``showCursor`` before quitting. ## ``showCursor`` before quitting.
@ -843,7 +843,7 @@ template setBackgroundColor*(color: Color) =
proc resetAttributes*() {.noconv.} = proc resetAttributes*() {.noconv.} =
## Resets all attributes on stdout. ## Resets all attributes on stdout.
## It is advisable to register this as a quit proc with ## It is advisable to register this as a quit proc with
## ``system.addQuitProc(resetAttributes)``. ## `exitprocs.addExitProc(resetAttributes)`.
resetAttributes(stdout) resetAttributes(stdout)
proc isTrueColorSupported*(): bool = proc isTrueColorSupported*(): bool =
@ -908,7 +908,7 @@ proc newTerminal(): owned(PTerminal) =
when not defined(testing) and isMainModule: when not defined(testing) and isMainModule:
assert ansiStyleCode(styleBright) == "\e[1m" assert ansiStyleCode(styleBright) == "\e[1m"
assert ansiStyleCode(styleStrikethrough) == "\e[9m" assert ansiStyleCode(styleStrikethrough) == "\e[9m"
#system.addQuitProc(resetAttributes) # exitprocs.addExitProc(resetAttributes)
write(stdout, "never mind") write(stdout, "never mind")
stdout.eraseLine() stdout.eraseLine()
stdout.styledWriteLine({styleBright, styleBlink, styleUnderscore}, "styled text ") stdout.styledWriteLine({styleBright, styleBlink, styleUnderscore}, "styled text ")

View file

@ -1462,7 +1462,6 @@ proc addQuitProc*(quitProc: proc() {.noconv.}) {.
## basis (that is, the last function registered is the first to be executed). ## basis (that is, the last function registered is the first to be executed).
## ``addQuitProc`` raises an EOutOfIndex exception if ``quitProc`` cannot be ## ``addQuitProc`` raises an EOutOfIndex exception if ``quitProc`` cannot be
## registered. ## registered.
# Support for addQuitProc() is done by Ansi C's facilities here. # Support for addQuitProc() is done by Ansi C's facilities here.
# In case of an unhandled exception the exit handlers should # In case of an unhandled exception the exit handlers should
# not be called explicitly! The user may decide to do this manually though. # not be called explicitly! The user may decide to do this manually though.

View file

@ -100,6 +100,7 @@ proc logPendingOps() {.noconv.} =
gLogger(gLog) gLogger(gLog)
gLog.count = 0 gLog.count = 0
addQuitProc logPendingOps import std/exitprocs
addExitProc logPendingOps
{.pop.} {.pop.}

View file

@ -7,6 +7,10 @@ contents thereof.
As said in the Olde Country, `Keepe it Gangster'.""" As said in the Olde Country, `Keepe it Gangster'."""
#[
xxx remove this? seems mostly duplicate of: tests/manyloc/nake/nake.nim
]#
import strutils, parseopt, tables, os import strutils, parseopt, tables, os
type type
@ -60,7 +64,8 @@ when true:
args.add " " args.add " "
quit(shell("nim", "c", "-r", "nakefile.nim", args)) quit(shell("nim", "c", "-r", "nakefile.nim", args))
else: else:
addQuitProc(proc() {.noconv.} = import std/exitprocs
addExitProc(proc() {.noconv.} =
var var
task: string task: string
printTaskList: bool printTaskList: bool

View file

@ -60,7 +60,8 @@ when true:
args.add " " args.add " "
quit(shell("nim", "c", "-r", "nakefile.nim", args)) quit(shell("nim", "c", "-r", "nakefile.nim", args))
else: else:
addQuitProc(proc() {.noconv.} = import std/exitprocs
addExitProc(proc() {.noconv.} =
var var
task: string task: string
printTaskList: bool printTaskList: bool

View file

@ -5,9 +5,11 @@ just exiting...
joinable: false joinable: false
""" """
# Test `addQuitProc` # Test `addQuitProc` (now deprecated by `addExitProc`)
proc myExit() {.noconv.} = proc myExit() {.noconv.} =
write(stdout, "just exiting...\n") write(stdout, "just exiting...\n")
{.push warning[deprecated]: off.}
addQuitProc(myExit) addQuitProc(myExit)
{.pop.}