Skip to content

Commit

Permalink
nimgrep improvements (nim-lang#12779)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
a-mr authored and Araq committed Dec 5, 2019
1 parent 0e7338d commit 26074f5
Show file tree
Hide file tree
Showing 2 changed files with 406 additions and 102 deletions.
17 changes: 12 additions & 5 deletions lib/pure/terminal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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"

Expand Down Expand Up @@ -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 ")
Expand Down
Loading

0 comments on commit 26074f5

Please sign in to comment.