diff --git a/lib/screen.go b/lib/screen.go
index 36c661d..512a62c 100644
--- a/lib/screen.go
+++ b/lib/screen.go
@@ -3,11 +3,10 @@
package mop
import (
- "fmt"
- "github.com/michaeldv/just"
- "github.com/nsf/termbox-go"
"regexp"
"strings"
+ "github.com/michaeldv/just"
+ "github.com/nsf/termbox-go"
)
// Can combine attributes and a single color using bitwise OR.
@@ -37,24 +36,6 @@ func Draw(stocks string) {
drawScreen(Format(message))
}
-//-----------------------------------------------------------------------------
-func Refresh(profile string) {
-loop:
- for {
- switch ev := termbox.PollEvent(); ev.Type {
- case termbox.EventKey:
- if ev.Key == termbox.KeyEsc {
- break loop
- }
- case termbox.EventResize:
- // Draw(profile)
- // x, y := termbox.Size()
- str := fmt.Sprintf("(%d:%d)", ev.Width, ev.Height)
- drawScreen(str + ": Hello world, how are you?")
- }
- }
-}
-
//
// Return regular expression that matches all possible color tags, i.e.
// ?black>|?red>| ... |?white>
@@ -121,3 +102,7 @@ func drawScreen(str string) {
}
termbox.Flush()
}
+
+func DrawScreen(str string) {
+ drawScreen(str)
+}
diff --git a/mop.go b/mop.go
index 482dd30..3b90dab 100644
--- a/mop.go
+++ b/mop.go
@@ -3,20 +3,60 @@
package main
import (
+ "fmt"
+ "time"
"github.com/michaeldv/mop/lib"
"github.com/nsf/termbox-go"
)
//-----------------------------------------------------------------------------
-func main() {
- profile := mop.LoadProfile()
-
+func initTermbox() {
err := termbox.Init()
if err != nil {
panic(err)
}
- defer termbox.Close()
+}
+
+//-----------------------------------------------------------------------------
+func mainLoop(profile string) {
+ event_queue := make(chan termbox.Event)
+ event_tick := time.NewTicker(1 * time.Second)
+
+ go func() {
+ for {
+ event_queue <- termbox.PollEvent()
+ }
+ }()
mop.Draw(profile)
- mop.Refresh(profile)
+loop:
+ for {
+ select {
+ case event := <- event_queue:
+ switch event.Type {
+ case termbox.EventKey:
+ if event.Key == termbox.KeyEsc {
+ break loop
+ }
+ case termbox.EventResize:
+ // Draw(profile)
+ // x, y := termbox.Size()
+ str := fmt.Sprintf("(%d:%d)", event.Width, event.Height)
+ mop.DrawScreen(str + ": Hello world, how are you?")
+ }
+ case <-event_tick.C:
+ mop.DrawScreen(time.Now().Format("3:04:05pm PST"))
+ //mop.Draw(profile)
+ }
+ }
+}
+
+//-----------------------------------------------------------------------------
+func main() {
+
+ initTermbox()
+ defer termbox.Close()
+
+ profile := mop.LoadProfile()
+ mainLoop(profile)
}