File: main.go

package info (click to toggle)
golang-github-theckman-yacspin 0.13.12-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 252 kB
  • sloc: sh: 8; makefile: 3
file content (66 lines) | stat: -rw-r--r-- 1,265 bytes parent folder | download
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// This program was used to generate the gifs in the README file

package main

import (
	"fmt"
	"os"
	"os/signal"
	"runtime"
	"runtime/debug"
	"syscall"
	"time"

	"github.com/theckman/yacspin"
)

func main() {
	// disable GC
	debug.SetGCPercent(-1)

	cfg := yacspin.Config{
		Frequency:       200 * time.Millisecond,
		CharSet:         yacspin.CharSets[36],
		SuffixAutoColon: true,
		Suffix:          " example spinner",
		Message:         "initial message",
		Colors:          []string{"fgYellow"},
	}

	spinner, err := yacspin.New(cfg)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to create spinner: %v\n", err)
		os.Exit(1)
	}

	// handle SIGINT / SIGTERM without needing terminal reset
	sigc := make(chan os.Signal, 2)
	signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM)
	go func() {
		<-sigc
		_ = spinner.Stop()
		os.Exit(0)
	}()

	// run GC once before we start to render
	runtime.GC()

	time.Sleep(3 * time.Second)

	for i := 0; i < len(yacspin.CharSets); i++ {
		spinner.Message("initial message")

		// interesting charsets for recording sizing: 19, 36
		_ = spinner.CharSet(yacspin.CharSets[i])

		_ = spinner.Start()

		time.Sleep(5 * time.Second)

		spinner.Message("updated message")

		time.Sleep(5 * time.Second)

		_ = spinner.Stop()
	}
}