diff options
author | bptato <nincsnevem662@gmail.com> | 2022-11-27 15:44:42 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-11-27 15:44:42 +0100 |
commit | 3a12afa7617f3ccecbbf6b5852da3d6382a412bb (patch) | |
tree | 7596ce7f667b9dabec6ec71c9bd05b9de67feb93 /src/utils | |
parent | e7f157c792f53cb084e8694ee608f00727432a3d (diff) | |
download | chawan-3a12afa7617f3ccecbbf6b5852da3d6382a412bb.tar.gz |
Fix some regressions, add loading progress bar
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/twtstr.nim | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/utils/twtstr.nim b/src/utils/twtstr.nim index 2123daeb..3d33f8d1 100644 --- a/src/utils/twtstr.nim +++ b/src/utils/twtstr.nim @@ -224,6 +224,19 @@ func skipBlanks*(buf: string, at: int): int = while result < buf.len and buf[result].isWhitespace(): inc result +# From w3m +const SizeUnit = [ + "b", "kb", "Mb", "Gb", "Tb", "Pb", "Eb", "Zb", "Bb", "Yb" +] +func convert_size*(len: int): string = + var sizepos = 0 + var csize = float(len) + while csize >= 999.495 and sizepos < SizeUnit.len: + csize = csize / 1024.0 + inc sizepos + result = $(floor(csize * 100 + 0.5) / 100) + result &= SizeUnit[sizepos] + func until*(s: string, c: set[char]): string = var i = 0 while i < s.len: |