Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fs.makeDir("buttons")
- function buttons()
- local event, button, X, Y = os.pullEvent("mouse_click")
- if button == 1 then
- X = tostring(X)
- Y = tostring(Y)
- XY = X.."_"..Y
- if fs.isDir("buttons") then
- sDir = shell.resolve("buttons")
- end
- local tAll = fs.list( sDir )
- local tFiles = {}
- local tDirs = {}
- for n, sItem in pairs( tAll ) do
- local sPath = fs.combine( sDir, sItem )
- local check = string.find(sPath, XY)
- if check ~= nil then
- dash = string.find(sPath, "-")
- ampersand = string.find(sPath, "=")
- iconlabel = string.sub(sPath, ampersand+1, dash-1)
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(2^14)
- term.setBackgroundColor(2^5)
- local file = fs.open(sPath, "r")
- local fileline = file.readLine()
- file.close()
- local pos = string.find(fileline, " ")
- local name = string.sub(fileline, pos+3, string.len(fileline) - 2)
- local w, l = term.getSize()
- local namelength = string.len(name)
- w = tonumber(w)
- namelength = tonumber(namelength)
- local empty = string.rep(" ", w - namelength - 5)
- local nAl = name.." ("..iconlabel..")"
- local nAlL = string.len(nAl)
- nAlL = w - nAlL
- local Npos = math.ceil(nAlL / 2)
- print(name..empty.."("..iconlabel..")")
- term.setTextColor(1)
- term.setBackgroundColor(2^15)
- term.setCursorPos(1,2)
- pcall(shell.run(sPath))
- term.setCursorBlink(false)
- sleep(2)
- term.clear()
- term.setCursorPos(19,9)
- term.setTextColor(2^math.random(1,14))
- textutils.slowPrint("Program:")
- term.setCursorPos(Npos, 10)
- term.setTextColor(2^math.random(1,14))
- textutils.slowPrint(nAl)
- term.setCursorPos(15, 11)
- term.setTextColor(2^math.random(1,14))
- textutils.slowPrint("has finished its run.")
- sleep(0.5)
- term.setCursorPos(18,12)
- term.setTextColor(2^math.random(1,14))
- print("Please wait....")
- sleep(1)
- term.setTextColor(1)
- term.clear()
- term.setCursorPos(1,1)
- end
- end
- elseif button == 2 then
- while true do
- term.clear()
- term.setCursorPos(1,1)
- print("What program would you like this button to run?")
- input = read()
- if fs.exists(input) == true and fs.isDir(input) == false then
- break
- end
- end
- while true do
- term.clear()
- term.setCursorPos(1,1)
- print("Please enter a 3 character abbreviation for your button. Please do not use =, -, or _ in your label.")
- local L = read()
- if string.len(L) == 3 then
- if string.find(L, "=") == nil then
- if string.find(L, "-") == nil then
- if string.find(L, "_") == nil then
- if string.find(L, "/") == nil then
- if string.find(L, "\\") == nil then
- label = L
- break
- end
- end
- end
- end
- end
- end
- end
- fs.makeDir("buttons")
- local XY = X.."_"..Y
- XY = tostring(XY)
- local nb = fs.open("buttons/button="..label.."-"..XY , "w")
- nb.writeLine("shell.run ('"..input.."')")
- nb.close()
- end
- listbuttons()
- end
- function listbuttons()
- term.clear()
- term.setCursorPos(1,1)
- if fs.isDir("buttons") then
- sDir = shell.resolve("buttons")
- local tAll = fs.list( sDir )
- local tFiles = {}
- local tDirs = {}
- for n, sItem in pairs( tAll ) do
- local sPath = fs.combine( sDir, sItem )
- dash = string.find(sPath, "-")
- colon = string.find(sPath, "_")
- ampersand = string.find(sPath, "=")
- length = string.len(sPath)
- iconlabel = string.sub(sPath, ampersand+1, dash-1)
- Xpos = tonumber(string.sub(sPath, dash+1, colon-1)) - 2
- Ypos = tonumber(string.sub(sPath, colon+1, length))
- if Xpos ~= nil then
- term.setCursorPos(Xpos,Ypos)
- print("("..iconlabel..")")
- end
- end
- end
- buttons()
- end
- listbuttons()
Advertisement
Add Comment
Please, Sign In to add comment