Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

synchronize access to Console (fixes #48) #49

Merged
merged 1 commit into from Jun 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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