Skip to content

Commit

Permalink
fixed not showing colors for export
Browse files Browse the repository at this point in the history
fixes #76
  • Loading branch information
dundee committed Jul 23, 2021
1 parent 045ad4d commit da5f797
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions cmd/gdu/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (a *App) createUI() (UI, error) {
ui = report.CreateExportUI(
a.Writer,
output,
!a.Flags.NoColor && a.Istty,
!a.Flags.NoProgress && a.Istty,
)
return ui, nil
Expand Down
6 changes: 5 additions & 1 deletion report/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type UI struct {
}

// CreateExportUI creates UI for stdout
func CreateExportUI(output io.Writer, exportOutput io.Writer, showProgress bool) *UI {
func CreateExportUI(output io.Writer, exportOutput io.Writer, useColors bool, showProgress bool) *UI {
ui := &UI{
UI: &common.UI{
ShowProgress: showProgress,
Expand All @@ -43,6 +43,10 @@ func CreateExportUI(output io.Writer, exportOutput io.Writer, showProgress bool)
ui.red = color.New(color.FgRed).Add(color.Bold)
ui.orange = color.New(color.FgYellow).Add(color.Bold)

if !useColors {
color.NoColor = true
}

return ui
}

Expand Down
12 changes: 6 additions & 6 deletions report/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestAnalyzePath(t *testing.T) {
output := bytes.NewBuffer(make([]byte, 10))
reportOutput := bytes.NewBuffer(make([]byte, 10))

ui := CreateExportUI(output, reportOutput, false)
ui := CreateExportUI(output, reportOutput, false, false)
ui.SetIgnoreDirPaths([]string{"/xxx"})
err := ui.AnalyzePath("test_dir", nil)
assert.Nil(t, err)
Expand All @@ -40,7 +40,7 @@ func TestAnalyzePathWithProgress(t *testing.T) {
output := bytes.NewBuffer(make([]byte, 10))
reportOutput := bytes.NewBuffer(make([]byte, 10))

ui := CreateExportUI(output, reportOutput, true)
ui := CreateExportUI(output, reportOutput, true, true)
ui.SetIgnoreDirPaths([]string{"/xxx"})
err := ui.AnalyzePath("test_dir", nil)
assert.Nil(t, err)
Expand All @@ -54,7 +54,7 @@ func TestShowDevices(t *testing.T) {
output := bytes.NewBuffer(make([]byte, 10))
reportOutput := bytes.NewBuffer(make([]byte, 10))

ui := CreateExportUI(output, reportOutput, true)
ui := CreateExportUI(output, reportOutput, false, true)
err := ui.ListDevices(device.Getter)

assert.Contains(t, err.Error(), "not supported")
Expand All @@ -64,7 +64,7 @@ func TestReadAnalysisWhileExporting(t *testing.T) {
output := bytes.NewBuffer(make([]byte, 10))
reportOutput := bytes.NewBuffer(make([]byte, 10))

ui := CreateExportUI(output, reportOutput, true)
ui := CreateExportUI(output, reportOutput, false, true)
err := ui.ReadAnalysis(output)

assert.Contains(t, err.Error(), "not possible while exporting")
Expand All @@ -82,7 +82,7 @@ func TestExportToFile(t *testing.T) {

output := bytes.NewBuffer(make([]byte, 10))

ui := CreateExportUI(output, reportOutput, true)
ui := CreateExportUI(output, reportOutput, false, true)
ui.SetIgnoreDirPaths([]string{"/xxx"})
err = ui.AnalyzePath("test_dir", nil)
assert.Nil(t, err)
Expand All @@ -104,7 +104,7 @@ func TestFormatSize(t *testing.T) {
output := bytes.NewBuffer(make([]byte, 10))
reportOutput := bytes.NewBuffer(make([]byte, 10))

ui := CreateExportUI(output, reportOutput, true)
ui := CreateExportUI(output, reportOutput, false, true)

assert.Contains(t, ui.formatSize(1), "B")
assert.Contains(t, ui.formatSize(1<<10+1), "KiB")
Expand Down

0 comments on commit da5f797

Please sign in to comment.