summaryrefslogtreecommitdiffstats
path: root/stdout/stdout.go
diff options
context:
space:
mode:
Diffstat (limited to 'stdout/stdout.go')
-rw-r--r--stdout/stdout.go69
1 files changed, 42 insertions, 27 deletions
diff --git a/stdout/stdout.go b/stdout/stdout.go
index 355097c..fcdafef 100644
--- a/stdout/stdout.go
+++ b/stdout/stdout.go
@@ -20,16 +20,23 @@ import (
// UI struct
type UI struct {
*common.UI
- output io.Writer
- red *color.Color
- orange *color.Color
- blue *color.Color
+ output io.Writer
+ red *color.Color
+ orange *color.Color
+ blue *color.Color
+ summarize bool
}
var progressRunes = []rune(`⠇⠏⠋⠙⠹⠸⠼⠴⠦⠧`)
// CreateStdoutUI creates UI for stdout
-func CreateStdoutUI(output io.Writer, useColors bool, showProgress bool, showApparentSize bool) *UI {
+func CreateStdoutUI(
+ output io.Writer,
+ useColors bool,
+ showProgress bool,
+ showApparentSize bool,
+ summarize bool,
+) *UI {
ui := &UI{
UI: &common.UI{
UseColors: useColors,
@@ -37,7 +44,8 @@ func CreateStdoutUI(output io.Writer, useColors bool, showProgress bool, showApp
ShowApparentSize: showApparentSize,
Analyzer: analyze.CreateAnalyzer(),
},
- output: output,
+ output: output,
+ summarize: summarize,
}
ui.red = color.New(color.FgRed).Add(color.Bold)
@@ -138,7 +146,11 @@ func (ui *UI) AnalyzePath(path string, _ *analyze.Dir) error {
wait.Wait()
- ui.showDir(dir)
+ if ui.summarize {
+ ui.printItem(dir)
+ } else {
+ ui.showDir(dir)
+ }
return nil
}
@@ -146,6 +158,12 @@ func (ui *UI) AnalyzePath(path string, _ *analyze.Dir) error {
func (ui *UI) showDir(dir *analyze.Dir) {
sort.Sort(dir.Files)
+ for _, file := range dir.Files {
+ ui.printItem(file)
+ }
+}
+
+func (ui *UI) printItem(file analyze.Item) {
var lineFormat string
if ui.UseColors {
lineFormat = "%s %20s %s\n"
@@ -154,27 +172,24 @@ func (ui *UI) showDir(dir *analyze.Dir) {
}
var size int64
+ if ui.ShowApparentSize {
+ size = file.GetSize()
+ } else {
+ size = file.GetUsage()
+ }
- for _, file := range dir.Files {
- if ui.ShowApparentSize {
- size = file.GetSize()
- } else {
- size = file.GetUsage()
- }
-
- if file.IsDir() {
- fmt.Fprintf(ui.output,
- lineFormat,
- string(file.GetFlag()),
- ui.formatSize(size),
- ui.blue.Sprintf("/"+file.GetName()))
- } else {
- fmt.Fprintf(ui.output,
- lineFormat,
- string(file.GetFlag()),
- ui.formatSize(size),
- file.GetName())
- }
+ if file.IsDir() {
+ fmt.Fprintf(ui.output,
+ lineFormat,
+ string(file.GetFlag()),
+ ui.formatSize(size),
+ ui.blue.Sprintf("/"+file.GetName()))
+ } else {
+ fmt.Fprintf(ui.output,
+ lineFormat,
+ string(file.GetFlag()),
+ ui.formatSize(size),
+ file.GetName())
}
}