termui/test/runtest.go

67 lines
1.3 KiB
Go
Raw Normal View History

2017-01-14 06:07:43 +00:00
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
2016-01-27 01:45:18 +00:00
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
2015-09-18 15:41:44 +00:00
package main
import (
"fmt"
"os"
"github.com/gizak/termui"
"github.com/gizak/termui/debug"
)
func main() {
// run as client
if len(os.Args) > 1 {
fmt.Print(debug.ConnectAndListen())
return
}
// run as server
go func() { panic(debug.ListenAndServe()) }()
if err := termui.Init(); err != nil {
panic(err)
}
defer termui.Close()
2015-10-09 02:11:26 +00:00
//termui.UseTheme("helloworld")
b := termui.NewBlock()
b.Width = 20
2015-10-13 05:00:15 +00:00
b.Height = 20
b.Float = termui.AlignCenter
b.BorderLabel = "[HELLO](fg-red,bg-white) [WORLD](fg-blue,bg-green)"
2015-10-13 05:00:15 +00:00
termui.Render(b)
2015-09-18 15:41:44 +00:00
termui.Handle("/sys", func(e termui.Event) {
k, ok := e.Data.(termui.EvtKbd)
debug.Logf("->%v\n", e)
2015-09-18 15:41:44 +00:00
if ok && k.KeyStr == "q" {
termui.StopLoop()
}
})
2015-10-13 16:45:03 +00:00
termui.Handle(("/usr"), func(e termui.Event) {
debug.Logf("->%v\n", e)
})
termui.Handle("/timer/1s", func(e termui.Event) {
t := e.Data.(termui.EvtTimer)
2015-10-13 16:45:03 +00:00
termui.SendCustomEvt("/usr/t", t.Count)
if t.Count%2 == 0 {
b.BorderLabel = "[HELLO](fg-red,bg-green) [WORLD](fg-blue,bg-white)"
} else {
b.BorderLabel = "[HELLO](fg-blue,bg-white) [WORLD](fg-red,bg-green)"
}
2015-10-13 05:00:15 +00:00
termui.Render(b)
2015-09-18 15:41:44 +00:00
})
2015-10-13 16:45:03 +00:00
2015-09-18 15:41:44 +00:00
termui.Loop()
}