aboutsummaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/gizak/termui/test/runtest.go
blob: 99794c4dbd2e37186f198d7ff8721bf809f03d6b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2016 Zack Guo <gizak@icloud.com>. All rights reserved.
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.

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()

    //termui.UseTheme("helloworld")
    b := termui.NewBlock()
    b.Width = 20
    b.Height = 20
    b.Float = termui.AlignCenter
    b.BorderLabel = "[HELLO](fg-red,bg-white) [WORLD](fg-blue,bg-green)"

    termui.Render(b)

    termui.Handle("/sys", func(e termui.Event) {
        k, ok := e.Data.(termui.EvtKbd)
        debug.Logf("->%v\n", e)
        if ok && k.KeyStr == "q" {
            termui.StopLoop()
        }
    })

    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)
        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)"
        }

        termui.Render(b)

    })

    termui.Loop()
}