1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-03 00:57:52 +02:00
Files
.devcontainer
.github
.vscode
cmd
docs
pkg
app
cheatsheet
commands
git_commands
git_config
hosting_service
models
oscommands
cmd_obj.go
cmd_obj_builder.go
cmd_obj_runner.go
cmd_obj_runner_default.go
cmd_obj_runner_win.go
copy.go
dummies.go
fake_cmd_obj_runner.go
gui_io.go
os.go
os_default_platform.go
os_test.go
os_test_default.go
os_test_windows.go
os_windows.go
patch
testdata
types
git.go
git_cmd_obj_builder.go
git_cmd_obj_runner.go
git_test.go
common
config
constants
env
gui
i18n
integration
logs
secureexec
snake
tasks
test
theme
updates
utils
scripts
test
uffizzi
vendor
.gitignore
.golangci.yml
.goreleaser.yml
CODE-OF-CONDUCT.md
CONTRIBUTING.md
Dockerfile
LICENSE
README.md
go.mod
go.sum
main.go
lazygit/pkg/commands/oscommands/cmd_obj_runner_win.go
Jesse Duffield 755ae0ef84 add deadlock mutex package
write to deadlock stderr after closing gocui

more deadlock checking
2022-08-07 11:16:14 +10:00

52 lines
1.3 KiB
Go

//go:build windows
// +build windows
package oscommands
import (
"bytes"
"io"
"os/exec"
"github.com/sasha-s/go-deadlock"
)
type Buffer struct {
b bytes.Buffer
m deadlock.Mutex
}
func (b *Buffer) Read(p []byte) (n int, err error) {
b.m.Lock()
defer b.m.Unlock()
return b.b.Read(p)
}
func (b *Buffer) Write(p []byte) (n int, err error) {
b.m.Lock()
defer b.m.Unlock()
return b.b.Write(p)
}
// TODO: Remove this hack and replace it with a proper way to run commands live on windows. We still have an issue where if a password is requested, the request for a password is written straight to stdout because we can't control the stdout of a subprocess of a subprocess. Keep an eye on https://github.com/creack/pty/pull/109
func (self *cmdObjRunner) getCmdHandler(cmd *exec.Cmd) (*cmdHandler, error) {
stdoutReader, stdoutWriter := io.Pipe()
cmd.Stdout = stdoutWriter
buf := &Buffer{}
cmd.Stdin = buf
if err := cmd.Start(); err != nil {
return nil, err
}
// because we don't yet have windows support for a pty, we instead just
// pass our standard stream handlers and because there's no pty to close
// we pass a no-op function for that.
return &cmdHandler{
stdoutPipe: stdoutReader,
stdinPipe: buf,
close: func() error { return nil },
}, nil
}