fixes #324 Fini() is not idempotent

This commit is contained in:
Garrett D'Amore 2020-08-30 19:00:54 -07:00
parent 2323e87243
commit 5216188a4f
2 changed files with 13 additions and 2 deletions

View File

@ -51,6 +51,8 @@ type cScreen struct {
oomode uint32 oomode uint32
cells CellBuffer cells CellBuffer
finiOnce sync.Once
sync.Mutex sync.Mutex
} }
@ -248,6 +250,10 @@ func (s *cScreen) DisableMouse() {
} }
func (s *cScreen) Fini() { func (s *cScreen) Fini() {
s.finiOnce.Do(s.finish)
}
func (s *cScreen) finish() {
s.Lock() s.Lock()
s.style = StyleDefault s.style = StyleDefault
s.curx = -1 s.curx = -1
@ -816,13 +822,13 @@ func (s *cScreen) sendVtStyle(style Style) {
r, g, b := fg.RGB() r, g, b := fg.RGB()
fmt.Fprintf(esc, vtSetFgRGB, r, g, b) fmt.Fprintf(esc, vtSetFgRGB, r, g, b)
} else if fg.Valid() { } else if fg.Valid() {
fmt.Fprintf(esc, vtSetFg, fg & 0xff) fmt.Fprintf(esc, vtSetFg, fg&0xff)
} }
if bg.IsRGB() { if bg.IsRGB() {
r, g, b := bg.RGB() r, g, b := bg.RGB()
fmt.Fprintf(esc, vtSetBgRGB, r, g, b) fmt.Fprintf(esc, vtSetBgRGB, r, g, b)
} else if bg.Valid() { } else if bg.Valid() {
fmt.Fprintf(esc, vtSetBg, bg & 0xff) fmt.Fprintf(esc, vtSetBg, bg&0xff)
} }
s.emitVtString(esc.String()) s.emitVtString(esc.String())
} }

View File

@ -113,6 +113,7 @@ type tScreen struct {
truecolor bool truecolor bool
escaped bool escaped bool
buttondn bool buttondn bool
finiOnce sync.Once
sync.Mutex sync.Mutex
} }
@ -443,6 +444,10 @@ outer:
} }
func (t *tScreen) Fini() { func (t *tScreen) Fini() {
t.finiOnce.Do(t.finish)
}
func (t *tScreen) finish() {
t.Lock() t.Lock()
defer t.Unlock() defer t.Unlock()