rework acs map creation, move tscreen attributes so the reader knows which one are guarded by the mutex
1 files changed, 51 insertions(+), 55 deletions(-)

M tscreen.go
M tscreen.go +51 -55
@@ 52,7 52,7 @@ func NewTerminfoScreen() (Screen, error)
 	t := &tScreen{ti: ti}
 
 	t.keyexist, t.keycodes = prepareKeys(ti)
-	t.buildAcsMap()
+	t.acs = buildAcsMap(ti)
 	t.sigwinch = make(chan os.Signal, 10)
 	t.fallback = make(map[rune]string)
 	for k, v := range RuneFallbacks {

          
@@ 115,12 115,10 @@ func NewTerminfoScreen() (Screen, error)
 
 	t.quit = make(chan struct{})
 
-	t.cx = -1
-	t.cy = -1
+	t.cx, t.cy = -1, -1
 	t.style = StyleDefault
 	t.cells.Resize(w, h)
-	t.cursorx = -1
-	t.cursory = -1
+	t.cursorx, t.cursory = -1, -1
 	t.resize()
 
 	go t.mainLoop()

          
@@ 137,17 135,29 @@ type tKeyCode struct {
 
 // tScreen represents a screen backed by a terminfo implementation.
 type tScreen struct {
-	ti       *terminfo.Terminfo
-	hasMouse bool
-	// in, out  *os.File
-	// baud     int
-	//	tiosp     *termiosPrivate
-	term     *terminal
+	ti   *terminfo.Terminfo
+	term *terminal
+
 	evch     chan Event
 	sigwinch chan os.Signal
-	keyexist map[Key]bool
-	keycodes map[string]*tKeyCode
+	indoneq  chan struct{}
+
+	acs       map[rune]string
+	keyexist  map[Key]bool
+	keycodes  map[string]*tKeyCode
+	keychan   chan []byte
+	keytimer  *time.Timer
+	keyexpire time.Time
 
+	charset          string
+	encoder, decoder transform.Transformer
+
+	truecolor bool
+	hasMouse  bool
+
+	palette []Color
+
+	// guards data below
 	sync.Mutex
 
 	h, w  int

          
@@ 155,34 165,22 @@ type tScreen struct {
 	// current style when drawing. if the style between cells does not change
 	// no style attributes have to be written to the terminal
 	//	curstyle Style
-	style   Style
-	fini    bool
-	cursorx int
-	cursory int
-	quit    chan struct{}
-	indoneq chan struct{}
+	style            Style
+	quit             chan struct{}
+	cursorx, cursory int
+	cx, cy           int
+	clear            bool
+	fini             bool
+	fallback         map[rune]string
+
+	colors map[Color]Color
 
 	// maybe
-	keychan   chan []byte
-	keytimer  *time.Timer
-	keyexpire time.Time
-	cx        int
-	cy        int
-	clear     bool
-	//	cursorx   int
-	//	cursory   int
+
+	wasbtn bool
 
-	wasbtn    bool
-	acs       map[rune]string
-	charset   string
-	encoder   transform.Transformer
-	decoder   transform.Transformer
-	fallback  map[rune]string
-	colors    map[Color]Color
-	palette   []Color
-	truecolor bool
-	escaped   bool
-	buttondn  bool
+	escaped  bool
+	buttondn bool
 }
 
 func (t *tScreen) Fini() {

          
@@ 608,23 606,6 @@ var vtACSNames = map[byte]rune{
 	'~': RuneBullet,
 }
 
-// buildAcsMap builds a map of characters that we translate from Unicode to
-// alternate character encodings.  To do this, we use the standard VT100 ACS
-// maps.  This is only done if the terminal lacks support for Unicode; we
-// always prefer to emit Unicode glyphs when we are able.
-func (t *tScreen) buildAcsMap() {
-	acsstr := t.ti.AltChars
-	t.acs = make(map[rune]string)
-	for len(acsstr) > 2 {
-		srcv := acsstr[0]
-		dstv := string(acsstr[1])
-		if r, ok := vtACSNames[srcv]; ok {
-			t.acs[r] = t.ti.EnterAcs + dstv + t.ti.ExitAcs
-		}
-		acsstr = acsstr[2:]
-	}
-}
-
 func (t *tScreen) PostEventWait(ev Event) {
 	t.evch <- ev
 }

          
@@ 1178,6 1159,21 @@ func (t *tScreen) HasKey(k Key) bool {
 
 func (t *tScreen) Resize(int, int, int, int) {}
 
+// buildAcsMap builds a map of characters that we translate from Unicode to
+// alternate character encodings.  To do this, we use the standard VT100 ACS
+// maps.  This is only done if the terminal lacks support for Unicode; we
+// always prefer to emit Unicode glyphs when we are able.
+func buildAcsMap(ti *terminfo.Terminfo) map[rune]string {
+	// todo: what if len(acs) is uneven?
+	acs := make(map[rune]string)
+	for acsstr := ti.AltChars; len(acsstr) > 2; acsstr = acsstr[2:] {
+		if r, ok := vtACSNames[acsstr[0]]; ok {
+			acs[r] = ti.EnterAcs + string(acsstr[1]) + ti.ExitAcs
+		}
+	}
+	return acs
+}
+
 func prepareKeys(ti *terminfo.Terminfo) (map[Key]bool, map[string]*tKeyCode) {
 
 	type key struct {