From 48e16edb474a59e74197793c2790f666d394e401 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Fri, 23 Jan 2015 20:30:50 +0900 Subject: [PATCH] Redraw and adjust upon terminal resize --- src/curses/curses.go | 4 ++++ src/terminal.go | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/curses/curses.go b/src/curses/curses.go index 8ebb583..454f1e3 100644 --- a/src/curses/curses.go +++ b/src/curses/curses.go @@ -421,6 +421,10 @@ func Clear() { C.clear() } +func Endwin() { + C.endwin() +} + func Refresh() { C.refresh() } diff --git a/src/terminal.go b/src/terminal.go index e5cf64a..e1eb4c2 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -4,10 +4,12 @@ import ( "bytes" "fmt" "os" + "os/signal" "regexp" "sort" "strings" "sync" + "syscall" "time" C "github.com/junegunn/fzf/src/curses" @@ -452,6 +454,15 @@ func (t *Terminal) Loop() { <-timer.C 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() { @@ -471,6 +482,8 @@ func (t *Terminal) Loop() { t.suppress = false case reqRedraw: C.Clear() + C.Endwin() + C.Refresh() t.printAll() case reqClose: C.Close()