Files
nomad/vendor/github.com/mitchellh/go-glint/components/progress.go
Isabel Suchanek 0edda116ad cli: add monitor flag to deployment status
Adding '-verbose' will print out the allocation information for the
deployment. This also changes the job run command so that it now blocks
until deployment is complete and adds timestamps to the output so that
it's more in line with the output of node drain.

This uses glint to print in place in running in a tty. Because glint
doesn't yet support cmd/powershell, Windows workflows use a different
library to print in place, which results in slightly different
formatting: 1) different margins, and 2) no spinner indicating
deployment in progress.
2021-06-09 16:18:45 -07:00

39 lines
938 B
Go

package components
import (
"context"
"github.com/cheggaaa/pb/v3"
"github.com/mitchellh/go-glint"
)
// ProgressElement renders a progress bar. This wraps the cheggaaa/pb package
// since that provides important functionality. This uses single call renders
// to render the progress bar as values change.
type ProgressElement struct {
*pb.ProgressBar
}
// Progress creates a new progress bar element with the given total.
// For more fine-grained control, please construct a ProgressElement
// directly.
func Progress(total int) *ProgressElement {
return &ProgressElement{
ProgressBar: pb.New(total),
}
}
func (el *ProgressElement) Body(context.Context) glint.Component {
// If we have no progress bar render nothing.
if el.ProgressBar == nil {
return nil
}
// Write the current progress
return glint.TextFunc(func(rows, cols uint) string {
el.ProgressBar.SetWidth(int(cols))
return el.ProgressBar.String()
})
}