Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nimgrep improvements #12779

Merged
merged 2 commits into from
Dec 5, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix sticky colors in styledWrite
  • Loading branch information
a-mr committed Nov 29, 2019
commit ef2997dedda1448d390bf204c4a6fac3d25fa596
17 changes: 12 additions & 5 deletions lib/pure/terminal.nim
Original file line number Diff line number Diff line change
@@ -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 ")