Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to clear the terminal and set the cursor position
- local function clearScreen()
- term.clear()
- term.setCursorPos(1, 1)
- end
- -- Function to display centered ASCII art
- local function displayCenteredArt(art, text)
- clearScreen()
- local lines = {}
- for line in art:gmatch("[^\n]+") do
- table.insert(lines, line)
- end
- local _, h = term.getSize()
- local startY = math.floor((h - #lines) / 2) + 1
- for i, line in ipairs(lines) do
- local w, _ = term.getSize()
- local startX = math.floor((w - #line) / 2) + 1
- term.setCursorPos(startX, startY + i - 1)
- print(line)
- end
- if text then
- local textX = math.floor((term.getSize() - #text) / 2) + 1
- term.setCursorPos(textX, startY + #lines + 1)
- print(text)
- end
- end
- -- Function to draw a password prompt box
- local function drawPasswordBox()
- clearScreen()
- local w, h = term.getSize()
- local boxWidth = 36
- local boxHeight = 7
- local startX = math.floor((w - boxWidth) / 2) + 1
- local startY = math.floor((h - boxHeight) / 2) + 1
- -- Draw password box
- paintutils.drawBox(startX, startY, startX + boxWidth - 1, startY + boxHeight - 1, colors.blue)
- paintutils.drawFilledBox(startX + 1, startY + 1, startX + boxWidth - 2, startY + boxHeight - 2, colors.lightBlue)
- term.setTextColor(colors.white)
- term.setCursorPos(startX + 2, startY + 1)
- term.write(string.rep(" ", boxWidth - 4))
- term.setCursorPos(startX + 3, startY + 1)
- term.write("PASSWORD REQUIRED")
- term.setCursorPos(startX + 2, startY + 3)
- term.write(string.rep(" ", boxWidth - 4))
- term.setCursorPos(startX + 3, startY + 3)
- term.write("Enter Password:")
- term.setCursorPos(startX + 2, startY + 5)
- term.write(string.rep("_", boxWidth - 4))
- term.setCursorPos(startX + 2, startY + 5)
- return startX + 2, startY + 5, boxWidth - 4
- end
- -- Function to handle password prompt
- local function passwordPrompt(correctPassword)
- local cursorX, cursorY, inputWidth = drawPasswordBox()
- term.setCursorPos(cursorX, cursorY)
- local input = read("*") -- Masks input
- return input == correctPassword
- end
- -- Function to draw a menu system
- local function drawMenu(title, options)
- clearScreen()
- local w, h = term.getSize()
- local boxWidth = 40
- local boxHeight = #options + 6
- local startX = math.floor((w - boxWidth) / 2) + 1
- local startY = math.floor((h - boxHeight) / 2) + 1
- -- Draw menu background and header
- paintutils.drawBox(startX, startY, startX + boxWidth - 1, startY + boxHeight - 1, colors.blue)
- paintutils.drawFilledBox(startX + 1, startY + 1, startX + boxWidth - 2, startY + boxHeight - 2, colors.lightBlue)
- term.setTextColor(colors.white)
- term.setCursorPos(startX + 2, startY + 1)
- term.write(string.rep(" ", boxWidth - 4))
- term.setCursorPos(startX + math.floor((boxWidth - #title) / 2), startY + 1)
- term.write(title)
- -- Draw options
- for i, option in ipairs(options) do
- term.setCursorPos(startX + 4, startY + 2 + i)
- print(i .. ". " .. option)
- end
- end
- -- Function to handle menu selection
- local function menuSelection(title, options)
- drawMenu(title, options)
- local w, h = term.getSize()
- local startX = math.floor((w - 40) / 2) + 2
- local startY = math.floor((h - (#options + 6)) / 2) + #options + 5
- term.setCursorPos(startX, startY)
- term.write("Select an option: ")
- local choice = tonumber(read())
- if choice and choice > 0 and choice <= #options then
- return choice
- else
- return nil
- end
- end
- -- Main program
- local function main()
- local correctPassword = "password"
- if not passwordPrompt(correctPassword) then
- print("Incorrect password. Access denied.")
- sleep(2)
- return
- end
- local menuTitle = "Main Menu"
- local menuOptions = {"Option 1", "Option 2", "Option 3"}
- local choice = menuSelection(menuTitle, menuOptions)
- if choice then
- print("You selected option " .. choice)
- else
- print("Invalid selection.")
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement