move helper methods to util

This commit is contained in:
Bradley Cicenas
2016-12-25 13:06:57 -06:00
parent 2a09ccc4a6
commit ca9ea17a81
4 changed files with 89 additions and 72 deletions
+37
View File
@@ -0,0 +1,37 @@
package main
import (
"math"
ui "github.com/gizak/termui"
)
func byteFormat(n uint64) string {
if n < 1024 {
return fmt.Sprintf("%sB", strconv.FormatUint(n, 10))
}
if n < 1048576 {
n = n / 1024
return fmt.Sprintf("%sK", strconv.FormatUint(n, 10))
}
if n < 1073741824 {
n = n / 1048576
return fmt.Sprintf("%sM", strconv.FormatUint(n, 10))
}
n = n / 1024000000
return fmt.Sprintf("%sG", strconv.FormatUint(n, 10))
}
func round(num float64) int {
return int(num + math.Copysign(0.5, num))
}
func colorScale(n int) ui.Attribute {
if n > 70 {
return ui.ColorRed
}
if n > 30 {
return ui.ColorYellow
}
return ui.ColorGreen
}