Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local AllowedPaths = {"os/System/Files","os/System/Client/Files","exit"}
- local OpenedPath = "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
- if tArg[1] == "direct" then
- FilePath = tArg[2]
- OpenFile()
- TextMenu_Base()
- else
- FileMenu()
- end
Add Comment
Please, Sign In to add comment