colors for debugging (not for windows) (#10786)

This commit is contained in:
Arne Döring 2019-03-05 19:58:14 +01:00 • committed by Andreas Rumpf
commit 20a21aa184

View file

@ -353,6 +353,12 @@ proc symToYaml(conf: ConfigRef; n: PSym, indent: int = 0, maxRecDepth: int = - 1
import tables import tables
const backrefStyle = "\e[90m"
const enumStyle = "\e[34m"
const numberStyle = "\e[33m"
const stringStyle = "\e[32m"
const resetStyle = "\e[0m"
type type
DebugPrinter = object DebugPrinter = object
conf: ConfigRef conf: ConfigRef
@ -361,6 +367,7 @@ type
indent: int indent: int
currentLine: int currentLine: int
firstItem: bool firstItem: bool
useColor: bool
res: string res: string
proc indentMore(this: var DebugPrinter) = proc indentMore(this: var DebugPrinter) =
@ -407,15 +414,29 @@ proc key(this: var DebugPrinter; key: string) =
this.res.add "\": " this.res.add "\": "
proc value(this: var DebugPrinter; value: string) = proc value(this: var DebugPrinter; value: string) =
if this.useColor:
this.res.add stringStyle
this.res.add "\"" this.res.add "\""
this.res.add value this.res.add value
this.res.add "\"" this.res.add "\""
if this.useColor:
this.res.add resetStyle
proc value(this: var DebugPrinter; value: BiggestInt) = proc value(this: var DebugPrinter; value: BiggestInt) =
if this.useColor:
this.res.add numberStyle
this.res.add value this.res.add value
if this.useColor:
this.res.add resetStyle
proc value[T: enum](this: var DebugPrinter; value: T) = proc value[T: enum](this: var DebugPrinter; value: T) =
this.value $value if this.useColor:
this.res.add enumStyle
this.res.add "\""
this.res.add $value
this.res.add "\""
if this.useColor:
this.res.add resetStyle
proc value[T: enum](this: var DebugPrinter; value: set[T]) = proc value[T: enum](this: var DebugPrinter; value: set[T]) =
this.openBracket this.openBracket
@ -436,9 +457,13 @@ template earlyExit(this: var DebugPrinter; n: PType | PNode | PSym) =
if index < 0: if index < 0:
this.visited[cast[pointer](n)] = this.currentLine this.visited[cast[pointer](n)] = this.currentLine
else: else:
if this.useColor:
this.res.add backrefStyle
this.res.add "<defined " this.res.add "<defined "
this.res.add(this.currentLine - index) this.res.add(this.currentLine - index)
this.res.add " lines upwards>" this.res.add " lines upwards>"
if this.useColor:
this.res.add resetStyle
return return
proc value(this: var DebugPrinter; value: PType): void proc value(this: var DebugPrinter; value: PType): void
@ -448,7 +473,7 @@ proc value(this: var DebugPrinter; value: PSym): void =
this.openCurly this.openCurly
this.key("kind") this.key("kind")
this.value($value.kind) this.value(value.kind)
this.key("name") this.key("name")
this.value(value.name.s) this.value(value.name.s)
this.key("id") this.key("id")
@ -477,6 +502,7 @@ proc value(this: var DebugPrinter; value: PType): void =
if value.sym != nil: if value.sym != nil:
this.key "sym" this.key "sym"
this.value value.sym this.value value.sym
#this.value value.sym.name.s
if card(value.flags) > 0: if card(value.flags) > 0:
this.key "flags" this.key "flags"
@ -529,7 +555,8 @@ proc value(this: var DebugPrinter; value: PNode): void =
this.value value.strVal this.value value.strVal
of nkSym: of nkSym:
this.key "sym" this.key "sym"
this.value(value.sym) this.value value.sym
#this.value value.sym.name.s
of nkIdent: of nkIdent:
if value.ident != nil: if value.ident != nil:
this.key "ident" this.key "ident"
@ -554,6 +581,7 @@ when declared(echo):
var this: DebugPrinter var this: DebugPrinter
this.visited = initTable[pointer, int]() this.visited = initTable[pointer, int]()
this.renderSymType = true this.renderSymType = true
this.useColor = not defined(windows)
this.value(n) this.value(n)
echo($this.res) echo($this.res)
@ -561,6 +589,7 @@ when declared(echo):
var this: DebugPrinter var this: DebugPrinter
this.visited = initTable[pointer, int]() this.visited = initTable[pointer, int]()
this.renderSymType = true this.renderSymType = true
this.useColor = not defined(windows)
this.value(n) this.value(n)
echo($this.res) echo($this.res)
@ -568,6 +597,7 @@ when declared(echo):
var this: DebugPrinter var this: DebugPrinter
this.visited = initTable[pointer, int]() this.visited = initTable[pointer, int]()
this.renderSymType = true this.renderSymType = true
this.useColor = not defined(windows)
this.value(n) this.value(n)
echo($this.res) echo($this.res)