Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- API --------------------------------------------------
- os.pullEvent = os.pullEventRaw
- local w, h = term.getSize()
- function printCentered(y, str)
- local x = math.floor((w - string.len(str)) / 2)
- term.setCursorPos(x, y)
- term.clearLine()
- term.write(str)
- end
- function printThird(y, third, str)
- local third_width = w / 3
- -- Centre position of the requested third
- local centre_x = (third - 0.5) * third_width
- local x = math.floor(centre_x - (#str / 2))
- term.setCursorPos(x, y)
- term.write(str)
- end
- function hasValue (tab, val)
- for index, value in ipairs(tab) do
- if value == val then
- return true
- end
- end
- return false
- end
- function printKeys(tab)
- -- Source - https://stackoverflow.com/a/12674376
- -- Posted by lhf
- -- Retrieved 2026-06-11, License - CC BY-SA 3.0
- local keyset={}
- local n=0
- for k,v in pairs(tab) do
- n=n+1
- keyset[n]=k
- end
- print(textutils.serialise(keyset))
- end
- ---------------------------------------------------------
- JUKEBOX_ID = -1
- JUKEBOX_BACKEND_ID = -1
- local menu_option = 1
- local function drawMenu()
- term.clear()
- term.setCursorPos(1, 1)
- term.write("Jukebox OS Alpha //")
- term.setCursorPos(w - 10, 1)
- if menu_option == 1 then
- term.write("Song List")
- elseif menu_option == 2 then
- term.write("Queue")
- elseif menu_option == 3 then
- term.write("Maintenance")
- elseif menu_option == 4 then
- term.write("Shutdown")
- end
- end
- local function drawFrontend()
- printCentered(math.floor(h/2) - 3, "")
- printCentered(math.floor(h/2) - 2, "Start Menu" )
- printCentered(math.floor(h/2) - 1, "")
- printCentered(math.floor(h/2) + 0, ((menu_option == 1) and "[ Song List ]") or "Song List ")
- printCentered(math.floor(h/2) + 1, ((menu_option == 2) and "[ Queue ]") or "Queue ")
- printCentered(math.floor(h/2) + 2, ((menu_option == 3) and "[ Maintenance ]") or "Maintenance")
- printCentered(math.floor(h/2) + 3, ((menu_option == 4) and "[ Shutdown ]") or "Shutdown ")
- printCentered(math.floor(h/2) + 4, "")
- end
- function main(...)
- local jukebox_id, jukebox_backend_id = ...
- JUKEBOX_ID = tonumber(jukebox_id)
- JUKEBOX_BACKEND_ID = tonumber(jukebox_backend_id)
- drawMenu()
- drawFrontend()
- while true do
- local e, p = os.pullEvent()
- if e == "key" then
- local key = p
- if key == keys.w or key == keys.up then
- if menu_option > 1 then
- menu_option = menu_option - 1
- drawMenu()
- drawFrontend()
- end
- elseif key == keys.s or key == keys.down then
- if menu_option < 4 then
- menu_option = menu_option + 1
- drawMenu()
- drawFrontend()
- end
- elseif key == keys.enter then
- break
- end
- end
- end
- term.clear()
- if menu_option == 1 then
- shell.run("jukebox_frontend_songlist", JUKEBOX_ID, JUKEBOX_BACKEND_ID)
- elseif menu_option == 2 then
- shell.run("jukebox_frontend_queue", JUKEBOX_ID, JUKEBOX_BACKEND_ID)
- elseif menu_option == 3 then
- elseif menu_option == 4 then
- os.shutdown()
- end
- end
- main(...)
Advertisement
Add Comment
Please, Sign In to add comment