Implement --noColor option.
This commit is contained in:
parent
c1ffe62a68
commit
d9f2e6c49e
2 changed files with 21 additions and 5 deletions
|
|
@ -19,6 +19,7 @@ type
|
||||||
level: Priority
|
level: Priority
|
||||||
warnings: HashSet[(string, string)]
|
warnings: HashSet[(string, string)]
|
||||||
suppressionCount: int ## Amount of messages which were not shown.
|
suppressionCount: int ## Amount of messages which were not shown.
|
||||||
|
showColor: bool ## Whether messages should be colored.
|
||||||
|
|
||||||
Priority* = enum
|
Priority* = enum
|
||||||
DebugPriority, LowPriority, MediumPriority, HighPriority
|
DebugPriority, LowPriority, MediumPriority, HighPriority
|
||||||
|
|
@ -40,7 +41,8 @@ proc newCLI(): CLI =
|
||||||
result = CLI(
|
result = CLI(
|
||||||
level: HighPriority,
|
level: HighPriority,
|
||||||
warnings: initSet[(string, string)](),
|
warnings: initSet[(string, string)](),
|
||||||
suppressionCount: 0
|
suppressionCount: 0,
|
||||||
|
showColor: true
|
||||||
)
|
)
|
||||||
|
|
||||||
var globalCLI = newCLI()
|
var globalCLI = newCLI()
|
||||||
|
|
@ -55,11 +57,16 @@ proc displayCategory(category: string, displayType: DisplayType,
|
||||||
# Calculate how much the `category` must be offset to align along a center
|
# Calculate how much the `category` must be offset to align along a center
|
||||||
# line.
|
# line.
|
||||||
let offset = calculateCategoryOffset(category)
|
let offset = calculateCategoryOffset(category)
|
||||||
|
|
||||||
# Display the category.
|
# Display the category.
|
||||||
if priority != DebugPriority:
|
let text = "$1$2 " % [spaces(offset), category]
|
||||||
setForegroundColor(stdout, foregrounds[displayType])
|
if globalCLI.showColor:
|
||||||
writeStyled("$1$2 " % [repeatChar(offset), category], styles[priority])
|
if priority != DebugPriority:
|
||||||
resetAttributes()
|
setForegroundColor(stdout, foregrounds[displayType])
|
||||||
|
writeStyled(text, styles[priority])
|
||||||
|
resetAttributes()
|
||||||
|
else:
|
||||||
|
stdout.write(text)
|
||||||
|
|
||||||
proc displayLine(category, line: string, displayType: DisplayType,
|
proc displayLine(category, line: string, displayType: DisplayType,
|
||||||
priority: Priority) =
|
priority: Priority) =
|
||||||
|
|
@ -145,6 +152,9 @@ proc promptCustom*(question, default: string): string =
|
||||||
proc setVerbosity*(level: Priority) =
|
proc setVerbosity*(level: Priority) =
|
||||||
globalCLI.level = level
|
globalCLI.level = level
|
||||||
|
|
||||||
|
proc setShowColor*(val: bool) =
|
||||||
|
globalCLI.showColor = val
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
display("Reading", "config file at /Users/dom/.config/nimble/nimble.ini",
|
display("Reading", "config file at /Users/dom/.config/nimble/nimble.ini",
|
||||||
priority = LowPriority)
|
priority = LowPriority)
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ type
|
||||||
pkgInfoCache*: TableRef[string, PackageInfo]
|
pkgInfoCache*: TableRef[string, PackageInfo]
|
||||||
showHelp*: bool
|
showHelp*: bool
|
||||||
showVersion*: bool
|
showVersion*: bool
|
||||||
|
noColor*: bool
|
||||||
|
|
||||||
ActionType* = enum
|
ActionType* = enum
|
||||||
actionNil, actionRefresh, actionInit, actionDump, actionPublish,
|
actionNil, actionRefresh, actionInit, actionDump, actionPublish,
|
||||||
|
|
@ -92,6 +93,7 @@ Options:
|
||||||
--nimbleDir:dirname Set the Nimble directory.
|
--nimbleDir:dirname Set the Nimble directory.
|
||||||
--verbose Show all non-debug output.
|
--verbose Show all non-debug output.
|
||||||
--debug Show all output including debug messages.
|
--debug Show all output including debug messages.
|
||||||
|
--noColor Don't colorise output.
|
||||||
|
|
||||||
For more information read the Github readme:
|
For more information read the Github readme:
|
||||||
https://github.com/nim-lang/nimble#readme
|
https://github.com/nim-lang/nimble#readme
|
||||||
|
|
@ -249,6 +251,7 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
|
||||||
of "nimbledir": result.nimbleDir = val
|
of "nimbledir": result.nimbleDir = val
|
||||||
of "verbose": result.verbosity = LowPriority
|
of "verbose": result.verbosity = LowPriority
|
||||||
of "debug": result.verbosity = DebugPriority
|
of "debug": result.verbosity = DebugPriority
|
||||||
|
of "nocolor": result.noColor = true
|
||||||
# Action-specific flags.
|
# Action-specific flags.
|
||||||
else:
|
else:
|
||||||
case result.action.typ
|
case result.action.typ
|
||||||
|
|
@ -318,6 +321,9 @@ proc parseCmdLine*(): Options =
|
||||||
# Set verbosity level.
|
# Set verbosity level.
|
||||||
setVerbosity(result.verbosity)
|
setVerbosity(result.verbosity)
|
||||||
|
|
||||||
|
# Set whether color should be shown.
|
||||||
|
setShowColor(not result.noColor)
|
||||||
|
|
||||||
# Parse config.
|
# Parse config.
|
||||||
result.config = parseConfig()
|
result.config = parseConfig()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue