Colors!
This commit is contained in:
parent
6820b2fea9
commit
8beed96106
4 changed files with 55 additions and 30 deletions
|
|
@ -532,6 +532,9 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) =
|
||||||
of "genscript":
|
of "genscript":
|
||||||
expectNoArg(switch, arg, pass, info)
|
expectNoArg(switch, arg, pass, info)
|
||||||
incl(gGlobalOptions, optGenScript)
|
incl(gGlobalOptions, optGenScript)
|
||||||
|
of "usecolors":
|
||||||
|
expectNoArg(switch, arg, pass, info)
|
||||||
|
incl(gGlobalOptions, optUseColors)
|
||||||
of "lib":
|
of "lib":
|
||||||
expectArg(switch, arg, pass, info)
|
expectArg(switch, arg, pass, info)
|
||||||
libpath = processPath(arg, notRelativeToProj=true)
|
libpath = processPath(arg, notRelativeToProj=true)
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
# nim files.
|
# nim files.
|
||||||
|
|
||||||
import
|
import
|
||||||
lists, ropes, os, strutils, osproc, platform, condsyms, options, msgs, crc
|
lists, ropes, os, strutils, osproc, platform, condsyms, options, msgs, crc, terminal
|
||||||
|
|
||||||
type
|
type
|
||||||
TSystemCC* = enum
|
TSystemCC* = enum
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
import
|
import
|
||||||
options, strutils, os, tables, ropes, platform
|
options, strutils, os, tables, ropes, platform, terminal
|
||||||
|
|
||||||
type
|
type
|
||||||
TMsgKind* = enum
|
TMsgKind* = enum
|
||||||
|
|
@ -601,13 +601,13 @@ proc suggestQuit*() =
|
||||||
# this format is understood by many text editors: it is the same that
|
# this format is understood by many text editors: it is the same that
|
||||||
# Borland and Freepascal use
|
# Borland and Freepascal use
|
||||||
const
|
const
|
||||||
PosErrorFormat* = "$1($2, $3) Error: $4"
|
PosErrorFormat* = "$1($2, $3) Error: "
|
||||||
PosWarningFormat* = "$1($2, $3) Warning: $4"
|
PosWarningFormat* = "$1($2, $3) Warning: "
|
||||||
PosHintFormat* = "$1($2, $3) Hint: $4"
|
PosHintFormat* = "$1($2, $3) Hint: "
|
||||||
PosContextFormat = "$1($2, $3) Info: $4"
|
PosContextFormat = "$1($2, $3) Info: "
|
||||||
RawErrorFormat* = "Error: $1"
|
RawError* = "Error: "
|
||||||
RawWarningFormat* = "Warning: $1"
|
RawWarning* = "Warning: "
|
||||||
RawHintFormat* = "Hint: $1"
|
RawHint* = "Hint: "
|
||||||
|
|
||||||
proc getInfoContextLen*(): int = return msgContext.len
|
proc getInfoContextLen*(): int = return msgContext.len
|
||||||
proc setInfoContextLen*(L: int) = setLen(msgContext, L)
|
proc setInfoContextLen*(L: int) = setLen(msgContext, L)
|
||||||
|
|
@ -682,17 +682,27 @@ proc outWriteln*(s: string) =
|
||||||
## Writes to stdout. Always.
|
## Writes to stdout. Always.
|
||||||
if eStdOut in errorOutputs: writeln(stdout, s)
|
if eStdOut in errorOutputs: writeln(stdout, s)
|
||||||
|
|
||||||
proc msgWriteln*(s: string) =
|
proc msgWriteln*(s: string, color: ForegroundColor = fgWhite, coloredText: string = "") =
|
||||||
## Writes to stdout. If --stdout option is given, writes to stderr instead.
|
## Writes to stdout. If --stderr option is given, writes to stderr instead.
|
||||||
|
|
||||||
#if gCmd == cmdIdeTools and optCDebug notin gGlobalOptions: return
|
#if gCmd == cmdIdeTools and optCDebug notin gGlobalOptions: return
|
||||||
|
|
||||||
|
var hasColor = optUseColors in gGlobalOptions
|
||||||
if not isNil(writelnHook):
|
if not isNil(writelnHook):
|
||||||
writelnHook(s)
|
writelnHook(coloredText & s)
|
||||||
elif optStdout in gGlobalOptions:
|
|
||||||
if eStdErr in errorOutputs: writeln(stderr, s)
|
|
||||||
else:
|
else:
|
||||||
if eStdOut in errorOutputs: writeln(stdout, s)
|
if optStdout in gGlobalOptions:
|
||||||
|
if eStdErr in errorOutputs:
|
||||||
|
if hasColor: setForegroundColor(color)
|
||||||
|
write(stderr, coloredText)
|
||||||
|
if hasColor: resetAttributes()
|
||||||
|
writeln(stderr, s)
|
||||||
|
else:
|
||||||
|
if eStdOut in errorOutputs:
|
||||||
|
if hasColor: setForegroundColor(color)
|
||||||
|
write(stdout, coloredText)
|
||||||
|
if hasColor: resetAttributes()
|
||||||
|
writeln(stdout, s)
|
||||||
|
|
||||||
proc coordToStr(coord: int): string =
|
proc coordToStr(coord: int): string =
|
||||||
if coord == -1: result = "???"
|
if coord == -1: result = "???"
|
||||||
|
|
@ -714,7 +724,7 @@ proc handleError(msg: TMsgKind, eh: TErrorHandling, s: string) =
|
||||||
if stackTraceAvailable() and isNil(writelnHook):
|
if stackTraceAvailable() and isNil(writelnHook):
|
||||||
writeStackTrace()
|
writeStackTrace()
|
||||||
else:
|
else:
|
||||||
msgWriteln("No stack traceback available\nTo create a stacktrace, rerun compilation with ./koch temp " & options.command & " <file>")
|
msgWriteln("", fgRed, "No stack traceback available\nTo create a stacktrace, rerun compilation with ./koch temp " & options.command & " <file>")
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
if msg >= fatalMin and msg <= fatalMax:
|
if msg >= fatalMin and msg <= fatalMax:
|
||||||
|
|
@ -746,25 +756,30 @@ proc ignoreMsgBecauseOfIdeTools(msg: TMsgKind): bool =
|
||||||
msg >= errGenerated and gCmd == cmdIdeTools and optIdeDebug notin gGlobalOptions
|
msg >= errGenerated and gCmd == cmdIdeTools and optIdeDebug notin gGlobalOptions
|
||||||
|
|
||||||
proc rawMessage*(msg: TMsgKind, args: openArray[string]) =
|
proc rawMessage*(msg: TMsgKind, args: openArray[string]) =
|
||||||
var frmt: string
|
var
|
||||||
|
frmt: string
|
||||||
|
color: ForegroundColor
|
||||||
case msg
|
case msg
|
||||||
of errMin..errMax:
|
of errMin..errMax:
|
||||||
writeContext(unknownLineInfo())
|
writeContext(unknownLineInfo())
|
||||||
frmt = RawErrorFormat
|
frmt = RawError
|
||||||
|
color = fgRed
|
||||||
of warnMin..warnMax:
|
of warnMin..warnMax:
|
||||||
if optWarns notin gOptions: return
|
if optWarns notin gOptions: return
|
||||||
if msg notin gNotes: return
|
if msg notin gNotes: return
|
||||||
writeContext(unknownLineInfo())
|
writeContext(unknownLineInfo())
|
||||||
frmt = RawWarningFormat
|
frmt = RawWarning
|
||||||
inc(gWarnCounter)
|
inc(gWarnCounter)
|
||||||
|
color = fgYellow
|
||||||
of hintMin..hintMax:
|
of hintMin..hintMax:
|
||||||
if optHints notin gOptions: return
|
if optHints notin gOptions: return
|
||||||
if msg notin gNotes: return
|
if msg notin gNotes: return
|
||||||
frmt = RawHintFormat
|
frmt = RawHint
|
||||||
inc(gHintCounter)
|
inc(gHintCounter)
|
||||||
let s = `%`(frmt, `%`(msgKindToString(msg), args))
|
color = fgGreen
|
||||||
|
let s = `%`(msgKindToString(msg), args)
|
||||||
if not ignoreMsgBecauseOfIdeTools(msg):
|
if not ignoreMsgBecauseOfIdeTools(msg):
|
||||||
msgWriteln(s)
|
msgWriteln(s, color, frmt)
|
||||||
handleError(msg, doAbort, s)
|
handleError(msg, doAbort, s)
|
||||||
|
|
||||||
proc rawMessage*(msg: TMsgKind, arg: string) =
|
proc rawMessage*(msg: TMsgKind, arg: string) =
|
||||||
|
|
@ -785,8 +800,10 @@ proc formatMsg*(info: TLineInfo, msg: TMsgKind, arg: string): string =
|
||||||
|
|
||||||
proc liMessage(info: TLineInfo, msg: TMsgKind, arg: string,
|
proc liMessage(info: TLineInfo, msg: TMsgKind, arg: string,
|
||||||
eh: TErrorHandling) =
|
eh: TErrorHandling) =
|
||||||
var frmt: string
|
var
|
||||||
var ignoreMsg = false
|
frmt: string
|
||||||
|
ignoreMsg = false
|
||||||
|
color: ForegroundColor
|
||||||
case msg
|
case msg
|
||||||
of errMin..errMax:
|
of errMin..errMax:
|
||||||
writeContext(info)
|
writeContext(info)
|
||||||
|
|
@ -795,22 +812,26 @@ proc liMessage(info: TLineInfo, msg: TMsgKind, arg: string,
|
||||||
# in the same file and line are produced:
|
# in the same file and line are produced:
|
||||||
#ignoreMsg = lastError == info and eh != doAbort
|
#ignoreMsg = lastError == info and eh != doAbort
|
||||||
lastError = info
|
lastError = info
|
||||||
|
color = fgRed
|
||||||
of warnMin..warnMax:
|
of warnMin..warnMax:
|
||||||
ignoreMsg = optWarns notin gOptions or msg notin gNotes
|
ignoreMsg = optWarns notin gOptions or msg notin gNotes
|
||||||
if not ignoreMsg: writeContext(info)
|
if not ignoreMsg: writeContext(info)
|
||||||
frmt = PosWarningFormat
|
frmt = PosWarningFormat
|
||||||
inc(gWarnCounter)
|
inc(gWarnCounter)
|
||||||
|
color = fgYellow
|
||||||
of hintMin..hintMax:
|
of hintMin..hintMax:
|
||||||
ignoreMsg = optHints notin gOptions or msg notin gNotes
|
ignoreMsg = optHints notin gOptions or msg notin gNotes
|
||||||
frmt = PosHintFormat
|
frmt = PosHintFormat
|
||||||
inc(gHintCounter)
|
inc(gHintCounter)
|
||||||
|
color = fgGreen
|
||||||
# NOTE: currently line info line numbers start with 1,
|
# NOTE: currently line info line numbers start with 1,
|
||||||
# but column numbers start with 0, however most editors expect
|
# but column numbers start with 0, however most editors expect
|
||||||
# first column to be 1, so we need to +1 here
|
# first column to be 1, so we need to +1 here
|
||||||
let s = frmt % [toMsgFilename(info), coordToStr(info.line),
|
let x = frmt % [toMsgFilename(info), coordToStr(info.line),
|
||||||
coordToStr(info.col+1), getMessageStr(msg, arg)]
|
coordToStr(info.col+1)]
|
||||||
|
let s = getMessageStr(msg, arg)
|
||||||
if not ignoreMsg and not ignoreMsgBecauseOfIdeTools(msg):
|
if not ignoreMsg and not ignoreMsgBecauseOfIdeTools(msg):
|
||||||
msgWriteln(s)
|
msgWriteln(s, color, x)
|
||||||
if optPrintSurroundingSrc and msg in errMin..errMax:
|
if optPrintSurroundingSrc and msg in errMin..errMax:
|
||||||
info.writeSurroundingSrc
|
info.writeSurroundingSrc
|
||||||
handleError(msg, eh, s)
|
handleError(msg, eh, s)
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ type # please make sure we have under 32 options
|
||||||
optSkipUserConfigFile, # skip the users's config file
|
optSkipUserConfigFile, # skip the users's config file
|
||||||
optSkipParentConfigFiles, # skip parent dir's config files
|
optSkipParentConfigFiles, # skip parent dir's config files
|
||||||
optNoMain, # do not generate a "main" proc
|
optNoMain, # do not generate a "main" proc
|
||||||
|
optUseColors, # use colors for hints, warnings, and errors
|
||||||
optThreads, # support for multi-threading
|
optThreads, # support for multi-threading
|
||||||
optStdout, # output to stdout
|
optStdout, # output to stdout
|
||||||
optThreadAnalysis, # thread analysis pass
|
optThreadAnalysis, # thread analysis pass
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue