Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
2.999 G / 2.999 G▕ ▏ 0.00% -- 10.00 k/s 02:50:00
9999 B / 9999 B▕██████████ ▏ 50.00% -- 10.00 k/s 00:59:59
10.00 k / 10.00 k▕██████████▏ ▏ 50.12% -- 10.00 k/s 55:59
99.99 k / 99.99 k▕██████████▎ ▏ 50.25% -- 99.99 k/s 10:00
100.0 k / 100.0 k▕██████████▍ ▏ 50.37% -- 100.0 k/s 09:59
999.9 k / 999.9 k▕██████████▌ ▏ 50.50% -- 999.9 k/s 01:30
1.000 G / 1.000 M▕██████████▋ ▏ 50.62% -- 1.000 G/s 00:05
9.999 G / 9.999 M▕██████████▊ ▏ 50.75% -- 9.999 G/s 00:00
10.00 G / 10.00 G▕██████████▉ ▏ 50.87% -- 10.00 G/s 2d, 22:22:22
99.99 G / 99.99 G▕███████████ ▏ 51.00% -- 99.99 G/s 9999d, 11:11:11
100.0 G / 100.0 G▕███████████████████ ▏ 99.00% -- 100.0 G/s 00:01:00
999.9 G / 999.9 G▕███████████████████▏▏ 99.12% -- 999.9 G/s 00:01:00
1.000 T / 1.000 T▕███████████████████▎▏ 99.25% -- 1.000 T/s 00:01:00
10.00 T / 10.00 T▕███████████████████▍▏ 99.37% -- 10.00 T/s 00:01:00
100.0 T / 100.0 T▕███████████████████▌▏ 99.50% -- 100.0 T/s 00:01:00
1000 T / 1000 T▕███████████████████▋▏ 99.62% -- 1000 T/s 00:01:00
10000 T / 10000 T▕███████████████████▊▏ 99.75% -- 10000 T/s 00:01:00
1.9e9 T / 1.9e9 T▕███████████████████▉▏ 99.87% -- 1.9e9 T/s 00:01:00
2e10 T / 2e10 T▕████████████████████▏100.00% -- 2e10 T/s 00:01:00
------------------------------
CHARACTERS
1/8: ▏ | U+258F
2/8: ▎ | U+258E
3/8: ▍ | U+258D
4/8: ▌ | U+258C
5/8: ▋ | U+258B
6/8: ▊ | U+258A
7/8: ▉ | U+2589
8/8: █ | U+2588
local comp = require("computer")
local unicode = require("unicode")
local units = {"B", "k", "M", "G", "T"}
local chars = {[0] = ""}
for i = 0x258f, 0x2588, -1 do
table.insert(chars, unicode.char(i))
end
local function formatFSize(fsize)
local result = ""
if fsize < 10e3 then
print("<")
local fstr = "%.4f"
if math.floor(fsize) == fsize then -- Integer check
fstr = "%d"
end
result = fstr:format(fsize):sub(1, 5):gsub("%.$", function(c) return "" end)
result = result .. (" "):rep(6 - #result) .. units[1]
elseif fsize < 10e13 then
local digits = #("%d"):format(fsize)
local unit = units[math.floor((digits - 1) / 3) + 1]
result = ("%.13f"):format(fsize / (10 ^ (math.floor((digits - 1) / 3) * 3))):sub(1, 5)
result = result .. (" "):rep(6 - #result) .. unit
else
result = ("%.1e"):format(fsize)
end
return result
end
local function progress(fgot, ftotal, tstart, width)
local perc = 0
if tonumber(tostring(fgot / ftotal)) then
perc = fgot / ftotal * 100
if perc > 100 then
perc = 100
end
else
error("The programmer has derped! fgot = 0, ftotal = 0, perc = -nan, undefined behaviour!")
end
local pstr = ("%.2f"):format(perc)
local delta = comp.uptime() - tstart
local perperc = delta / perc
local t = (100 - perc) * perperc
local time = "n/a"
local cspeed = ""
if tonumber(tostring(t)) then
cspeed = tonumber(tostring(fgot / delta))
cspeed = cspeed and (formatFSize(cspeed) .. "/s") or "n/a"
local days = math.floor(t / 86400)
t = t - days * 86400
local hours = math.floor(t / 3600)
t = t - hours * 3600
local minutes = math.floor(t / 60)
local seconds = t - minutes * 60
time = ("%02d"):format(seconds)
time = ("%02d"):format(minutes) .. ":" .. time
if hours ~= 0 or days ~= 0 then
time = ("%02d"):format(hours) .. ":" .. time
end
if days ~= 0 then
time = tostring(days) .. "d, " .. time
end
end
local lpart = formatFSize(fgot) .. " / " .. formatFSize(ftotal) .. ""
local rpart = chars[1] .. (" "):rep(6 - #pstr) .. pstr .. "% " .. cspeed .. " -- " .. time
local pwidth = width - unicode.len(lpart) - unicode.len(rpart)
local cwidth = pwidth / 100
local fr = tonumber(select(2, math.modf(perc * cwidth)))
local lastblockindex = math.floor(fr * 8)
if lastblockindex == 8 then
lastblockindex = 7
end
local lastblock = chars[lastblockindex]
local blocks = math.floor(perc * cwidth)
local result = lpart .. chars[8]:rep(blocks) .. lastblock
result = result .. (" "):rep(width - unicode.len(result) - unicode.len(rpart)) .. rpart
return result
end
return progress
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment