From 26074f594d6e75e8679372fd00a47cdfc3e00e3a Mon Sep 17 00:00:00 2001 From: Andrey Makarov Date: Thu, 5 Dec 2019 16:42:20 +0300 Subject: 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 --- lib/pure/terminal.nim | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'lib/pure') 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 ") -- cgit 1.4.1-2-gfad0