Adds mechanism to set custom sleep time for frames

This commit is contained in:
Hugo Müller-Downing 2023-10-08 17:24:39 +11:00
parent b427fd460a
commit b065534fff
3 changed files with 13 additions and 1 deletions

View File

@ -1,8 +1,11 @@
package frames
import "time"
type FrameType struct {
GetFrame func(int) string
GetLength func() int
GetSleep func() time.Duration
}
// Create a function that returns the next frame, based on length
@ -19,11 +22,19 @@ func DefaultGetLength(frames []string) func() int {
}
}
// Sleep time between frames
func DefaultGetSleep() func() time.Duration {
return func() time.Duration {
return time.Millisecond * 70
}
}
// Given frames, create a FrameType with those frames
func DefaultFrameType(frames []string) FrameType {
return FrameType{
GetFrame: DefaultGetFrame(frames),
GetLength: DefaultGetLength(frames),
GetSleep: DefaultGetSleep(),
}
}

View File

@ -5,6 +5,7 @@ import "time"
var Clock = FrameType{
GetFrame: getClockFrame,
GetLength: getClockLength,
GetSleep: DefaultGetSleep(),
}
func getClockFrame(i int) string {

View File

@ -87,7 +87,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
i = 0
}
// Artificially wait between reponses.
time.Sleep(time.Millisecond * 70)
time.Sleep(frames.GetSleep())
// Clear screen
clearScreen := "\033[2J\033[H"