Skip to content

Instantly share code, notes, and snippets.

@alexmherrmann
Created June 26, 2019 15:26
Show Gist options
  • Save alexmherrmann/cc97895f99f3e4f89a348bc1896a0d34 to your computer and use it in GitHub Desktop.
Save alexmherrmann/cc97895f99f3e4f89a348bc1896a0d34 to your computer and use it in GitHub Desktop.
Use a fun little termui app to show event ids so you can see what termui is thinking. Run it and mash some keys, click the mouse and stuff and you'll see events fill up pretty quick!
package main
import (
"fmt"
"github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
)
const eventMax = 30
func main() {
// init and defer close
err := termui.Init()
if err != nil {
panic(err.Error())
}
defer termui.Close()
events := []string{}
idx := 0
for event := range termui.PollEvents() {
// do quit
if event.ID == "<C-c>" {
break
}
paragraph := widgets.NewParagraph()
paragraph.Title = "Event"
paragraph.SetRect(0, 0, 50, eventMax+2)
idx++
formatted := fmt.Sprintf("%4d %1d %s", idx, len(event.ID), event.ID)
if len(events) >= eventMax {
events = append(events[1:], formatted)
} else {
events = append(events[:], formatted)
}
paragraph.Text = events[0]
for _, s := range events[1:] {
paragraph.Text += "\n" + s
}
termui.Render(paragraph)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment