Skip to content
Myr

Detect terminal resize on Windows (fix #4790)

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

Windows has no SIGWINCH and notifyOnResize was an empty TODO, so fzf running in --height mode never noticed console size changes. Poll the console screen buffer dimensions every 100ms and push a signal through the same channel SIGWINCH uses on Unix. Full-screen mode is unaffected as it goes through tcell which emits its own resize events.

authored by Cyrus · committed by Cyrus · parent b163463 · Browse files · 1 file+39 added−1 removed
This commit

State

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

Diff stats

1 file+39 added−1 removed

  • other:+39 added−1 removed

1 file+39 added−1 removed

modified:src/terminal_windows.go+39 added-1 removed
2 unmodified lines
3package fzf45import (6 "os"7 "syscall"8 "time"910 "golang.org/x/sys/windows"11)1213const resizePollInterval = 100 * time.Millisecond1415type resizeSignal struct{}1617func (resizeSignal) String() string { return "resize" }18func (resizeSignal) Signal() {}1920// Windows has no SIGWINCH, so poll the console screen buffer for window21// size changes instead.22func notifyOnResize(resizeChan chan<- os.Signal) {10 // TODO23 consoleOut, err := syscall.Open("CONOUT$", syscall.O_RDWR, 0)24 if err != nil {25 return26 }27 var info windows.ConsoleScreenBufferInfo28 if windows.GetConsoleScreenBufferInfo(windows.Handle(consoleOut), &info) != nil {29 return30 }31 last := info.Window32 go func() {33 for {34 time.Sleep(resizePollInterval)35 if windows.GetConsoleScreenBufferInfo(windows.Handle(consoleOut), &info) != nil {36 continue37 }38 current := info.Window39 if current.Right-current.Left != last.Right-last.Left ||40 current.Bottom-current.Top != last.Bottom-last.Top {41 last = current42 select {43 case resizeChan <- resizeSignal{}:44 default:45 }46 }47 }48 }()49}5051func notifyStop(p *os.Process) {52 // NOOP
1 unmodified line