Skip to content

Commit

Permalink
Size child process ptys correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
pjeby authored and cespare committed Jun 2, 2018
1 parent a88689e commit 5bbd606
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions reflex.go
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"os"
"os/exec"
"os/signal"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -273,6 +274,17 @@ func (r *Reflex) runCommand(name string, stdout chan<- OutMsg) {
}
r.tty = tty

// Handle pty size.
chResize := make(chan os.Signal, 1)
signal.Notify(chResize, syscall.SIGWINCH)
go func() {
for range chResize {
// Intentionally ignore errors in case stdout is not a tty
pty.InheritSize(os.Stdout, tty)
}
}()
chResize <- syscall.SIGWINCH // Initial resize.

go func() {
scanner := bufio.NewScanner(tty)
for scanner.Scan() {
Expand All @@ -293,6 +305,10 @@ func (r *Reflex) runCommand(name string, stdout chan<- OutMsg) {
stdout <- OutMsg{r.id, fmt.Sprintf("(error exit: %s)", err)}
}
r.done <- struct{}{}

signal.Stop(chResize)
close(chResize)

if flagSequential {
seqCommands.Unlock()
}
Expand Down

0 comments on commit 5bbd606

Please sign in to comment.