Skip to content

Instantly share code, notes, and snippets.

@mrnugget
Created January 28, 2020 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrnugget/f46caf71b214ae6b6ffa9880a0036003 to your computer and use it in GitHub Desktop.
Save mrnugget/f46caf71b214ae6b6ffa9880a0036003 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"io"
"os"
"sync"
"time"
"github.com/fatih/color"
"github.com/gosuri/uilive"
)
func main() {
uilive.Out = os.Stderr
uilive.RefreshInterval = 10 * time.Hour
color.NoColor = false
var (
lwMu sync.Mutex
lw = uilive.New()
)
lw.Start()
defer lw.Stop()
// foobar
lwMu.Lock()
defer lwMu.Unlock()
spinner := []rune{'⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'}
spinnerI := 0
start := time.Now()
names := []string{
"github.com/sourcegraph/foobar1",
"github.com/sourcegraph/foobar2",
"github.com/sourcegraph/foobar3",
"github.com/sourcegraph/foobar4",
"github.com/sourcegraph/foobar5",
"github.com/sourcegraph/foobar6",
}
for i := 0; i < 100; i++ {
spinnerRune := spinner[spinnerI%len(spinner)]
spinnerI++
statusColor := color.GreenString
timerDuration := time.Since(start)
for j, n := range names {
var w io.Writer
if j == 0 {
w = lw
} else {
w = lw.Newline()
}
fmt.Fprintf(w, "%s %s %s %s",
statusColor(fmt.Sprintf("%-*s", len(n), n)),
color.HiBlackString("|"),
statusColor(string(spinnerRune)),
"/var/logs/this-is-really-long-and-should-bust-the-display",
)
fmt.Fprintf(w, color.HiBlackString(" %s"), timerDuration.Round(time.Second))
fmt.Fprintln(w)
}
_ = lw.Flush()
time.Sleep(50 * time.Millisecond)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment