From 79ca4d09d107ecdb4297f9f98fefe058783b2bd7 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Wed, 18 Nov 2020 18:38:34 -0500 Subject: [PATCH] Fix doc comments and remove magic number --- go.mod | 1 + go.sum | 2 ++ progress/example/go.mod | 4 ++-- progress/example/go.sum | 1 + progress/progress.go | 8 +++++--- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 01df893..40af13b 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/charmbracelet/bubbletea v0.12.2 github.com/lucasb-eyer/go-colorful v1.0.3 github.com/mattn/go-runewidth v0.0.9 + github.com/muesli/reflow v0.2.0 github.com/muesli/termenv v0.7.4 golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 // indirect golang.org/x/sys v0.0.0-20201020230747-6e5568b54d1a // indirect diff --git a/go.sum b/go.sum index a1c370b..d16a387 100644 --- a/go.sum +++ b/go.sum @@ -12,6 +12,8 @@ github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHX github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/muesli/reflow v0.2.0 h1:2o0UBJPHHH4fa2GCXU4Rg4DwOtWPMekCeyc5EWbAQp0= +github.com/muesli/reflow v0.2.0/go.mod h1:qT22vjVmM9MIUeLgsVYe/Ye7eZlbv9dZjL3dVhUqLX8= github.com/muesli/termenv v0.7.2 h1:r1raklL3uKE7rOvWgSenmEm2px+dnc33OTisZ8YR1fw= github.com/muesli/termenv v0.7.2/go.mod h1:ct2L5N2lmix82RaY3bMWwVu/jUFc9Ule0KGDCiKYPh8= github.com/muesli/termenv v0.7.4 h1:/pBqvU5CpkY53tU0vVn+xgs2ZTX63aH5nY+SSps5Xa8= diff --git a/progress/example/go.mod b/progress/example/go.mod index 768a188..bd98aae 100644 --- a/progress/example/go.mod +++ b/progress/example/go.mod @@ -5,6 +5,6 @@ replace github.com/charmbracelet/bubbles => ../../ go 1.15 require ( - github.com/charmbracelet/bubbles v0.0.0-00010101000000-000000000000 // indirect - github.com/muesli/reflow v0.2.0 // indirect + github.com/charmbracelet/bubbles v0.0.0-00010101000000-000000000000 + github.com/charmbracelet/bubbletea v0.12.2 ) diff --git a/progress/example/go.sum b/progress/example/go.sum index deac0d6..bb97e9b 100644 --- a/progress/example/go.sum +++ b/progress/example/go.sum @@ -15,6 +15,7 @@ github.com/muesli/reflow v0.2.0/go.mod h1:qT22vjVmM9MIUeLgsVYe/Ye7eZlbv9dZjL3dVh github.com/muesli/termenv v0.7.2/go.mod h1:ct2L5N2lmix82RaY3bMWwVu/jUFc9Ule0KGDCiKYPh8= github.com/muesli/termenv v0.7.4 h1:/pBqvU5CpkY53tU0vVn+xgs2ZTX63aH5nY+SSps5Xa8= github.com/muesli/termenv v0.7.4/go.mod h1:pZ7qY9l3F7e5xsAOS0zCew2tME+p7bWeBkotCEcIIcc= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= diff --git a/progress/progress.go b/progress/progress.go index f3a5087..c8793ca 100644 --- a/progress/progress.go +++ b/progress/progress.go @@ -9,6 +9,8 @@ import ( "github.com/muesli/termenv" ) +const defaultWidth = 40 + var color func(string) termenv.Color = termenv.ColorProfile().Color // Option is used to set options in NewModel. For example: @@ -45,7 +47,7 @@ func WithScaledRamp(colorA, colorB string) Option { } } -// WithSoildFill sets the progress to use a solid fill with the given color. +// WithSolidFill sets the progress to use a solid fill with the given color. func WithSolidFill(color string) Option { return func(m *Model) error { m.FullColor = color @@ -103,7 +105,7 @@ type Model struct { // NewModel returns a model with default values. func NewModel(opts ...Option) (*Model, error) { m := &Model{ - Width: 40, + Width: defaultWidth, Full: '█', FullColor: "#7571F9", Empty: '░', @@ -121,7 +123,7 @@ func NewModel(opts ...Option) (*Model, error) { return m, nil } -// view renders the progress bar as a given percentage. +// View renders the progress bar as a given percentage. func (m Model) View(percent float64) string { b := strings.Builder{} if m.ShowPercentage {