storj/private/cui/example.go

53 lines
844 B
Go
Raw Normal View History

2019-02-06 08:04:12 +00:00
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
//go:build ignore
2019-02-06 08:04:12 +00:00
// +build ignore
package main
import (
"context"
"fmt"
"strings"
"time"
"golang.org/x/sync/errgroup"
"storj.io/storj/private/cui"
2019-02-06 08:04:12 +00:00
)
func main() {
screen, err := cui.NewScreen()
if err != nil {
fmt.Println(err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var group errgroup.Group
group.Go(func() error {
defer cancel()
return screen.Run()
})
counter := 0
for ctx.Err() == nil {
width, _ := screen.Size()
fmt.Fprintf(screen, "%2d\n", counter)
fmt.Fprintf(screen, "%s\n", strings.Repeat("=", width))
screen.Flush()
counter++
time.Sleep(time.Second)
}
if err := screen.Close(); err != nil {
fmt.Println(err)
}
if err := group.Wait(); err != nil {
fmt.Println(err)
}
}