Adds mechanism to set custom sleep time for frames
This commit is contained in:
parent
b427fd460a
commit
b065534fff
3 changed files with 13 additions and 1 deletions
|
@ -1,8 +1,11 @@
|
||||||
package frames
|
package frames
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
type FrameType struct {
|
type FrameType struct {
|
||||||
GetFrame func(int) string
|
GetFrame func(int) string
|
||||||
GetLength func() int
|
GetLength func() int
|
||||||
|
GetSleep func() time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a function that returns the next frame, based on length
|
// 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
|
// Given frames, create a FrameType with those frames
|
||||||
func DefaultFrameType(frames []string) FrameType {
|
func DefaultFrameType(frames []string) FrameType {
|
||||||
return FrameType{
|
return FrameType{
|
||||||
GetFrame: DefaultGetFrame(frames),
|
GetFrame: DefaultGetFrame(frames),
|
||||||
GetLength: DefaultGetLength(frames),
|
GetLength: DefaultGetLength(frames),
|
||||||
|
GetSleep: DefaultGetSleep(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import "time"
|
||||||
var Clock = FrameType{
|
var Clock = FrameType{
|
||||||
GetFrame: getClockFrame,
|
GetFrame: getClockFrame,
|
||||||
GetLength: getClockLength,
|
GetLength: getClockLength,
|
||||||
|
GetSleep: DefaultGetSleep(),
|
||||||
}
|
}
|
||||||
|
|
||||||
func getClockFrame(i int) string {
|
func getClockFrame(i int) string {
|
||||||
|
|
2
main.go
2
main.go
|
@ -87,7 +87,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
||||||
i = 0
|
i = 0
|
||||||
}
|
}
|
||||||
// Artificially wait between reponses.
|
// Artificially wait between reponses.
|
||||||
time.Sleep(time.Millisecond * 70)
|
time.Sleep(frames.GetSleep())
|
||||||
|
|
||||||
// Clear screen
|
// Clear screen
|
||||||
clearScreen := "\033[2J\033[H"
|
clearScreen := "\033[2J\033[H"
|
||||||
|
|
Loading…
Reference in a new issue