File: spinners.go

package info (click to toggle)
kitty 0.45.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 27,476 kB
  • sloc: ansic: 84,285; python: 57,992; objc: 5,432; sh: 1,333; xml: 364; makefile: 144; javascript: 78
file content (31 lines) | stat: -rw-r--r-- 603 bytes parent folder | download | duplicates (3)
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
27
28
29
30
31
// License: GPLv3 Copyright: 2022, Kovid Goyal, <kovid at kovidgoyal.net>

package tui

import (
	"fmt"
	"time"
)

var _ = fmt.Print

type Spinner struct {
	Name           string
	interval       time.Duration
	frames         []string
	current_frame  int
	last_change_at time.Time
}

func (self Spinner) Interval() time.Duration {
	return self.interval
}

func (self *Spinner) Tick() string {
	now := time.Now()
	if now.Sub(self.last_change_at) >= self.interval {
		self.last_change_at = now
		self.current_frame = (self.current_frame + 1) % len(self.frames)
	}
	return self.frames[self.current_frame]
}