Created
February 17, 2018 12:22
-
-
Save miguelmota/383733b2435dc4d69f800e72da48ceae to your computer and use it in GitHub Desktop.
Golang goncurses detect resize event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"os/signal" | |
"strconv" | |
"sync" | |
"syscall" | |
gc "github.com/rgburke/goncurses" | |
) | |
var wg sync.WaitGroup | |
func main() { | |
wg.Add(1) | |
resizeChannel := make(chan os.Signal) | |
signal.Notify(resizeChannel, syscall.SIGWINCH) | |
go onResize(resizeChannel) | |
wg.Wait() | |
} | |
func onResize(channel chan os.Signal) { | |
stdScr, _ := gc.Init() | |
stdScr.ScrollOk(true) | |
gc.NewLines(true) | |
for { | |
<-channel | |
gc.StdScr().Clear() | |
gc.End() | |
gc.Update() | |
y, x := gc.StdScr().MaxYX() | |
gc.StdScr().Println(strconv.Itoa(x) + ", " + strconv.Itoa(y)) | |
gc.StdScr().Refresh() | |
} | |
wg.Done() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment