Redraw and adjust upon terminal resize

This commit is contained in:
Junegunn Choi 2015-01-23 20:30:50 +09:00
parent c35d98dc42
commit 48e16edb47
2 changed files with 17 additions and 0 deletions

View File

@ -421,6 +421,10 @@ func Clear() {
C.clear() C.clear()
} }
func Endwin() {
C.endwin()
}
func Refresh() { func Refresh() {
C.refresh() C.refresh()
} }

View File

@ -4,10 +4,12 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"os" "os"
"os/signal"
"regexp" "regexp"
"sort" "sort"
"strings" "strings"
"sync" "sync"
"syscall"
"time" "time"
C "github.com/junegunn/fzf/src/curses" C "github.com/junegunn/fzf/src/curses"
@ -452,6 +454,15 @@ func (t *Terminal) Loop() {
<-timer.C <-timer.C
t.reqBox.Set(reqRefresh, nil) t.reqBox.Set(reqRefresh, nil)
}() }()
resizeChan := make(chan os.Signal, 1)
signal.Notify(resizeChan, syscall.SIGWINCH)
go func() {
for {
<-resizeChan
t.reqBox.Set(reqRedraw, nil)
}
}()
} }
go func() { go func() {
@ -471,6 +482,8 @@ func (t *Terminal) Loop() {
t.suppress = false t.suppress = false
case reqRedraw: case reqRedraw:
C.Clear() C.Clear()
C.Endwin()
C.Refresh()
t.printAll() t.printAll()
case reqClose: case reqClose:
C.Close() C.Close()