Applications can now manually call a screen redraw in a way that I think is thread safe
This commit is contained in:
@@ -8,8 +8,11 @@ import _ "image/png"
|
||||
import "git.tebibyte.media/sashakoshka/stone"
|
||||
import _ "git.tebibyte.media/sashakoshka/stone/backends/x"
|
||||
|
||||
var application = &stone.Application { }
|
||||
var currentTime = time.Time { }
|
||||
var tickPing = make(chan(struct { }))
|
||||
|
||||
func main () {
|
||||
application := &stone.Application { }
|
||||
application.SetTitle("hellorld")
|
||||
application.SetSize(12, 2)
|
||||
|
||||
@@ -29,32 +32,51 @@ func main () {
|
||||
channel, err := application.Run()
|
||||
if err != nil { panic(err) }
|
||||
|
||||
currentTime := time.Time { }
|
||||
redraw()
|
||||
application.Draw()
|
||||
go tick()
|
||||
|
||||
for {
|
||||
event := <- channel
|
||||
switch event.(type) {
|
||||
case stone.EventQuit:
|
||||
os.Exit(0)
|
||||
select {
|
||||
case <- tickPing:
|
||||
redraw()
|
||||
application.Draw()
|
||||
|
||||
case event := <- channel:
|
||||
switch event.(type) {
|
||||
case stone.EventQuit:
|
||||
os.Exit(0)
|
||||
|
||||
case stone.EventResize:
|
||||
currentTime = time.Now()
|
||||
|
||||
application.ResetDot()
|
||||
fmt.Fprintln(application, "hellorld!")
|
||||
|
||||
hour := currentTime.Hour()
|
||||
minute := currentTime.Minute()
|
||||
second := currentTime.Second()
|
||||
|
||||
application.SetRune(0, 1, rune(hour / 10 + 48))
|
||||
application.SetRune(1, 1, rune(hour % 10 + 48))
|
||||
application.SetRune(2, 1, ':')
|
||||
application.SetRune(3, 1, rune(minute / 10 + 48))
|
||||
application.SetRune(4, 1, rune(minute % 10 + 48))
|
||||
application.SetRune(5, 1, ':')
|
||||
application.SetRune(6, 1, rune(second / 10 + 48))
|
||||
application.SetRune(7, 1, rune(second % 10 + 48))
|
||||
case stone.EventResize:
|
||||
redraw()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func redraw () {
|
||||
currentTime = time.Now()
|
||||
|
||||
application.ResetDot()
|
||||
fmt.Fprintln(application, "hellorld!")
|
||||
|
||||
hour := currentTime.Hour()
|
||||
minute := currentTime.Minute()
|
||||
second := currentTime.Second()
|
||||
|
||||
application.SetRune(0, 1, rune(hour / 10 + 48))
|
||||
application.SetRune(1, 1, rune(hour % 10 + 48))
|
||||
application.SetRune(2, 1, ':')
|
||||
application.SetRune(3, 1, rune(minute / 10 + 48))
|
||||
application.SetRune(4, 1, rune(minute % 10 + 48))
|
||||
application.SetRune(5, 1, ':')
|
||||
application.SetRune(6, 1, rune(second / 10 + 48))
|
||||
application.SetRune(7, 1, rune(second % 10 + 48))
|
||||
}
|
||||
|
||||
func tick () {
|
||||
for {
|
||||
tickPing <- struct { } { }
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user