| 1 |
//go:build windows |
| 2 |
|
| 3 |
package fzf |
| 4 |
|
| 5 |
import ( |
| 6 |
"context" |
| 7 |
"os" |
| 8 |
"syscall" |
| 9 |
"time" |
| 10 |
|
| 11 |
"golang.org/x/sys/windows" |
| 12 |
) |
| 13 |
|
| 14 |
const resizePollInterval = 100 * time.Millisecond |
| 15 |
|
| 16 |
type resizeSignal struct{} |
| 17 |
|
| 18 |
func (resizeSignal) String() string { return "resize" } |
| 19 |
func (resizeSignal) Signal() {} |
| 20 |
|
| 21 |
// Windows has no SIGWINCH, so poll the console screen buffer for window |
| 22 |
// size changes instead. |
| 23 |
func notifyOnResize(ctx context.Context, resizeChan chan<- os.Signal) { |
| 24 |
consoleOut, err := syscall.Open("CONOUT$", syscall.O_RDWR, 0) |
| 25 |
if err != nil { |
| 26 |
return |
| 27 |
} |
| 28 |
var info windows.ConsoleScreenBufferInfo |
| 29 |
if windows.GetConsoleScreenBufferInfo(windows.Handle(consoleOut), &info) != nil { |
| 30 |
syscall.Close(consoleOut) |
| 31 |
return |
| 32 |
} |
| 33 |
last := info.Window |
| 34 |
go func() { |
| 35 |
defer syscall.Close(consoleOut) |
| 36 |
ticker := time.NewTicker(resizePollInterval) |
| 37 |
defer ticker.Stop() |
| 38 |
for { |
| 39 |
select { |
| 40 |
case <-ctx.Done(): |
| 41 |
return |
| 42 |
case <-ticker.C: |
| 43 |
} |
| 44 |
if windows.GetConsoleScreenBufferInfo(windows.Handle(consoleOut), &info) != nil { |
| 45 |
continue |
| 46 |
} |
| 47 |
current := info.Window |
| 48 |
if current.Right-current.Left != last.Right-last.Left || |
| 49 |
current.Bottom-current.Top != last.Bottom-last.Top { |
| 50 |
last = current |
| 51 |
select { |
| 52 |
case resizeChan <- resizeSignal{}: |
| 53 |
default: |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
}() |
| 58 |
} |
| 59 |
|
| 60 |
func notifyStop(p *os.Process) { |
| 61 |
// NOOP |
| 62 |
} |