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 ui "github.com/gizak/termui"
import "math" import "math"
import "time"
func main() { func main() {
err := ui.Init() err := ui.Init()
if err != nil { if err != nil {
@ -18,8 +16,19 @@ func main() {
} }
defer ui.Close() 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 := ui.NewPar(":PRESS q TO QUIT DEMO")
p.Height = 3 p.Height = 3
p.Width = 50 p.Width = 50
@ -106,7 +115,7 @@ func main() {
lc1.Y = 14 lc1.Y = 14
p1 := ui.NewPar("Hey!\nI am a borderless block!") p1 := ui.NewPar("Hey!\nI am a borderless block!")
p1.HasBorder = false p1.Border = false
p1.Width = 26 p1.Width = 26
p1.Height = 2 p1.Height = 2
p1.X = 52 p1.X = 52
@ -123,21 +132,13 @@ func main() {
ui.Render(p, list, g, sp, lc, bc, lc1, p1) ui.Render(p, list, g, sp, lc, bc, lc1, p1)
} }
evt := ui.EventCh() ui.Render(p, list, g, sp, lc, bc, lc1, p1)
i := 0 ui.Handle("/sys/kbd/q", func(ui.Event) {
for { ui.StopLoop()
select { })
case e := <-evt: ui.Handle("/timer/1s", func(e ui.Event) {
if e.Type == ui.EventKey && e.Ch == 'q' { t := e.Data.(ui.EvtTimer)
return draw(int(t.Count))
} })
default: ui.Loop()
draw(i)
i++
if i == 102 {
return
}
time.Sleep(time.Second / 2)
}
}
} }

View File

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