diskspace/utils.go

78 lines
1.9 KiB
Go
Raw Normal View History

2022-06-28 13:11:16 +02:00
package main
import (
"math"
"os"
"strconv"
)
func fmtSize(size uint64) string {
sf := float64(size)
if size/1000000000000 >= 1 {
return strconv.FormatFloat(round(sf/1000000000000), 'G', -1, 64) + " TB"
} else if size/1000000000 >= 1 {
return strconv.FormatFloat(round(sf/1000000000), 'G', -1, 64) + " GB"
} else if size/1000000 >= 1 {
return strconv.FormatFloat(round(sf/1000000), 'G', -1, 64) + " MB"
} else if size/1000 >= 1 {
return strconv.FormatFloat(round(sf/1000), 'G', -1, 64) + " KB"
} else {
return strconv.FormatFloat(round(sf), 'G', -1, 64) + " B"
}
}
func round(value float64) float64 {
return math.Round(value*100) / 100
}
func icon(ext string) string {
switch *IconTheme {
default:
fallthrough
case "unicode":
switch ext {
case "folder":
return "📂"
default:
return "📄"
}
case "nerd":
switch ext {
case "app":
return "ﬓ"
case "folder":
return ""
case ".doc", ".docx", ".odt", ".rtx", ".pdf", ".tex":
return ""
case ".xls", ".xlsx", ".xlsm", ".dex", ".ods", ".csv":
return ""
case ".jpg", ".jpeg", ".png", ".gif", ".ppm", ".svg", ".tiff", ".bmp", ".webp", ".blend", ".obj":
return ""
case ".go", ".c", ".cpp", ".rs", ".h", ".java", ".asm", ".js", ".html", ".css", ".ts", ".sql":
return ""
case ".mp3", ".flac", ".m4a", ".opus", ".wav", ".wma":
return ""
case ".mp4", ".webm", ".mkv", ".flv", ".ogg", ".ogv", ".gifv", ".avi", ".mov", ".wmv", ".mp2", ".mpg", ".mpv", ".mpe", ".mpeg", ".m2v", ".3gp":
return ""
case ".txt":
return ""
case ".zip", ".rar", ".7z", ".tar", ".bz2", ".gz", ".xz", ".tgz", ".tbz2", ".txz":
return ""
case ".iso":
return "﫭"
case ".apk":
return ""
case ".jar":
return ""
case ".json", ".yaml", ".yml":
return ""
default:
return ""
}
}
}
func clearEOL() {
os.Stdout.Write([]byte{0x1b, 0x5b, 0x4b})
}