From b4d4d64c1638c1335a580a92ffea9086e22a28aa Mon Sep 17 00:00:00 2001 From: hkc Date: Wed, 18 Oct 2023 01:06:35 +0300 Subject: [PATCH] Added more options --- tapeget.lua | 62 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/tapeget.lua b/tapeget.lua index e4c99d6..5e8b79d 100644 --- a/tapeget.lua +++ b/tapeget.lua @@ -1,5 +1,16 @@ 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) return string.format("%6.1f kiB", value / 1024) end @@ -31,24 +42,29 @@ local function textProgress(p, c1, c2, fmt, ...) term.setBackgroundColor(bg) end -local tape = { peripheral.find("tape_drive") } -if #tape == 0 then - print("tape where") - return -elseif #tape ~= 1 then - print("More than one drive found:") - for i = 1, #tape do - print(peripheral.getName(tape[i])) - end - print("Input drive name:") - io.write("> ") - tape = peripheral.wrap(read()) - if not tape then - printError("wrong name") - return - end +local tape +if driveName ~= nil then + tape = peripheral.wrap(driveName) else - tape = tape[1] + local drives = { peripheral.find("tape_drive") } + if #drives == 0 then + print("Drive where") + return + elseif #tape ~= 1 then + print("More than one drive found:") + for i = 1, #drives do + print(peripheral.getName(drives[i])) + end + print("Input drive name:") + io.write("> ") + tape = peripheral.wrap(read()) + if not tape then + printError("wrong name") + return + end + else + tape = drives[1] + end end if not http then @@ -77,8 +93,10 @@ if length > tape.getSize() then end tape.stop() -tape.seek(-tape.getSize()) -tape.stop() +if shouldSeek then + tape.seek(-tape.getSize()) + tape.stop() +end local _, y = term.getCursorPos() local written = 0 @@ -103,5 +121,7 @@ term.clearLine() print("Written "..n_to_kib(written)) tape.stop() -tape.seek(-tape.getSize()) -tape.stop() +if shouldSeek then + tape.seek(-tape.getSize()) + tape.stop() +end