Merge pull request #5058 from johnnovak/terminal-win-fix
Fix setStyle for Windows
This commit is contained in:
commit
ab43ad13dc
1 changed files with 6 additions and 3 deletions
|
|
@ -31,6 +31,8 @@ when defined(windows):
|
||||||
BACKGROUND_GREEN = 32
|
BACKGROUND_GREEN = 32
|
||||||
BACKGROUND_RED = 64
|
BACKGROUND_RED = 64
|
||||||
BACKGROUND_INTENSITY = 128
|
BACKGROUND_INTENSITY = 128
|
||||||
|
FOREGROUND_RGB = FOREGROUND_RED or FOREGROUND_GREEN or FOREGROUND_BLUE
|
||||||
|
BACKGROUND_RGB = BACKGROUND_RED or BACKGROUND_GREEN or BACKGROUND_BLUE
|
||||||
|
|
||||||
type
|
type
|
||||||
SHORT = int16
|
SHORT = int16
|
||||||
|
|
@ -407,12 +409,13 @@ proc setStyle*(f: File, style: set[Style]) =
|
||||||
## Sets the terminal style.
|
## Sets the terminal style.
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
let h = conHandle(f)
|
let h = conHandle(f)
|
||||||
|
var old = getAttributes(h) and (FOREGROUND_RGB or BACKGROUND_RGB)
|
||||||
var a = 0'i16
|
var a = 0'i16
|
||||||
if styleBright in style: a = a or int16(FOREGROUND_INTENSITY)
|
if styleBright in style: a = a or int16(FOREGROUND_INTENSITY)
|
||||||
if styleBlink in style: a = a or int16(BACKGROUND_INTENSITY)
|
if styleBlink in style: a = a or int16(BACKGROUND_INTENSITY)
|
||||||
if styleReverse in style: a = a or 0x4000'i16 # COMMON_LVB_REVERSE_VIDEO
|
if styleReverse in style: a = a or 0x4000'i16 # COMMON_LVB_REVERSE_VIDEO
|
||||||
if styleUnderscore in style: a = a or 0x8000'i16 # COMMON_LVB_UNDERSCORE
|
if styleUnderscore in style: a = a or 0x8000'i16 # COMMON_LVB_UNDERSCORE
|
||||||
discard setConsoleTextAttribute(h, a)
|
discard setConsoleTextAttribute(h, old or a)
|
||||||
else:
|
else:
|
||||||
for s in items(style):
|
for s in items(style):
|
||||||
f.write("\e[" & $ord(s) & 'm')
|
f.write("\e[" & $ord(s) & 'm')
|
||||||
|
|
@ -461,7 +464,7 @@ proc setForegroundColor*(f: File, fg: ForegroundColor, bright=false) =
|
||||||
## Sets the terminal's foreground color.
|
## Sets the terminal's foreground color.
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
let h = conHandle(f)
|
let h = conHandle(f)
|
||||||
var old = getAttributes(h) and not 0x0007
|
var old = getAttributes(h) and not FOREGROUND_RGB
|
||||||
if bright:
|
if bright:
|
||||||
old = old or FOREGROUND_INTENSITY
|
old = old or FOREGROUND_INTENSITY
|
||||||
const lookup: array[ForegroundColor, int] = [
|
const lookup: array[ForegroundColor, int] = [
|
||||||
|
|
@ -483,7 +486,7 @@ proc setBackgroundColor*(f: File, bg: BackgroundColor, bright=false) =
|
||||||
## Sets the terminal's background color.
|
## Sets the terminal's background color.
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
let h = conHandle(f)
|
let h = conHandle(f)
|
||||||
var old = getAttributes(h) and not 0x0070
|
var old = getAttributes(h) and not BACKGROUND_RGB
|
||||||
if bright:
|
if bright:
|
||||||
old = old or BACKGROUND_INTENSITY
|
old = old or BACKGROUND_INTENSITY
|
||||||
const lookup: array[BackgroundColor, int] = [
|
const lookup: array[BackgroundColor, int] = [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue