From 5eb3067a34482adfa90e46222b2794fe04572a47 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 12 Jan 2023 16:12:43 -0500 Subject: [PATCH] Added an example demonstrating the use of goroutines --- examples/goroutines/main.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 examples/goroutines/main.go diff --git a/examples/goroutines/main.go b/examples/goroutines/main.go new file mode 100644 index 0000000..4d2a8f0 --- /dev/null +++ b/examples/goroutines/main.go @@ -0,0 +1,33 @@ +package main + +import "os" +import "time" +import "git.tebibyte.media/sashakoshka/tomo" +import "git.tebibyte.media/sashakoshka/tomo/elements/basic" +import _ "git.tebibyte.media/sashakoshka/tomo/backends/x" + +func main () { + tomo.Run(run) + os.Exit(0) +} + +func run () { + window, _ := tomo.NewWindow(2, 2) + window.SetTitle("clock") + label := basic.NewLabel(formatTime(), false) + window.Adopt(label) + window.OnClose(tomo.Stop) + window.Show() + go tick(label) +} + +func formatTime () (timeString string) { + return time.Now().Format("2006-01-02 15:04:05") +} + +func tick (label *basic.Label) { + for { + label.SetText(formatTime()) + time.Sleep(time.Second) + } +}