fixes #119 Restore Windows terminal colors

This commit is contained in:
Garrett D'Amore 2016-10-19 14:21:13 -07:00
parent d94cafee62
commit c52de15673
1 changed files with 14 additions and 12 deletions

View File

@ -188,7 +188,7 @@ func (s *cScreen) Fini() {
s.setCursorPos(0, 0) s.setCursorPos(0, 0)
procSetConsoleTextAttribute.Call( procSetConsoleTextAttribute.Call(
uintptr(s.out), uintptr(s.out),
uintptr(mapStyle(StyleDefault))) uintptr(s.mapStyle(StyleDefault)))
close(s.quit) close(s.quit)
syscall.Close(s.in) syscall.Close(s.in)
@ -618,24 +618,26 @@ func mapColor2RGB(c Color) uint16 {
} }
// Map a tcell style to Windows attributes // Map a tcell style to Windows attributes
func mapStyle(style Style) uint16 { func (s *cScreen) mapStyle(style Style) uint16 {
f, b, a := style.Decompose() f, b, a := style.Decompose()
if f == ColorDefault { fa := s.oscreen.attrs & 0xf
f = ColorWhite ba := (s.oscreen.attrs) >> 4 & 0xf
if f != ColorDefault {
fa = mapColor2RGB(f)
} }
if b == ColorDefault { if b != ColorDefault {
b = ColorBlack ba = mapColor2RGB(b)
} }
var attr uint16 var attr uint16
// We simulate reverse by doing the color swap ourselves. // We simulate reverse by doing the color swap ourselves.
// Apparently windows cannot really do this except in DBCS // Apparently windows cannot really do this except in DBCS
// views. // views.
if a&AttrReverse != 0 { if a&AttrReverse != 0 {
attr = mapColor2RGB(b) attr = ba
attr |= (mapColor2RGB(f) << 4) attr |= (fa << 4)
} else { } else {
attr = mapColor2RGB(f) attr = fa
attr |= (mapColor2RGB(b) << 4) attr |= (ba << 4)
} }
if a&AttrBold != 0 { if a&AttrBold != 0 {
attr |= 0x8 attr |= 0x8
@ -683,7 +685,7 @@ func (s *cScreen) writeString(x, y int, style Style, ch []uint16) {
nw := uint32(len(ch)) nw := uint32(len(ch))
procSetConsoleTextAttribute.Call( procSetConsoleTextAttribute.Call(
uintptr(s.out), uintptr(s.out),
uintptr(mapStyle(style))) uintptr(s.mapStyle(style)))
s.setCursorPos(x, y) s.setCursorPos(x, y)
syscall.WriteConsole(s.out, &ch[0], nw, &nw, nil) syscall.WriteConsole(s.out, &ch[0], nw, &nw, nil)
} }
@ -859,7 +861,7 @@ func (s *cScreen) Fill(r rune, style Style) {
func (s *cScreen) clearScreen(style Style) { func (s *cScreen) clearScreen(style Style) {
pos := coord{0, 0} pos := coord{0, 0}
attr := mapStyle(style) attr := s.mapStyle(style)
x, y := s.w, s.h x, y := s.w, s.h
scratch := uint32(0) scratch := uint32(0)
count := uint32(x * y) count := uint32(x * y)