mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-22 08:51:21 +00:00
nimgrep improvements (#12779)
* fix sticky colors in styledWrite * nimgrep: context printing, colorthemes and other * add context printing (lines after and before a match) * nimgrep: add exclude/include options * nimgrep: improve error printing & symlink handling * nimgrep: rename dangerous `-r` argument * add a `--newLine` style option for starting matching/context lines from a new line * add color themes: 3 new themes besides default `simple` * enable printing of multi-line matches with line numbers * proper display of replace when there was another match replaced at the same line / context block * improve cmdline arguments error reporting
This commit is contained in:
committed by
Andreas Rumpf
parent
0e7338d65c
commit
26074f594d
@@ -458,6 +458,11 @@ proc eraseScreen*(f: File) =
|
||||
else:
|
||||
f.write("\e[2J")
|
||||
|
||||
when not defined(windows):
|
||||
var
|
||||
gFG {.threadvar.}: int
|
||||
gBG {.threadvar.}: int
|
||||
|
||||
proc resetAttributes*(f: File) =
|
||||
## Resets all attributes.
|
||||
when defined(windows):
|
||||
@@ -468,6 +473,8 @@ proc resetAttributes*(f: File) =
|
||||
discard setConsoleTextAttribute(term.hStdout, term.oldStdoutAttr)
|
||||
else:
|
||||
f.write(ansiResetCode)
|
||||
gFG = 0
|
||||
gBG = 0
|
||||
|
||||
type
|
||||
Style* = enum ## different styles for text output
|
||||
@@ -481,11 +488,6 @@ type
|
||||
styleHidden, ## hidden text
|
||||
styleStrikethrough ## strikethrough
|
||||
|
||||
when not defined(windows):
|
||||
var
|
||||
gFG {.threadvar.}: int
|
||||
gBG {.threadvar.}: int
|
||||
|
||||
proc ansiStyleCode*(style: int): string =
|
||||
result = fmt"{stylePrefix}{style}m"
|
||||
|
||||
@@ -938,6 +940,11 @@ when not defined(testing) and isMainModule:
|
||||
stdout.styledWriteLine(" ordinary text ")
|
||||
stdout.styledWriteLine(fgGreen, "green text")
|
||||
|
||||
writeStyled("underscored text", {styleUnderscore})
|
||||
stdout.styledWrite(fgRed, " red text ")
|
||||
writeStyled("bright text ", {styleBright})
|
||||
echo "ordinary text"
|
||||
|
||||
stdout.styledWrite(fgRed, "red text ")
|
||||
stdout.styledWrite(fgWhite, bgRed, "white text in red background")
|
||||
stdout.styledWrite(" ordinary text ")
|
||||
|
||||
Reference in New Issue
Block a user