Skip to content

Commit

Permalink
update coloring to only use three, similar to signal lights
Browse files Browse the repository at this point in the history
  • Loading branch information
yashbhutwala committed Jul 12, 2020
1 parent d84c683 commit d74416d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ A `kubectl` plugin to see `df` for persistent volumes.

☑ human readable output as default (using IEC format)

☑ color based on usage (i.e.: > 75% = red; > 50% = magenta; > 25% = yellow; default = green)
&#9745; color based on usage [red: > 75% (too high); yellow: < 25% (too low); green: >= 25 and <= 75 (OK)]

&#9746; sort-by flag

Expand Down
18 changes: 9 additions & 9 deletions pkg/df-pv/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func setupRootCommand() *cobra.Command {
It autoconverts all "sizes" to IEC values (see: https://en.wikipedia.org/wiki/Binary_prefix and https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#meaning-of-memory)
It colors the values based on "severity" (i.e.: > 75% = red; > 50% = magenta; > 25% = yellow; default = green)`,
It colors the values based on "severity" [red: > 75% (too high); yellow: < 25% (too low); green: >= 25 and <= 75 (OK)]`,
Args: cobra.MaximumNArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
return runRootCommand(flags)
Expand Down Expand Up @@ -86,17 +86,18 @@ func runRootCommand(flags *flagpole) error {
}

func PrintUsingGoPretty(sliceOfOutputRowPVC []*OutputRowPVC) {
// https://github.com/jedib0t/go-pretty/tree/master/table#table
// https://github.com/jedib0t/go-pretty/tree/v6.0.4/table
t := table.NewWriter()

t.AppendHeader(table.Row{"PVC", "Namespace", "Pod", "Size", "Used", "Available", "%Used", "iused", "ifree", "%iused"})
hiWhiteColor := text.FgHiWhite
for _, pvcRow := range sliceOfOutputRowPVC {
percentageUsedColor := GetColorFromPercentageUsed(pvcRow.PercentageUsed)
percentageIUsedColor := GetColorFromPercentageUsed(pvcRow.PercentageIUsed)
t.AppendRow([]interface{}{
fmt.Sprintf("%s", pvcRow.PVCName),
fmt.Sprintf("%s", pvcRow.Namespace),
fmt.Sprintf("%s", pvcRow.PodName),
hiWhiteColor.Sprintf("%s", pvcRow.PVCName),
hiWhiteColor.Sprintf("%s", pvcRow.Namespace),
hiWhiteColor.Sprintf("%s", pvcRow.PodName),
percentageUsedColor.Sprintf("%s", ConvertQuantityValueToHumanReadableIECString(pvcRow.CapacityBytes)),
percentageUsedColor.Sprintf("%s", ConvertQuantityValueToHumanReadableIECString(pvcRow.UsedBytes)),
percentageUsedColor.Sprintf("%s", ConvertQuantityValueToHumanReadableIECString(pvcRow.AvailableBytes)),
Expand All @@ -107,10 +108,11 @@ func PrintUsingGoPretty(sliceOfOutputRowPVC []*OutputRowPVC) {
})
}

// https://github.com/jedib0t/go-pretty/blob/master/table/style.go
// https://github.com/jedib0t/go-pretty/blob/v6.0.4/table/style.go
styleBold := table.StyleBold
styleBold.Options = table.OptionsNoBordersAndSeparators
t.SetStyle(styleBold)
t.Style().Color.Header = text.Colors{hiWhiteColor, text.Bold}
// t.Style().Options.SeparateRows = true
// t.SetAutoIndex(true)
// t.SetOutputMirror(os.Stdout)
Expand All @@ -120,9 +122,7 @@ func PrintUsingGoPretty(sliceOfOutputRowPVC []*OutputRowPVC) {
func GetColorFromPercentageUsed(percentageUsed float64) text.Color {
if percentageUsed > 75 {
return text.FgHiRed
} else if percentageUsed > 50 {
return text.FgHiMagenta
} else if percentageUsed > 25 {
} else if percentageUsed < 25 {
return text.FgHiYellow
} else {
return text.FgHiGreen
Expand Down

0 comments on commit d74416d

Please sign in to comment.