Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Show elapsed time #155

Open
saitho opened this issue Apr 23, 2021 · 0 comments
Open

Show elapsed time #155

saitho opened this issue Apr 23, 2021 · 0 comments
Labels
cli Issue related to StackHead CLI
Milestone

Comments

@saitho
Copy link
Member

saitho commented Apr 23, 2021

package main

import (
	"fmt"
	"math"
	"time"

	"github.com/briandowns/spinner"
)

const elapsed = " Doing awesome stuff... Please hang on! (%s:%s)"

func main() {
	s := spinner.New(spinner.CharSets[9], time.Duration(time.Millisecond*200))
	startTime := time.Now()
	s.Start()
	s.Suffix = fmt.Sprintf(elapsed, "00", "00")

	go func() {
		ticker := time.NewTicker(time.Millisecond * 400)
		defer ticker.Stop()
		for range ticker.C {
			elspd := time.Since(startTime)
			minutes := fmt.Sprintf("%.0f", math.Floor(elspd.Minutes()))
			if len(minutes) == 1 {
				minutes = "0" + minutes
			}
			seconds := fmt.Sprintf("%.0f", math.Floor(elspd.Seconds()))
			if len(seconds) == 1 {
				seconds = "0" + seconds
			}
			s.Suffix = fmt.Sprintf(elapsed, minutes, seconds)
		}
	}()

	time.Sleep(time.Second * 10)

	s.Stop()
}
@saitho saitho transferred this issue from getstackhead/stackhead-cli Sep 17, 2021
@saitho saitho added the cli Issue related to StackHead CLI label Sep 17, 2021
@saitho saitho added this to the v2.x milestone Sep 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cli Issue related to StackHead CLI
Projects
None yet
Development

No branches or pull requests

1 participant