Skip to content
Myr

terminal_windows.go

This file

Path

src/terminal_windows.go

62 lines · 1.3 KiB · Go

Last changed by

Terminate resize notification when Loop exitsJunegunn Choibefore adoptiondc384af

History of this file

Take it

The walk stopped after 200 commits: lines older than 76efddd point at it.

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

lines 1–5why, one step back
1//go:build windows
23package fzf45import (

Terminate resize notification when Loop exitsJunegunn Choibefore adoptiondc384af

line 6why, one step back
6 "context"

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

line 7why, one step back
7 "os"

Detect terminal resize on Windows (fix #4790)Cyrusbefore adoption6e65d86

lines 8–11why, one step back
8 "syscall"
9 "time"1011 "golang.org/x/sys/windows"

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

lines 12–13why, one step back
12)
13

Detect terminal resize on Windows (fix #4790)Cyrusbefore adoption6e65d86

lines 14–22why, one step back
14const resizePollInterval = 100 * time.Millisecond
1516type resizeSignal struct{}1718func (resizeSignal) String() string { return "resize" }19func (resizeSignal) Signal() {}2021// Windows has no SIGWINCH, so poll the console screen buffer for window22// size changes instead.

Terminate resize notification when Loop exitsJunegunn Choibefore adoptiondc384af

line 23why, one step back
23func notifyOnResize(ctx context.Context, resizeChan chan<- os.Signal) {

Detect terminal resize on Windows (fix #4790)Cyrusbefore adoption6e65d86

lines 24–29why, one step back
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 {

Terminate resize notification when Loop exitsJunegunn Choibefore adoptiondc384af

line 30why, one step back
30 syscall.Close(consoleOut)

Detect terminal resize on Windows (fix #4790)Cyrusbefore adoption6e65d86

lines 31–34why, one step back
31 return
32 }33 last := info.Window34 go func() {

Terminate resize notification when Loop exitsJunegunn Choibefore adoptiondc384af

lines 35–37why, one step back
35 defer syscall.Close(consoleOut)
36 ticker := time.NewTicker(resizePollInterval)37 defer ticker.Stop()

Detect terminal resize on Windows (fix #4790)Cyrusbefore adoption6e65d86

line 38why, one step back
38 for {

Terminate resize notification when Loop exitsJunegunn Choibefore adoptiondc384af

lines 39–43why, one step back
39 select {
40 case <-ctx.Done():41 return42 case <-ticker.C:43 }

Detect terminal resize on Windows (fix #4790)Cyrusbefore adoption6e65d86

lines 44–57why, one step back
44 if windows.GetConsoleScreenBufferInfo(windows.Handle(consoleOut), &info) != nil {
45 continue46 }47 current := info.Window48 if current.Right-current.Left != last.Right-last.Left ||49 current.Bottom-current.Top != last.Bottom-last.Top {50 last = current51 select {52 case resizeChan <- resizeSignal{}:53 default:54 }55 }56 }57 }()

bash: shift-delete to delete history entries during CTRL-RJunegunn Choibefore adoption76efddd

lines 58–62why, one step back
58}
5960func notifyStop(p *os.Process) {61 // NOOP62}