forked from pterm/pterm
/
main.go
51 lines (43 loc) · 2.44 KB
/
main.go
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
package main
import (
"time"
"github.com/pterm/pterm"
)
func main() {
// Create and start a fork of the default spinner.
spinnerInfo, _ := pterm.DefaultSpinner.Start("Some informational action...")
time.Sleep(time.Second * 2) // Simulate 3 seconds of processing something.
spinnerInfo.Info() // Resolve spinner with error message.
// Create and start a fork of the default spinner.
spinnerSuccess, _ := pterm.DefaultSpinner.Start("Doing something important... (will succeed)")
time.Sleep(time.Second * 2) // Simulate 3 seconds of processing something.
spinnerSuccess.Success() // Resolve spinner with success message.
// Create and start a fork of the default spinner.
spinnerWarning, _ := pterm.DefaultSpinner.Start("Doing something important... (will warn)")
time.Sleep(time.Second * 2) // Simulate 3 seconds of processing something.
spinnerWarning.Warning() // Resolve spinner with warning message.
// Create and start a fork of the default spinner.
spinnerFail, _ := pterm.DefaultSpinner.Start("Doing something important... (will fail)")
time.Sleep(time.Second * 2) // Simulate 3 seconds of processing something.
spinnerFail.Fail() // Resolve spinner with error message.
// Create and start a fork of the default spinner.
spinnerNochange, _ := pterm.DefaultSpinner.Start("Checking something important... (will result in no change)")
// Replace the InfoPrinter with a custom "NOCHG" one
spinnerNochange.InfoPrinter = &pterm.PrefixPrinter{
MessageStyle: &pterm.Style{pterm.FgLightBlue},
Prefix: pterm.Prefix{
Style: &pterm.Style{pterm.FgBlack, pterm.BgLightBlue},
Text: " NOCHG ",
},
}
time.Sleep(time.Second * 2) // Simulate 3 seconds of processing something.
spinnerNochange.Info("No change were required") // Resolve spinner with error message.
// Create and start a fork of the default spinner.
spinnerLiveText, _ := pterm.DefaultSpinner.Start("Doing a lot of stuff...")
time.Sleep(time.Second) // Simulate 2 seconds of processing something.
spinnerLiveText.UpdateText("It's really much") // Update spinner text.
time.Sleep(time.Second) // Simulate 2 seconds of processing something.
spinnerLiveText.UpdateText("We're nearly done!") // Update spinner text.
time.Sleep(time.Second) // Simulate 2 seconds of processing something.
spinnerLiveText.Success("Finally!") // Resolve spinner with success message.
}