From b6d341e0a4417c5ff678b4a84e9287b95feab311 Mon Sep 17 00:00:00 2001 From: Sergey Simonchik Date: Tue, 28 Apr 2020 00:25:12 +0300 Subject: [PATCH] synchronize access to Console (fixes #48) --- colorable_windows.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/colorable_windows.go b/colorable_windows.go index d9967cd..04c4229 100644 --- a/colorable_windows.go +++ b/colorable_windows.go @@ -10,6 +10,7 @@ import ( "os" "strconv" "strings" + "sync" "syscall" "unsafe" @@ -94,6 +95,7 @@ type Writer struct { oldattr word oldpos coord rest bytes.Buffer + mutex sync.Mutex } // NewColorable returns new instance of Writer which handles escape sequence from File. @@ -433,6 +435,8 @@ func atoiWithDefault(s string, def int) (int, error) { // Write writes data on console func (w *Writer) Write(data []byte) (n int, err error) { + w.mutex.Lock() + defer w.mutex.Unlock() var csbi consoleScreenBufferInfo procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))