Added more options
This commit is contained in:
parent
11be60a0b1
commit
b4d4d64c16
32
tapeget.lua
32
tapeget.lua
|
@ -1,5 +1,16 @@
|
||||||
local args = { ... }
|
local args = { ... }
|
||||||
|
|
||||||
|
local shouldSeek = true
|
||||||
|
local driveName = nil
|
||||||
|
if args[1] == "-S" then
|
||||||
|
shouldSeek = false
|
||||||
|
table.remove(args, 1)
|
||||||
|
end
|
||||||
|
if args[1] == "-D" then
|
||||||
|
table.remove(args, 1)
|
||||||
|
driveName = table.remove(args, 1)
|
||||||
|
end
|
||||||
|
|
||||||
local function n_to_kib(value)
|
local function n_to_kib(value)
|
||||||
return string.format("%6.1f kiB", value / 1024)
|
return string.format("%6.1f kiB", value / 1024)
|
||||||
end
|
end
|
||||||
|
@ -31,14 +42,18 @@ local function textProgress(p, c1, c2, fmt, ...)
|
||||||
term.setBackgroundColor(bg)
|
term.setBackgroundColor(bg)
|
||||||
end
|
end
|
||||||
|
|
||||||
local tape = { peripheral.find("tape_drive") }
|
local tape
|
||||||
if #tape == 0 then
|
if driveName ~= nil then
|
||||||
print("tape where")
|
tape = peripheral.wrap(driveName)
|
||||||
|
else
|
||||||
|
local drives = { peripheral.find("tape_drive") }
|
||||||
|
if #drives == 0 then
|
||||||
|
print("Drive where")
|
||||||
return
|
return
|
||||||
elseif #tape ~= 1 then
|
elseif #tape ~= 1 then
|
||||||
print("More than one drive found:")
|
print("More than one drive found:")
|
||||||
for i = 1, #tape do
|
for i = 1, #drives do
|
||||||
print(peripheral.getName(tape[i]))
|
print(peripheral.getName(drives[i]))
|
||||||
end
|
end
|
||||||
print("Input drive name:")
|
print("Input drive name:")
|
||||||
io.write("> ")
|
io.write("> ")
|
||||||
|
@ -48,7 +63,8 @@ elseif #tape ~= 1 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
tape = tape[1]
|
tape = drives[1]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not http then
|
if not http then
|
||||||
|
@ -77,8 +93,10 @@ if length > tape.getSize() then
|
||||||
end
|
end
|
||||||
|
|
||||||
tape.stop()
|
tape.stop()
|
||||||
|
if shouldSeek then
|
||||||
tape.seek(-tape.getSize())
|
tape.seek(-tape.getSize())
|
||||||
tape.stop()
|
tape.stop()
|
||||||
|
end
|
||||||
|
|
||||||
local _, y = term.getCursorPos()
|
local _, y = term.getCursorPos()
|
||||||
local written = 0
|
local written = 0
|
||||||
|
@ -103,5 +121,7 @@ term.clearLine()
|
||||||
print("Written "..n_to_kib(written))
|
print("Written "..n_to_kib(written))
|
||||||
|
|
||||||
tape.stop()
|
tape.stop()
|
||||||
|
if shouldSeek then
|
||||||
tape.seek(-tape.getSize())
|
tape.seek(-tape.getSize())
|
||||||
tape.stop()
|
tape.stop()
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue