This commit is contained in:
Zack Guo 2017-05-02 22:11:46 +08:00
parent 86c275c69b
commit 1fd509e58d
2 changed files with 25 additions and 24 deletions

View File

@ -9,8 +9,6 @@ package main
import ui "github.com/gizak/termui"
import "math"
import "time"
func main() {
err := ui.Init()
if err != nil {
@ -18,8 +16,19 @@ func main() {
}
defer ui.Close()
ui.UseTheme("helloworld")
// Deprecated
//ui.UseTheme("helloworld")
ui.ColorMap = map[string]ui.Attribute{
"fg": ui.ColorWhite,
"bg": ui.ColorDefault,
"border.fg": ui.ColorYellow,
"label.fg": ui.ColorGreen,
"par.fg": ui.ColorYellow,
"par.label.bg": ui.ColorWhite,
"gauge.bar.bg": ui.ColorCyan,
"gauge.percent.fg": ui.ColorBlue,
"barchart.bar.bg": ui.ColorRed,
}
p := ui.NewPar(":PRESS q TO QUIT DEMO")
p.Height = 3
p.Width = 50
@ -106,7 +115,7 @@ func main() {
lc1.Y = 14
p1 := ui.NewPar("Hey!\nI am a borderless block!")
p1.HasBorder = false
p1.Border = false
p1.Width = 26
p1.Height = 2
p1.X = 52
@ -123,21 +132,13 @@ func main() {
ui.Render(p, list, g, sp, lc, bc, lc1, p1)
}
evt := ui.EventCh()
i := 0
for {
select {
case e := <-evt:
if e.Type == ui.EventKey && e.Ch == 'q' {
return
}
default:
draw(i)
i++
if i == 102 {
return
}
time.Sleep(time.Second / 2)
}
}
ui.Render(p, list, g, sp, lc, bc, lc1, p1)
ui.Handle("/sys/kbd/q", func(ui.Event) {
ui.StopLoop()
})
ui.Handle("/timer/1s", func(e ui.Event) {
t := e.Data.(ui.EvtTimer)
draw(int(t.Count))
})
ui.Loop()
}

View File

@ -68,7 +68,7 @@ func (s *Server) ListenAndServe() error {
http.Handle(s.Path, websocket.Handler(func(ws *websocket.Conn) {
defer ws.Close()
mc := make(chan string)
mc := make(chan string, 10)
s.chs = append(s.chs, mc)
for m := range mc {
@ -79,7 +79,7 @@ func (s *Server) ListenAndServe() error {
go func() {
for msg := range s.Msg {
for _, c := range s.chs {
go func(a chan string) {
func(a chan string) {
a <- msg
}(c)
}