Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --this program is a text Editor
- local w, h = term.getSize()
- local OpenedFile = "n"
- local FileData = {}
- local OpenedPath = "os"
- local PathParts = {"os"}
- local PathSection = 1
- local function Clear()
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- end
- local function CenterText(y,text)
- local x = math.floor((w - string.len(text)) /2)
- term.setCursorPos(x,y)
- term.clearLine()
- term.write(text)
- end
- local function OpenFile(file)
- local Item = fs.open(file,"r")
- local line
- while true do
- line = Item.readLine()
- if line == nil then
- break
- else
- FileData[#FileData + 1] = line
- end
- end
- Item.close()
- EditorMenu()
- end
- local function SaveFile(file)
- local Item = fs.open(file,"w")
- Item.clear()
- Item.setCursorPos(1,1)
- for i = 1, #FileData do
- Item.writeLine(FileData[i])
- end
- Item.close()
- end
- function EditorMenu()
- Clear()
- print(OpenedFile)
- local Options = {"=Exit=","=Save="}
- for i = 1, #FileData do
- Options[#Options + 1] = FileData[i]
- end
- local n = CUI(Options,2)
- if Options[n] == "=Exit=" then
- FileData = {}
- OpenedFile = "n"
- FileNavigator()
- elseif Options[n] == "=Save=" then
- SaveFile(OpenedFile)
- else
- local event
- input = FileData[n]
- while true do
- event = {os.pullEvent("key")}
- input = read
- if event[2] == keys.enter then break end
- end
- FileData[n] = input
- EditorMenu()
- end
- end
- function CUI(m,y) --declare function
- n=1
- local l = #m
- while true do
- term.setCursorPos(1,y)
- term.clearLine()
- for i = 1, #m do
- if i==n then print("["..m[i].."]") else print(m[i]) end
- end
- if b==keys.a and n>1 then n=n-1 end
- if b==keys.d and n<l then n=n+1 end
- if b==keys.enter then break end
- end
- return n --return the value
- end
- function FileNavigator()
- Clear()
- print(OpenedPath)
- Files = {fs.list(OpenedPath)}
- local Options = {"exit","return"}
- for i = 1, #Files do
- Options[#Options + 1] = Files[i]
- end
- local n = CUI(Options,2)
- if Options[n] == "exit" then
- shell.run(settings.get("os_DesktopLoc"))
- elseif Options[n] == "return" then
- OpenedPath = PathPart[PathSection-1]
- else
- if fs.isDir(Options[n]) == true then
- OpenedPath = Options[n]
- else
- OpenedFile = Options[n]
- OpenFile(Options[n])
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement