diff --git a/cmd/root.go b/cmd/root.go index 01d0988..9402fdd 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -7,7 +7,6 @@ import ( "path" "strings" - "github.com/k0kubun/go-ansi" "github.com/mitchellh/go-homedir" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -42,8 +41,6 @@ func Execute() { } func init() { - ansi.CursorHide() - cobra.OnInitialize(initConfig) cobra.OnInitialize(initLogging) diff --git a/image/docker_image.go b/image/docker_image.go index 1991040..ca259ab 100644 --- a/image/docker_image.go +++ b/image/docker_image.go @@ -86,7 +86,6 @@ func (image *dockerImageAnalyzer) Parse(tarFile io.ReadCloser) error { header, err := tarReader.Next() if err == io.EOF { - fmt.Println(" ╧") break } @@ -191,36 +190,20 @@ func (image *dockerImageAnalyzer) Analyze() (*AnalysisResult, error) { }, nil } -// todo: it is bad that this is printing out to the screen. As the interface gets more flushed out, an event update mechanism should be built in (so the caller can format and print updates) func (image *dockerImageAnalyzer) processLayerTar(name string, layerIdx uint, reader *tar.Reader) error { tree := filetree.NewFileTree() tree.Name = name - title := fmt.Sprintf("[layer: %2d]", layerIdx) - message := fmt.Sprintf(" ├─ %s %s ", title, "working...") - fmt.Printf("\r%s", message) - fileInfos, err := image.getFileList(reader) if err != nil { return err } - shortName := name[:15] - pb := utils.NewProgressBar(int64(len(fileInfos)), 30) - for idx, element := range fileInfos { + for _, element := range fileInfos { tree.FileSize += uint64(element.Size) - // todo: we should check for errors but also allow whiteout files to be not be added (thus not error out) tree.AddPath(element.Path, element) - - if pb.Update(int64(idx)) { - message = fmt.Sprintf(" ├─ %s %s : %s", title, shortName, pb.String()) - fmt.Printf("\r%s", message) - } } - pb.Done() - message = fmt.Sprintf(" ├─ %s %s : %s", title, shortName, pb.String()) - fmt.Printf("\r%s\n", message) image.layerMap[tree.Name] = tree return nil diff --git a/utils/exit.go b/utils/exit.go index df2abe3..41b272e 100644 --- a/utils/exit.go +++ b/utils/exit.go @@ -3,7 +3,6 @@ package utils import ( "fmt" "github.com/jroimartin/gocui" - "github.com/k0kubun/go-ansi" "github.com/sirupsen/logrus" "os" ) @@ -31,5 +30,4 @@ func Cleanup() { if ui != nil { ui.Close() } - ansi.CursorShow() } diff --git a/utils/progress.go b/utils/progress.go deleted file mode 100644 index 873d2bc..0000000 --- a/utils/progress.go +++ /dev/null @@ -1,49 +0,0 @@ -package utils - -import ( - "fmt" - "strings" -) - -type progressBar struct { - width int - percent int - rawTotal int64 - rawCurrent int64 -} - -func NewProgressBar(total int64, width int) *progressBar { - return &progressBar{ - rawTotal: total, - width: width, - } -} - -func (pb *progressBar) Done() { - pb.rawCurrent = pb.rawTotal - pb.percent = 100 -} - -func (pb *progressBar) Update(currentValue int64) (hasChanged bool) { - pb.rawCurrent = currentValue - percent := int(100.0 * (float64(pb.rawCurrent) / float64(pb.rawTotal))) - if percent != pb.percent { - hasChanged = true - } - pb.percent = percent - return hasChanged -} - -func (pb *progressBar) String() string { - done := int((pb.percent * pb.width) / 100.0) - if done > pb.width { - done = pb.width - } - todo := pb.width - done - if todo < 0 { - todo = 0 - } - head := 1 - - return "[" + strings.Repeat("=", done) + strings.Repeat(">", head) + strings.Repeat(" ", todo) + "]" + fmt.Sprintf(" %d %% (%d/%d)", pb.percent, pb.rawCurrent, pb.rawTotal) -}