diff options
author | Andrey Makarov <ph.makarov@gmail.com> | 2019-12-05 16:42:20 +0300 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-12-05 14:42:20 +0100 |
commit | 26074f594d6e75e8679372fd00a47cdfc3e00e3a (patch) | |
tree | c7853aa0de791e21451ae4410be4bd002696e38b /lib/pure | |
parent | 0e7338d65c1bd6c4e2211fa531982a4c0a0e478c (diff) | |
download | Nim-26074f594d6e75e8679372fd00a47cdfc3e00e3a.tar.gz |
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
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/terminal.nim | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/pure/terminal.nim b/lib/pure/terminal.nim index 9d1d055fd..e798bbaf1 100644 --- a/lib/pure/terminal.nim +++ b/lib/pure/terminal.nim @@ -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 ") |