Skip to content

Commit f6c0098

Browse files
authored
Merge pull request #49 from segrey/sync-access-to-console
synchronize access to Console (fixes #48)
2 parents f1b5a0e + b6d341e commit f6c0098

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

colorable_windows.go

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111
"strconv"
1212
"strings"
13+
"sync"
1314
"syscall"
1415
"unsafe"
1516

@@ -94,6 +95,7 @@ type Writer struct {
9495
oldattr word
9596
oldpos coord
9697
rest bytes.Buffer
98+
mutex sync.Mutex
9799
}
98100

99101
// NewColorable returns new instance of Writer which handles escape sequence from File.
@@ -433,6 +435,8 @@ func atoiWithDefault(s string, def int) (int, error) {
433435

434436
// Write writes data on console
435437
func (w *Writer) Write(data []byte) (n int, err error) {
438+
w.mutex.Lock()
439+
defer w.mutex.Unlock()
436440
var csbi consoleScreenBufferInfo
437441
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
438442

0 commit comments

Comments
 (0)