Skip to content

Commit

Permalink
Fix rendering to main view on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSav authored and jesseduffield committed Jul 21, 2023
1 parent 39c900c commit a7969ae
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions pkg/tasks/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,20 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p
scanner := bufio.NewScanner(r)
scanner.Split(bufio.ScanLines)

data := make(chan []byte)

// We're reading from the scanner in a separate goroutine because on windows
// if running git through a shim, we sometimes kill the parent process without
// killing its children, meaning the scanner blocks forever. This solution
// leaves us with a dead goroutine, but it's better than blocking all
// rendering to main views.
go utils.Safe(func() {
for scanner.Scan() {
data <- scanner.Bytes()
}
close(data)
})

loaded := false

go utils.Safe(func() {
Expand Down Expand Up @@ -203,13 +217,15 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p
break outer
case linesToRead := <-self.readLines:
for i := 0; i < linesToRead.Total; i++ {
var ok bool
var line []byte
select {
case <-opts.Stop:
break outer
default:
case line, ok = <-data:
break
}

ok := scanner.Scan()
loadingMutex.Lock()
if !loaded {
self.beforeStart()
Expand All @@ -226,7 +242,7 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p
self.onEndOfInput()
break outer
}
writeToView(append(scanner.Bytes(), '\n'))
writeToView(append(line, '\n'))

if i+1 == linesToRead.InitialRefreshAfter {
// We have read enough lines to fill the view, so do a first refresh
Expand Down

0 comments on commit a7969ae

Please sign in to comment.