Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Background = colors.lightGray
- local Username = "guest"
- local function Clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- local function GetUser()
- local file = fs.open("os/System/Client/Files/.UserFile.txt","r")
- Username = file.readLine()
- file.close()
- end
- function CreateFile()
- Clear()
- print("enter name for file")
- local input
- while true do
- local event = {os.pullEvent("key")}
- if event[2] == keys.enter then break end
- input = read()
- end
- input = input..".txt"
- local P = fs.combine("os/System/Client/Files", input)
- local file = fs.open(P,"w")
- file.write("new file")
- file.close()
- shell.run("os/System/Programs/TextEditor","direct",P)
- FileAccess()
- end
- function CUI(m) --declare function
- n=1
- local l = #m
- while true do
- term.setCursorPos(1,5)
- 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 FileAccess()
- Clear()
- print("[ os/System/Client/Files ]")
- local List = fs.list("os/System/Client/Files")
- local options = {}
- for i = 1, #List do
- if fs.isDir(fs.combine("os/System/Client/Files",List[i])) == false then options[#options + 1] = List[i] end
- end
- options[#options + 1] = "new file"
- options[#options + 1] = "exit"
- local n = CUI(options)
- if options[n] == "exit" then
- Menu()
- elseif options[n] == "new file" then
- CreateFile()
- else
- shell.run("os/System/Programs/TextEditor.lua","direct",fs.combine("os/System/Client/Files",options[n]))
- FileAccess()
- end
- end
- function Local_Net()
- Clear()
- print("connected devices")
- local List = peripheral.getNames()
- List[#List + 1] = "return"
- local n = CUI(List)
- if List[n] == "return" then
- Menu()
- else
- local Target = List[n]
- local Comp = peripherals.find(Target)
- local TarPath = fs.combine(Comp.getMountPath,"os/System/Client/Files")
- Clear()
- print("Options")
- local options = {"upload","download"}
- local n = CUI(options)
- local Items
- local Act
- if options[n] == "upload" then
- Act = "upload"
- Items = fs.list("os/System/Client/Files")
- elseif options[n] == "download" then
- Act = "download"
- Items = fs.list(TarPath)
- end
- local n = CUI(Items)
- if Act == "upload" then
- fs.copy(fs.combine("os/System/Client/Files",Items[n]),fs.combine(TarPath,Items[n]))
- elseif Act == "download" then
- fs.copy(fs.combine(TarPath,Items[n]), fs.combine("os/System/Client/Files",Items[n]))
- end
- Menu()
- end
- end
- function Menu()
- term.setBackgroundColor(Background)
- Clear()
- print("Workers Terminal Program")
- print("options")
- local options = {"Files","Local_Network","Settings","Logout"}
- local n = CUI(options)
- if options[n] == "Files" then
- FileAccess()
- elseif options[n] == "Local_Network" then
- Local_Net()
- elseif options[n] == "Settings" then
- Menu()
- elseif options[n] == "Logout" then
- Login()
- end
- end
- function Login()
- GetUser()
- Clear()
- print("Login")
- local input
- while true do
- local event = {os.pullEvent("key")}
- if event[2] == keys.enter then break end
- input = read()
- end
- if Username == input then
- Menu()
- else
- Login()
- end
- end
- Login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement