Skip to content

Commit

Permalink
synchronize access to Console (fixes mattn#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
segrey committed Jun 25, 2020
1 parent f1b5a0e commit 0ef2a7a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions colorable_windows.go
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"strconv"
"strings"
"sync"
"syscall"
"unsafe"

Expand Down Expand Up @@ -431,8 +432,14 @@ func atoiWithDefault(s string, def int) (int, error) {
return strconv.Atoi(s)
}

var (
writeMutex sync.Mutex
)

// Write writes data on console
func (w *Writer) Write(data []byte) (n int, err error) {
writeMutex.Lock()
defer writeMutex.Unlock()
var csbi consoleScreenBufferInfo
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))

Expand Down

0 comments on commit 0ef2a7a

Please sign in to comment.