Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local OpenedPath = "n"
- local StoredFiles = {}
- local StartFile = "n"
- local ProgramImage = "n"
- local Line = 1
- local Lines = {}
- local tArg = {...}
- local options = {}
- local FilePath = ""
- local w, h = term.getSize()
- local function Clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function OpenFile()
- Lines = {}
- Line = 1
- local file = fs.open(FilePath,"r")
- repeat
- local Contents = file.readLine()
- if Contents ~= nil then Lines[#Lines + 1] = Contents end
- until Contents == nil
- file.close()
- Lines[#Lines + 1] = "=NewLine="
- Lines[#Lines + 1] = "=exit="
- end
- function SaveFile()
- local file = fs.open(FilePath,"w")
- for i = 1, #Lines do
- file.writeLine(Lines[i])
- end
- file.close()
- Lines = {}
- Line = 1
- end
- function FindFile(name)
- FilePath = fs.combine(OpenedPath,name)
- end
- function CUI(m,y) --declare function
- n=1
- local l = #m
- while true do
- term.setCursorPos(1,y)
- for i=1, #m, 1 do --traverse the table of options
- if i==n then term.clearLine() print(i, " >",m[i]) else term.clearLine() print(i, " ", m[i]) end --print them
- end
- a, b= os.pullEvent("key") --wait for keypress
- if b==keys.w and n>1 then n=n-1 end
- if b==keys.s and n<l then n=n+1 end
- if b==keys.enter then break end
- end
- return n --return the value
- end
- function TextMenu_Base()
- Clear()
- options = Lines
- local n = CUI(options,1)
- if options[n] == "=exit=" then
- Lines[#Lines] = nil
- Lines[#Lines] = nil
- SaveFile()
- if tArg[1] == "direct" then
- else
- FileMenu()
- end
- elseif options[n] == "=NewLine=" then
- Lines[n] = "empty"
- Lines[#Lines] = "=NewLine="
- Lines[#Lines + 1] = "=exit="
- TextMenu_Base()
- else
- Line = n
- TextMenu_Line()
- end
- end
- function TextMenu_Line()
- Clear()
- print("line ",Line," :",Lines[Line])
- term.setCursorPos(1,3)
- local input = Lines[Line]
- while true do
- local event = {os.pullEvent("key")}
- if event[2] == keys.enter then break end
- input = read()
- end
- Lines[Line] = input
- TextMenu_Base()
- end
- function FileMenu()
- Clear()
- options = nil
- if OpenedPath == "n" then
- options = AllowedPaths
- else
- options = fs.list(OpenedPath)
- options[#fs.list(OpenedPath) + 1] = "return"
- end
- local n = CUI(options,2)
- if options[n] == "exit" then
- elseif options[n] == "return" then
- OpenedPath = "n"
- FileMenu()
- elseif OpenedPath == "n" then
- OpenedPath = options[n]
- FileMenu()
- else
- FindFile(options[n])
- OpenFile()
- TextMenu_Base()
- end
- end
- function ProjectDisplay()
- print("[return]")
- print("//Options//")
- print("<StartFile>",StartFile)
- print("<Image>",ProgramImage)
- end
- function Menu()
- term.setBackgroundColor(colors.black)
- Clear()
- print("////Developer////")
- print("[Proj][Tools][File][Help]")
- print("|Files|")
- if StartFile ~= "n" then
- term.setCursorPos(9,3)
- term.write("[run]")
- end
- term.setCursorPos(1,4)
- for i = 1, #StoredFiles do
- print(string.sub(StoredFiles[i],1,7))
- end
- local n = 0
- while true do
- local a, b, c, d = os.pullEvent("mouse_click")
- if d == 2 then
- if c < 7 then n = 1 end
- if c < 15 then n = 2 end
- if c < 22 then n = 3 end
- if c < 26 then n = 4 end
- else
- if d == 3 and c > 8 and c < 14 and StartFile ~= "n" then n = 5 end
- if d > 3 and c < 8 then n = (d - 3) + 10 end
- end
- if n > 0 then break end
- end
- if n == 1 then
- elseif n == 2 then
- elseif n == 3 then
- elseif n == 4 then
- elseif n == 5 then
- shell.run(StartFile)
- paintutils.DrawBox(1,1,w,h,colors.blue)
- term.setTextColor(white)
- term.setCursorPos((w/2) - 2, h /2)
- term.write("done")
- os.sleep(3)
- Menu()
- elseif n == 6 then
- elseif n == 7 then
- else
- end
- end
- Menu()
Add Comment
Please, Sign In to add comment