From 5216188a4fa40f0c180a98f1e5d42f409207f3e9 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 30 Aug 2020 19:00:54 -0700 Subject: [PATCH] fixes #324 Fini() is not idempotent --- console_win.go | 10 ++++++++-- tscreen.go | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/console_win.go b/console_win.go index 811486b..e246a6c 100644 --- a/console_win.go +++ b/console_win.go @@ -51,6 +51,8 @@ type cScreen struct { oomode uint32 cells CellBuffer + finiOnce sync.Once + sync.Mutex } @@ -248,6 +250,10 @@ func (s *cScreen) DisableMouse() { } func (s *cScreen) Fini() { + s.finiOnce.Do(s.finish) +} + +func (s *cScreen) finish() { s.Lock() s.style = StyleDefault s.curx = -1 @@ -816,13 +822,13 @@ func (s *cScreen) sendVtStyle(style Style) { r, g, b := fg.RGB() fmt.Fprintf(esc, vtSetFgRGB, r, g, b) } else if fg.Valid() { - fmt.Fprintf(esc, vtSetFg, fg & 0xff) + fmt.Fprintf(esc, vtSetFg, fg&0xff) } if bg.IsRGB() { r, g, b := bg.RGB() fmt.Fprintf(esc, vtSetBgRGB, r, g, b) } else if bg.Valid() { - fmt.Fprintf(esc, vtSetBg, bg & 0xff) + fmt.Fprintf(esc, vtSetBg, bg&0xff) } s.emitVtString(esc.String()) } diff --git a/tscreen.go b/tscreen.go index 3e436aa..4ad6fa0 100644 --- a/tscreen.go +++ b/tscreen.go @@ -113,6 +113,7 @@ type tScreen struct { truecolor bool escaped bool buttondn bool + finiOnce sync.Once sync.Mutex } @@ -443,6 +444,10 @@ outer: } func (t *tScreen) Fini() { + t.finiOnce.Do(t.finish) +} + +func (t *tScreen) finish() { t.Lock() defer t.Unlock()