Skip to content

Commit 57ad8fc

Browse files
committed
More style fixes
Thanks @alaviss for guidance
1 parent 599b3a0 commit 57ad8fc

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

src/file_size_distribution.nim

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os, strutils, math, terminal, fusion/btreetables
22

33
const
4-
HistogramBlocks = ["","","","","","","",""]
4+
HistogramBlocks = ["", "", "", "", "", "", "", ""]
55
ProgressChars = ["", "", "", "", "", "", "", ""]
66

77
type
@@ -45,19 +45,20 @@ func getLog2Stats(fs: FsStat): seq[Stat] =
4545
result.add(initStat())
4646
for size, n in fs.table.pairs:
4747
for _ in 1..n:
48-
let bin = if size == 0:
48+
let bin =
49+
if size == 0:
4950
0
5051
else:
5152
toInt(floor(log2(toBiggestFloat(size)) / 2)) + 1
5253
addFile(result[bin], size)
5354

54-
func drawBar(num, maxNum: Natural; width: Natural): string =
55+
func drawBar(num, maxNum, width: Natural): string =
5556
let
5657
f = toFloat(num) / toFloat(maxNum) * toFloat(width)
5758
full = toInt(floor(f))
5859
tail = f - trunc(f)
5960
var
60-
partial = toInt(round(7.0*tail))
61+
partial = toInt(round(7.0 * tail))
6162
if partial == 0 and full == 0 and num > 0:
6263
partial = 1
6364
for _ in 1..full:
@@ -86,15 +87,17 @@ proc walkFs(path: string): FsStat =
8687
result.stat.filesSeen.inc()
8788
check.inc()
8889
result.stat.totalSize += fSize
89-
result.stat.maxSize = max(result.stat.maxSize,fSize)
90-
result.stat.minSize = min(result.stat.minSize,fSize)
90+
result.stat.maxSize = max(result.stat.maxSize, fSize)
91+
result.stat.minSize = min(result.stat.minSize, fSize)
9192
result.table.inc(fSize)
92-
mainThreadBusy = false
93-
joinThread(thProgress)
94-
stdout.write("\r")
93+
defer:
94+
mainThreadBusy = false
95+
joinThread(thProgress)
96+
stdout.write("\r")
9597

9698
when isMainModule:
97-
var startPath = if paramCount() > 0:
99+
var startPath =
100+
if paramCount() > 0:
98101
paramStr(1)
99102
else:
100103
getCurrentDir()
@@ -107,26 +110,27 @@ when isMainModule:
107110
echo("Stats for files by size strata; Bars: file count.")
108111
var
109112
statStrSeq: seq[(string,BiggestInt)]
110-
maxNum:BiggestInt = 0
113+
maxNum: BiggestInt = 0
111114
maxLineLen = 0
112115
for bin, s in stats.pairs:
113116
let
114117
maxSize = if s.filesSeen == 0: BiggestInt(0) else: s.maxSize
115-
line = if bin == 0:
116-
format("$1: Max: $2; $3 files", [
117-
align(formatSize(0), 16),
118-
align(formatSize(maxSize), 11),
119-
$s.filesSeen
120-
])
121-
else:
122-
let curStrata = toInt(2.0.pow(toFloat(bin)*2))
123-
let prevStrata = toInt(2.0.pow(toFloat(bin-1)*2))
124-
format("$1$2: Max: $3; $4 files", [
125-
alignLeft(formatSize(prevStrata) & "<", 8, '.'),
126-
align("<" & formatSize(curStrata), 8, '.'),
127-
align(formatSize(maxSize), 11),
128-
$s.filesSeen
129-
])
118+
line =
119+
if bin == 0:
120+
format("$1: Max: $2; $3 files", [
121+
align(formatSize(0), 16),
122+
align(formatSize(maxSize), 11),
123+
$s.filesSeen
124+
])
125+
else:
126+
let curStrata = toInt(2.0.pow(toFloat(bin) * 2))
127+
let prevStrata = toInt(2.0.pow(toFloat(bin - 1) * 2))
128+
format("$1$2: Max: $3; $4 files", [
129+
alignLeft(formatSize(prevStrata) & "<", 8, '.'),
130+
align("<" & formatSize(curStrata), 8, '.'),
131+
align(formatSize(maxSize), 11),
132+
$s.filesSeen
133+
])
130134
maxLineLen = max(maxLineLen, line.len())
131135
maxNum = max(maxNum, s.filesSeen)
132136
statStrSeq.add((line, s.filesSeen))

0 commit comments

Comments
 (0)