Skip to content

Commit 602ded3

Browse files
authored
refactor: adjust style (#18)
* refactor: adjust style * refactor: adjust style
1 parent abe6a35 commit 602ded3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

internal/stat.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ func Stat(cmd *cobra.Command, _ []string) error {
123123
totalSize += f.size
124124
}
125125

126-
header := fmt.Sprintf("Total: %s\t%s", getReduce(unit, totalSize), color.HiGreenString(dir))
126+
val, reduceUnit := getReduce(unit, totalSize)
127+
header := fmt.Sprintf("Total: %0.3f%s\t%s", val, reduceUnit, color.HiGreenString(dir))
127128
colorPrintln(header)
128129
colorPrintln(strings.Repeat("-", len(header)+2))
129130
printFiles(files, 0, depth, unit)
@@ -234,8 +235,8 @@ func printFiles(files []file, n, depth int, unit string) {
234235

235236
bar := strings.Repeat(" ", n) + "|--"
236237
for _, f := range files {
237-
238-
part1 := fmt.Sprintf("%s %s %s", f.modifyTime.Format("20060102 15:04:05"), f.mode, getReduce(unit, f.size))
238+
val, reduceUnit := getReduce(unit, f.size)
239+
part1 := fmt.Sprintf("%s %s %9.3f%s", f.modifyTime.Format("20060102 15:04:05"), f.mode, val, reduceUnit)
239240
part2 := color.HiGreenString(f.name)
240241
var s = bar
241242
if f.isDir {
@@ -251,7 +252,7 @@ func printFiles(files []file, n, depth int, unit string) {
251252
}
252253
}
253254

254-
func getReduce(unit string, n int64) string {
255+
func getReduce(unit string, n int64) (float64, string) {
255256
reduce := 0
256257
switch unit {
257258
case "B":
@@ -278,7 +279,7 @@ func getReduce(unit string, n int64) string {
278279

279280
}
280281

281-
return fmt.Sprintf("%9.3f%s", float64(n)/float64(units[reduce]), unitStrings[reduce])
282+
return float64(n) / float64(units[reduce]), unitStrings[reduce]
282283
}
283284

284285
func colorPrintln(a ...any) {

0 commit comments

Comments
 (0)