-
Notifications
You must be signed in to change notification settings - Fork 1
/
exportConsole.go
87 lines (68 loc) · 1.7 KB
/
exportConsole.go
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"context"
"fmt"
"os"
"text/template"
"github.com/fatih/color"
"github.com/nicksnyder/go-i18n/i18n"
nest "github.com/patrickalin/nest-api-go"
)
type console struct {
in chan nest.Nest
textTemplate *template.Template
}
//InitConsole listen on the chanel
func createConsole(messages chan nest.Nest, translateFunc i18n.TranslateFunc, dev bool) (console, error) {
f := map[string]interface{}{"T": translateFunc}
//Get template
c := console{in: messages, textTemplate: GetTemplate("nest.txt", "tmpl/nest.txt", f, dev)}
logInfo(funcName(), "Console listen", "")
return c, nil
}
func (c *console) listen(context context.Context) {
go func() {
/*
TODO
g, err := gocui.NewGui(gocui.OutputNormal)
if err != nil {
log.Panicln(err)
}
defer g.Close()
g.SetManagerFunc(layout)
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
log.Panicln(err)
}
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
log.Panicln(err)
}*/
logDebug(funcName(), "Init the queue console to display message", "")
for {
select {
case msg := <-c.in:
color.Set(color.FgBlack)
color.Set(color.BgWhite)
if err := c.textTemplate.Execute(os.Stdout, msg); err != nil {
fmt.Printf("%v", err)
}
color.Unset()
case <-context.Done():
fmt.Println("console done")
}
}
}()
}
/*
func layout(g *gocui.Gui) error {
maxX, maxY := g.Size()
if v, err := g.SetView("hello", maxX/2-7, maxY/2, maxX/2+7, maxY/2+2); err != nil {
if err != gocui.ErrUnknownView {
return err
}
fmt.Fprintln(v, "Hello world!")
}
return nil
}
func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}*/