1
0
mirror of https://github.com/gdamore/tcell.git synced 2025-04-26 13:48:53 +08:00

fixes #75 Add goreport and fix related issues (a couple more)

This commit is contained in:
Garrett D'Amore 2015-11-04 17:29:11 -08:00
parent 43f9cc0d07
commit f763a5b1b7
3 changed files with 52 additions and 67 deletions

View File

@ -28,13 +28,13 @@ import (
var row = 0 var row = 0
var style = tcell.StyleDefault var style = tcell.StyleDefault
func Putln(s tcell.Screen, str string) { func putln(s tcell.Screen, str string) {
Puts(s, style, 1, row, str) puts(s, style, 1, row, str)
row++ row++
} }
func Puts(s tcell.Screen, style tcell.Style, x, y int, str string) { func puts(s tcell.Screen, style tcell.Style, x, y int, str string) {
i := 0 i := 0
var deferred []rune var deferred []rune
dwidth := 0 dwidth := 0
@ -94,52 +94,52 @@ func main() {
quit := make(chan struct{}) quit := make(chan struct{})
style = bold style = bold
Putln(s, "Press ESC to Exit") putln(s, "Press ESC to Exit")
Putln(s, "Character set: "+s.CharacterSet()) putln(s, "Character set: "+s.CharacterSet())
style = plain style = plain
Putln(s, "English: October") putln(s, "English: October")
Putln(s, "Icelandic: október") putln(s, "Icelandic: október")
Putln(s, "Arabic: أكتوبر") putln(s, "Arabic: أكتوبر")
Putln(s, "Russian: октября") putln(s, "Russian: октября")
Putln(s, "Greek: Οκτωβρίου") putln(s, "Greek: Οκτωβρίου")
Putln(s, "Chinese: 十月 (note, two double wide characters)") putln(s, "Chinese: 十月 (note, two double wide characters)")
Putln(s, "Combining: A\u030a (should look like Angstrom)") putln(s, "Combining: A\u030a (should look like Angstrom)")
Putln(s, "Emoticon: \U0001f618 (blowing a kiss)") putln(s, "Emoticon: \U0001f618 (blowing a kiss)")
Putln(s, "Airplane: \u2708 (fly away)") putln(s, "Airplane: \u2708 (fly away)")
Putln(s, "Command: \u2318 (mac clover key)") putln(s, "Command: \u2318 (mac clover key)")
Putln(s, "Enclose: !\u20e3 (should be enclosed exclamation)") putln(s, "Enclose: !\u20e3 (should be enclosed exclamation)")
Putln(s, "") putln(s, "")
Putln(s, "Box:") putln(s, "Box:")
Putln(s, string([]rune{ putln(s, string([]rune{
tcell.RuneULCorner, tcell.RuneULCorner,
tcell.RuneHLine, tcell.RuneHLine,
tcell.RuneTTee, tcell.RuneTTee,
tcell.RuneHLine, tcell.RuneHLine,
tcell.RuneURCorner, tcell.RuneURCorner,
})) }))
Putln(s, string([]rune{ putln(s, string([]rune{
tcell.RuneVLine, tcell.RuneVLine,
tcell.RuneBullet, tcell.RuneBullet,
tcell.RuneVLine, tcell.RuneVLine,
tcell.RuneLantern, tcell.RuneLantern,
tcell.RuneVLine, tcell.RuneVLine,
})+" (bullet, lantern/section)") })+" (bullet, lantern/section)")
Putln(s, string([]rune{ putln(s, string([]rune{
tcell.RuneLTee, tcell.RuneLTee,
tcell.RuneHLine, tcell.RuneHLine,
tcell.RunePlus, tcell.RunePlus,
tcell.RuneHLine, tcell.RuneHLine,
tcell.RuneRTee, tcell.RuneRTee,
})) }))
Putln(s, string([]rune{ putln(s, string([]rune{
tcell.RuneVLine, tcell.RuneVLine,
tcell.RuneDiamond, tcell.RuneDiamond,
tcell.RuneVLine, tcell.RuneVLine,
tcell.RuneUArrow, tcell.RuneUArrow,
tcell.RuneVLine, tcell.RuneVLine,
})+" (diamond, up arrow)") })+" (diamond, up arrow)")
Putln(s, string([]rune{ putln(s, string([]rune{
tcell.RuneLLCorner, tcell.RuneLLCorner,
tcell.RuneHLine, tcell.RuneHLine,
tcell.RuneBTee, tcell.RuneBTee,

View File

@ -125,17 +125,17 @@ func (s *cScreen) Init() error {
s.evch = make(chan Event, 10) s.evch = make(chan Event, 10)
s.quit = make(chan struct{}) s.quit = make(chan struct{})
if in, e := syscall.Open("CONIN$", syscall.O_RDWR, 0); e != nil { in, e := syscall.Open("CONIN$", syscall.O_RDWR, 0)
if e != nil {
return e return e
} else {
s.in = in
} }
if out, e := syscall.Open("CONOUT$", syscall.O_RDWR, 0); e != nil { s.in = in
out, e := syscall.Open("CONOUT$", syscall.O_RDWR, 0)
if e != nil {
syscall.Close(s.in) syscall.Close(s.in)
return e return e
} else {
s.out = out
} }
s.out = out
s.Lock() s.Lock()

View File

@ -83,50 +83,35 @@ const (
AttrReverse AttrReverse
) )
func fixColor(c tcell.Color) tcell.Color {
if c == tcell.ColorDefault {
return c
}
switch outMode {
case OutputNormal:
c %= tcell.Color(16)
case Output256:
c %= tcell.Color(256)
case Output216:
c %= tcell.Color(216)
c += tcell.Color(16)
case OutputGrayscale:
c %= tcell.Color(24)
c += tcell.Color(232)
default:
c = tcell.ColorDefault
}
return c
}
func mkStyle(fg, bg Attribute) tcell.Style { func mkStyle(fg, bg Attribute) tcell.Style {
st := tcell.StyleDefault st := tcell.StyleDefault
f := tcell.Color(int(fg)&0x1ff) - 1 f := tcell.Color(int(fg)&0x1ff) - 1
b := tcell.Color(int(bg)&0x1ff) - 1 b := tcell.Color(int(bg)&0x1ff) - 1
switch outMode { f = fixColor(f)
case Output256: b = fixColor(b)
if f != tcell.ColorDefault {
f %= tcell.Color(256)
}
if b != tcell.ColorDefault {
b %= tcell.Color(256)
}
break
case Output216:
if f != tcell.ColorDefault {
f %= tcell.Color(216)
f += tcell.Color(16)
}
if b != tcell.ColorDefault {
b %= tcell.Color(216)
b += tcell.Color(16)
}
case OutputGrayscale:
if f != tcell.ColorDefault {
f %= tcell.Color(24)
f += tcell.Color(232)
}
if b != tcell.ColorDefault {
b %= tcell.Color(24)
b += tcell.Color(232)
}
case OutputNormal:
if f != tcell.ColorDefault {
f %= tcell.Color(16)
}
if b != tcell.ColorDefault {
b %= tcell.Color(16)
}
default:
f = tcell.ColorDefault
b = tcell.ColorDefault
}
st = st.Foreground(f).Background(b) st = st.Foreground(f).Background(b)
if (fg|bg)&AttrBold != 0 { if (fg|bg)&AttrBold != 0 {
st = st.Bold(true) st = st.Bold(true)