Skip to content

Commit

Permalink
Merge pull request #49 from segrey/sync-access-to-console
Browse files Browse the repository at this point in the history
synchronize access to Console (fixes #48)
  • Loading branch information
mattn committed Jun 26, 2020
2 parents f1b5a0e + b6d341e commit f6c0098
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions colorable_windows.go
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"strconv"
"strings"
"sync"
"syscall"
"unsafe"

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)))

Expand Down

0 comments on commit f6c0098

Please sign in to comment.