forked from hkc/cc-stuff
Improved tapeget and added some old mess
This commit is contained in:
parent
9b6b198798
commit
58b63b4cde
|
@ -0,0 +1,43 @@
|
|||
term.clear()
|
||||
term.setCursorPos(1, 1)
|
||||
term.setTextColor(colors.white)
|
||||
|
||||
local tw, th = term.getSize()
|
||||
print(string.format("Terminal: %dx%d", tw, th))
|
||||
local function printScale(c1, c2, p, fmt, ...)
|
||||
local str = string.format(fmt, ...)
|
||||
local w1 = math.ceil(p * tw)
|
||||
local w2 = tw - w1
|
||||
|
||||
local bg = term.getBackgroundColor()
|
||||
term.setBackgroundColor(c1)
|
||||
term.write(str:sub(1, w1))
|
||||
local rem = w1 - #str
|
||||
if rem > 0 then
|
||||
term.write(string.rep(" ", rem))
|
||||
end
|
||||
|
||||
term.setBackgroundColor(c2)
|
||||
term.write(str:sub(w1 + 1, w1 + w2))
|
||||
|
||||
rem = math.min(tw - #str, w2)
|
||||
if rem > 0 then
|
||||
term.write(string.rep(" ", rem))
|
||||
end
|
||||
|
||||
term.setBackgroundColor(bg)
|
||||
print()
|
||||
end
|
||||
|
||||
|
||||
term.setBackgroundColor(colors.black)
|
||||
local t = 0
|
||||
while true do
|
||||
for i = 1, th do
|
||||
local p = 0.5 + 0.5 * math.sin((i + t) * math.pi / 25)
|
||||
term.setCursorPos(1, i)
|
||||
printScale(colors.red, colors.gray, p, "%7.3f%%", p * 100)
|
||||
end
|
||||
os.sleep(0.05)
|
||||
t = t + 1
|
||||
end
|
49
tapeget.lua
49
tapeget.lua
|
@ -1,5 +1,36 @@
|
|||
local args = { ... }
|
||||
|
||||
local function n_to_kib(value)
|
||||
return string.format("%6.1f kiB", value / 1024)
|
||||
end
|
||||
|
||||
local function textProgress(p, c1, c2, fmt, ...)
|
||||
p = math.min(p, 1)
|
||||
local tw = term.getSize()
|
||||
local str = string.format(fmt, ...)
|
||||
local w1 = math.ceil(p * tw)
|
||||
local w2 = tw - w1
|
||||
|
||||
local bg = term.getBackgroundColor()
|
||||
|
||||
term.setBackgroundColor(c1)
|
||||
term.write(str:sub(1, w1))
|
||||
local rem = w1 - #str
|
||||
if rem > 0 then
|
||||
term.write(string.rep(" ", rem))
|
||||
end
|
||||
|
||||
term.setBackgroundColor(c2)
|
||||
term.write(str:sub(w1 + 1, w1 + w2))
|
||||
|
||||
rem = math.min(tw - #str, w2)
|
||||
if rem > 0 then
|
||||
term.write(string.rep(" ", rem))
|
||||
end
|
||||
|
||||
term.setBackgroundColor(bg)
|
||||
end
|
||||
|
||||
local tape = peripheral.find("tape_drive")
|
||||
if not tape then
|
||||
print("tape where")
|
||||
|
@ -22,27 +53,19 @@ if not req then
|
|||
end
|
||||
|
||||
local headers = req.getResponseHeaders()
|
||||
local length = headers["content-length"]
|
||||
local length = headers["content-length"] or 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(256)
|
||||
if not chunk then
|
||||
print("EOF")
|
||||
break
|
||||
end
|
||||
tape.write(chunk)
|
||||
written = written + 1
|
||||
if (written % 8192) == 0 then
|
||||
os.sleep(0.01)
|
||||
term.setCursorPos(1, y)
|
||||
term.write(n_to_kib(written) .. " / " .. n_to_kib(length) .. string.format(" %7.3f%%", 100 * written / length))
|
||||
end
|
||||
term.setCursorPos(1, y)
|
||||
term.clearLine()
|
||||
textProcess(written / length, colors.green, colors.gray, "%8d / %8d", n_to_kib(written), n_to_kib(length))
|
||||
os.sleep(0.01)
|
||||
end
|
||||
|
||||
tape.stop()
|
||||
|
|
Loading…
Reference in New Issue