Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local findtable=function(txt)
- --[[ Broken Stub
- local t
- if not string.find(txt, ".") then return (string.sub(txt, {string.find(txt,".")}[1] - 1, #txt)) end
- while true do
- if not string.find(string.sub(txt.."", {string.find(txt.."", ".")}[2]+1).."", ".") then return txt break end
- local t={string.find(txt.."", ".")}
- txt=string.sub(txt, t[2]+1)..""
- end
- ]]--
- return "fs"
- end
- local function drawMenu(tMenu, xpos, ypos, curSel)
- if xpos == true then
- centered = true
- else
- centered = false
- end
- if curSel ~= nil or curSel~= "" then
- sel = 1
- else
- sel = curSel
- end
- tPlaces = {}
- while true do
- for i=1, #tMenu do
- iSel = i-1
- local w, h = term.getSize()
- table.remove(tPlaces, i)
- if i == sel then
- if centered == false then
- term.setCursorPos(xpos, ypos+iSel)
- term.clearLine()
- table.insert(tPlaces, i, term.getCursorPos()+2)
- write("[ "..tMenu[i].." ]")
- else
- term.setCursorPos(w/2-#tMenu[i]/2-2, ypos+iSel)
- term.clearLine()
- table.insert(tPlaces, i, term.getCursorPos()+2)
- write("[ "..tMenu[i].." ]")
- end
- else
- if centered == false then
- term.setCursorPos(xpos, ypos+iSel)
- term.clearLine()
- table.insert(tPlaces, i, term.getCursorPos())
- write(tMenu[i])
- else
- term.setCursorPos(w/2-#tMenu[i]/2, ypos+iSel)
- term.clearLine()
- table.insert(tPlaces, i, term.getCursorPos())
- write(tMenu[i])
- end
- end
- end
- local event, key, x, y = os.pullEvent()
- if event == "key" then
- if key == 200 and sel > 1 and sel <= #tMenu then sel = sel-1
- elseif key == 208 and sel >= 1 and sel < #tMenu then sel = sel+1
- elseif key == 208 and sel == #tMenu then sel = 1
- elseif key == 200 and sel == 1 then sel = #tMenu
- end
- for v = 1, #tMenu do
- if key == 28 and sel == v then
- return tMenu[v], sel
- end
- end
- elseif event == "mouse_click" then
- for s = 1, #tMenu do
- iSel = s-1
- if s == sel then
- if x >= tPlaces[s] and x < tPlaces[s]+#tMenu[s] and y == ypos+iSel then
- return tMenu[s], s
- end
- end
- end
- end
- end
- end
- local function centerPrint(message, yoffset)
- local width = term.getSize()
- local o = string.len(message)
- if o > width then
- return 1
- else
- term.setCursorPos((width-o)/2, yoffset)
- print(message)
- end
- end
- local function errorVirus(lfunction)
- local w,h=term.getSize()
- term.setTextColor(colors.red)
- centerPrint("ERROR:", 5)
- centerPrint("Program tried to use function "..lfunction.."!", 7)
- term.setTextColor(1)
- centerPrint("Would you like to let this program use this function?")
- local sel=drawMenu({"Yes", "No", "Let use all functions from "..findtable(lfunction)},nil,9,2)
- if sel==1 then env[lfunction]=oldenv[lfunction] return
- elseif sel==2 then error("Program terminated",2)
- elseif sel==3 then
- for k,v in pairs(oldenv[findtable(lfunction)]) do
- env[findtable(lfunction)[k]]=v
- end
- end
- end
- local env={["fs"]={}, ["shell"]={}, ["os"]={}}
- local oldenv={}
- for k,v in pairs(_G) do
- oldenv[k]=v
- end
- term.clear()
- errorVirus("fs.open")
Advertisement
Add Comment
Please, Sign In to add comment