Skip to content
Myr

Terminate resize notification when Loop exits

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- Pass Loop context to notifyOnResize - Windows: stop polling goroutine, close CONOUT$ handle on ctx.Done - Unix: unregister SIGWINCH handler on ctx.Done

authored by Junegunn Choi · committed by Junegunn Choi · parent 6e65d86 · Browse files · 3 files+18 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+18 added−4 removed

  • other:+18 added−4 removed

3 files+18 added−4 removed

modified:src/terminal_unix.go+6 added-1 removed
1 unmodified line
23package fzf45import (6 "context"7 "os"8 "os/signal"9 "syscall"1011 "golang.org/x/sys/unix"12)1313func notifyOnResize(resizeChan chan<- os.Signal) {14func notifyOnResize(ctx context.Context, resizeChan chan<- os.Signal) {15 signal.Notify(resizeChan, syscall.SIGWINCH)16 go func() {17 <-ctx.Done()18 signal.Stop(resizeChan)19 }()20}2122func notifyStop(p *os.Process) {23 pid := p.Pid
6 unmodified lines
modified:src/terminal_windows.go+11 added-2 removed
1 unmodified line
23package fzf45import (6 "context"7 "os"8 "syscall"9 "time"10
8 unmodified lines
19func (resizeSignal) Signal() {}2021// Windows has no SIGWINCH, so poll the console screen buffer for window22// size changes instead.22func notifyOnResize(resizeChan chan<- os.Signal) {23func notifyOnResize(ctx context.Context, resizeChan chan<- os.Signal) {24 consoleOut, err := syscall.Open("CONOUT$", syscall.O_RDWR, 0)25 if err != nil {26 return27 }28 var info windows.ConsoleScreenBufferInfo29 if windows.GetConsoleScreenBufferInfo(windows.Handle(consoleOut), &info) != nil {30 syscall.Close(consoleOut)31 return32 }33 last := info.Window34 go func() {35 defer syscall.Close(consoleOut)36 ticker := time.NewTicker(resizePollInterval)37 defer ticker.Stop()38 for {34 time.Sleep(resizePollInterval)39 select {40 case <-ctx.Done():41 return42 case <-ticker.C:43 }44 if windows.GetConsoleScreenBufferInfo(windows.Handle(consoleOut), &info) != nil {45 continue46 }47 current := info.Window
15 unmodified lines
modified:src/terminal.go+1 added-1 removed
6197 unmodified lines
6198 }()61996200 if !t.tui.ShouldEmitResizeEvent() {6201 resizeChan := make(chan os.Signal, 1)6202 notifyOnResize(resizeChan) // Non-portable6202 notifyOnResize(ctx, resizeChan) // Non-portable6203 go func() {6204 for {6205 select {6206 case <-ctx.Done():
2504 unmodified lines