termui/_test/log_events.go

36 lines
669 B
Go
Raw Normal View History

2018-11-29 10:19:22 -07:00
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
2022-08-28 10:46:41 -06:00
// Use of this source code is governed by a GPLv3 license that can
2018-11-29 10:19:22 -07:00
// be found in the LICENSE file.
2018-12-28 14:07:47 -07:00
// +build ignore
2018-11-29 10:19:22 -07:00
package main
import (
"fmt"
2019-01-24 06:23:30 -07:00
"log"
2018-11-29 10:19:22 -07:00
ui "git.tebitea.media/sashakoshka/termui/v3"
2018-11-29 10:19:22 -07:00
)
// logs all events to the termui window
// stdout can also be redirected to a file and read with `tail -f`
func main() {
2019-01-23 21:12:10 -07:00
if err := ui.Init(); err != nil {
2019-01-24 06:23:30 -07:00
log.Fatalf("failed to initialize termui: %v", err)
2018-11-29 10:19:22 -07:00
}
defer ui.Close()
2019-01-24 06:23:30 -07:00
events := ui.PollEvents()
2018-11-29 10:19:22 -07:00
for {
2019-01-24 06:23:30 -07:00
e := <-events
2018-11-29 10:19:22 -07:00
fmt.Printf("%v", e)
switch e.ID {
case "q", "<C-c>":
return
2019-01-24 06:23:30 -07:00
case "<MouseLeft>":
return
2018-11-29 10:19:22 -07:00
}
}
}