From 842a8c4250ca17bb4c11417c0e69aad74b75ac80 Mon Sep 17 00:00:00 2001 From: hkc Date: Tue, 3 Oct 2023 19:46:25 +0300 Subject: [PATCH] Added progressbar --- tapeget.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tapeget.lua b/tapeget.lua index 732b93e..f567d04 100644 --- a/tapeget.lua +++ b/tapeget.lua @@ -24,7 +24,12 @@ end local headers = req.getResponseHeaders() local length = headers["content-length"] -local i = 1 +local function n_to_kib(value) + return string.format("%6.1f kiB", value / 1024) +end + +local written = 1 +local _, y = term.getCursorPos() while true do local chunk = req.read() if not chunk then @@ -32,10 +37,11 @@ while true do break end tape.write(chunk) - i = i + 1 - if (i % 16384) == 0 then + written = written + 1 + if (written % 8192) == 0 then os.sleep(0.01) - print(i .. " written out of "..length) + term.setCursorPos(1, y) + term.write(n_to_kib(written) .. " / " .. n_to_kib(length) .. string.format(" %7.3f%%", 100 * written / length)) end end