Implement message suppression.
This commit is contained in:
parent
dcbbb8b62e
commit
8ebc4bb7c1
2 changed files with 29 additions and 5 deletions
|
|
@ -996,12 +996,18 @@ proc doAction(options: Options) =
|
|||
discard execHook(options, false)
|
||||
|
||||
when isMainModule:
|
||||
let error = ""
|
||||
when defined(release):
|
||||
try:
|
||||
parseCmdLine().doAction()
|
||||
except NimbleError:
|
||||
quit("FAILURE: " & getCurrentExceptionMsg())
|
||||
error = getCurrentExceptionMsg()
|
||||
finally:
|
||||
removeDir(getNimbleTempDir())
|
||||
else:
|
||||
parseCmdLine().doAction()
|
||||
|
||||
displayTip()
|
||||
if error.len > 0:
|
||||
display("Error", error, Error, HighPriority)
|
||||
quit(1)
|
||||
|
|
|
|||
|
|
@ -16,10 +16,12 @@ import logging, terminal, sets, strutils
|
|||
|
||||
type
|
||||
CLI* = ref object
|
||||
level: Priority
|
||||
warnings: HashSet[(string, string)]
|
||||
suppressionCount: int ## Amount of messages which were not shown.
|
||||
|
||||
Priority* = enum
|
||||
HighPriority, MediumPriority, LowPriority
|
||||
LowPriority, MediumPriority, HighPriority
|
||||
|
||||
DisplayType* = enum
|
||||
Error, Warning, Message, Success
|
||||
|
|
@ -28,12 +30,14 @@ const
|
|||
longestCategory = len("Downloading")
|
||||
foregrounds: array[Error .. Success, ForegroundColor] =
|
||||
[fgRed, fgYellow, fgCyan, fgGreen]
|
||||
styles: array[HighPriority .. LowPriority, set[Style]] =
|
||||
[{styleBright}, {}, {styleDim}]
|
||||
styles: array[LowPriority .. HighPriority, set[Style]] =
|
||||
[{styleDim}, {}, {styleBright}]
|
||||
|
||||
proc newCLI(): CLI =
|
||||
result = CLI(
|
||||
warnings: initSet[(string, string)]()
|
||||
level: HighPriority,
|
||||
warnings: initSet[(string, string)](),
|
||||
suppressionCount: 0
|
||||
)
|
||||
|
||||
var globalCLI = newCLI()
|
||||
|
|
@ -66,6 +70,11 @@ proc display*(category, msg: string, displayType = Message,
|
|||
else:
|
||||
globalCLI.warnings.incl(warningPair)
|
||||
|
||||
# Suppress this message if its priority isn't high enough.
|
||||
if priority < globalCLI.level:
|
||||
globalCLI.suppressionCount.inc
|
||||
return
|
||||
|
||||
# Display each line in the message.
|
||||
var i = 0
|
||||
for line in msg.splitLines():
|
||||
|
|
@ -73,6 +82,15 @@ proc display*(category, msg: string, displayType = Message,
|
|||
displayLine(if i == 0: category else: "...", line, displayType, priority)
|
||||
i.inc
|
||||
|
||||
proc displayTip*() =
|
||||
## Called just before Nimble exits. Shows some tips for the user, for example
|
||||
## the amount of messages that were suppressed and how to show them.
|
||||
if globalCLI.suppressionCount > 0:
|
||||
let msg = "$1 messages have been suppressed, use --verbose to show them." %
|
||||
$globalCLI.suppressionCount
|
||||
display("Tip", msg, Warning, HighPriority)
|
||||
|
||||
|
||||
when isMainModule:
|
||||
display("Reading", "config file at /Users/dom/.config/nimble/nimble.ini",
|
||||
priority = LowPriority)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue