turbo-editors/turbo-corepublic Fork 0
d662cebdb65b319885da903daf7eff9ab1bfbb78
Commits
Clone
git clone https://git.rickub.com/turbo-editors/turbo-core.git
git clone ssh://git@rickub.com/turbo-editors/turbo-core.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

🛟 Updated. 28d5985 · on d662cebdb65b319885da903daf7eff9ab1bfbb78 · k33g · 21h ago
spinner.go · 26 lines · 1.0 KBGo Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package acp

import "time"

// SpinnerPeriod is how long one frame of the spinner lasts. Eight frames a
// second reads as motion without drawing attention away from the text.
const SpinnerPeriod = 120 * time.Millisecond

// spinnerFrames are the braille dots every terminal spinner uses. They are one
// column wide, which matters: a frame that changed width would shift the words
// beside it on every tick.
var spinnerFrames = []rune("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏")

// Spinner returns the frame to draw at a moment.
//
// It is a function of the clock rather than of a counter somebody increments,
// so drawing stays a pure function of state — the same rule the rest of this
// editor follows, and what lets a test assert on a frame without waiting for
// one. Nothing has to be reset when a turn starts, and two windows thinking at
// once turn in step.
//
//	view.ruleLabel() // " ⠙ thinking — Esc stops it "
func Spinner(at time.Time) rune {
	frame := at.UnixNano() / int64(SpinnerPeriod)
	return spinnerFrames[int(frame%int64(len(spinnerFrames)))]
}