Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to draw the exit option
- local function drawExitOption()
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.write("X")
- term.setBackgroundColor(colors.black)
- end
- -- Function to clear the screen with a black background
- local function clearScreen()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- end
- local function getDiskID()
- local drive = peripheral.wrap("bottom")
- if drive and peripheral.getType("bottom") == "drive" then
- if drive.isDiskPresent() then
- local diskID = drive.getDiskID()
- return diskID
- else
- return nil, "No disk present in the drive."
- end
- else
- return nil, "No drive found at the bottom."
- end
- end
- local function listCards()
- clearScreen()
- drawExitOption()
- local cardDir = "/disk/Cards/"
- local files = fs.list(cardDir)
- if #files > 0 then
- print("Cards in /disk/Cards:")
- for _, file in ipairs(files) do
- print("- " .. file)
- end
- else
- print("No cards found in /disk/Cards.")
- end
- while true do
- local event, button, x, y = os.pullEvent("mouse_click")
- if x == 1 and y == 1 then
- return
- end
- end
- end
- local function linkCard()
- clearScreen()
- drawExitOption()
- print("Link Card:")
- print("1. Insert Card to Link")
- print("2. Enter Card ID")
- print("0. Back to Main Menu")
- while true do
- local event, button, x, y = os.pullEvent("mouse_click")
- if x == 1 and y == 1 then
- return
- end
- if event == "char" then
- local choice = tonumber(button)
- if choice == 1 then
- clearScreen()
- drawExitOption()
- print("Insert a disk to link or click cancel:")
- while true do
- local diskID, errorMsg = getDiskID()
- if diskID then
- local cardFileName = "/disk/Cards/" .. diskID .. ".ID"
- local file = fs.open(cardFileName, "w")
- file.close()
- print("Card linked successfully.")
- sleep(2)
- local drive = peripheral.wrap("bottom")
- drive.ejectDisk()
- return
- elseif x == 1 and y == 1 then
- return
- else
- print(errorMsg)
- sleep(2)
- return
- end
- end
- elseif choice == 2 then
- clearScreen()
- drawExitOption()
- print("Enter the card ID:")
- local cardID = read()
- local cardFileName = "/disk/Cards/" .. cardID .. ".ID"
- local file = fs.open(cardFileName, "w")
- file.close()
- print("Card linked successfully.")
- sleep(2)
- return
- elseif choice == 0 then
- return
- else
- print("Invalid choice. Please enter 1, 2, or 0.")
- end
- end
- end
- end
- local function unlinkCard()
- clearScreen()
- drawExitOption()
- print("Unlink Card:")
- print("1. Insert Card to Unlink")
- print("2. Enter Card ID")
- print("0. Back to Main Menu")
- while true do
- local event, button, x, y = os.pullEvent("mouse_click")
- if x == 1 and y == 1 then
- return
- end
- if event == "char" then
- local choice = tonumber(button)
- if choice == 1 then
- clearScreen()
- drawExitOption()
- print("Insert a disk to unlink or click cancel:")
- while true do
- local diskID, errorMsg = getDiskID()
- if diskID then
- local cardFileName = "/disk/Cards/" .. diskID .. ".ID"
- if fs.exists(cardFileName) then
- fs.delete(cardFileName)
- print("Card unlinked successfully.")
- else
- print("No matching card found to unlink.")
- end
- sleep(2)
- local drive = peripheral.wrap("bottom")
- drive.ejectDisk()
- return
- elseif x == 1 and y == 1 then
- return
- else
- print(errorMsg)
- sleep(2)
- return
- end
- end
- elseif choice == 2 then
- clearScreen()
- drawExitOption()
- print("Enter the card ID:")
- local cardID = read()
- local cardFileName = "/disk/Cards/" .. cardID .. ".ID"
- if fs.exists(cardFileName) then
- fs.delete(cardFileName)
- print("Card unlinked successfully.")
- else
- print("No matching card found to unlink.")
- end
- sleep(2)
- return
- elseif choice == 0 then
- return
- else
- print("Invalid choice. Please enter 1, 2, or 0.")
- end
- end
- end
- end
- local function mainMenu()
- clearScreen()
- drawExitOption()
- print("Main Menu:")
- print("1. List Cards")
- print("2. Link Card")
- print("3. Unlink Card")
- print("0. Exit")
- while true do
- local event, button, x, y = os.pullEvent("mouse_click")
- if x == 1 and y == 1 then
- os.reboot()
- end
- if event == "char" then
- local choice = tonumber(button)
- if choice == 1 then
- listCards()
- mainMenu()
- elseif choice == 2 then
- linkCard()
- mainMenu()
- elseif choice == 3 then
- unlinkCard()
- mainMenu()
- elseif choice == 0 then
- os.reboot()
- else
- print("Invalid choice. Please enter 1, 2, 3, or 0.")
- end
- end
- end
- end
- mainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement