Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Created February 17, 2018 12:22
Show Gist options
  • Save miguelmota/383733b2435dc4d69f800e72da48ceae to your computer and use it in GitHub Desktop.
Save miguelmota/383733b2435dc4d69f800e72da48ceae to your computer and use it in GitHub Desktop.
Golang goncurses detect resize event
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