Advertisement
Marlingaming

CC Tweaked CCSPS Iron 2.0.0 - Workers Terminal Package

Feb 11th, 2022 (edited)
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.38 KB | None | 0 0
  1. local Background = colors.lightGray
  2. local Username = "guest"
  3.  
  4. local function Clear()
  5. term.clear()
  6. term.setCursorPos(1,1)
  7. end
  8.  
  9. local function GetUser()
  10. local file = fs.open("os/System/Client/Files/.UserFile.txt","r")
  11. Username = file.readLine()
  12. file.close()
  13. end
  14.  
  15. function CreateFile()
  16. Clear()
  17. print("enter name for file")
  18. local input
  19. while true do
  20.     local event = {os.pullEvent("key")}
  21.     if event[2] == keys.enter then break end
  22.     input = read()
  23. end
  24. input = input..".txt"
  25. local P = fs.combine("os/System/Client/Files", input)
  26. local file = fs.open(P,"w")
  27. file.write("new file")
  28. file.close()
  29. shell.run("os/System/Programs/TextEditor","direct",P)
  30. FileAccess()
  31. end
  32.  
  33. function CUI(m) --declare function
  34. n=1
  35. local l = #m
  36. while true do
  37. term.setCursorPos(1,5)
  38. for i=1, #m, 1 do --traverse the table of options
  39. if i==n then term.clearLine() print(i, ">",m[i]) else term.clearLine() print(i, "-", m[i]) end --print them
  40. end
  41. a, b= os.pullEvent("key") --wait for keypress
  42. if b==keys.w and n>1 then n=n-1 end
  43. if b==keys.s and n<l then n=n+1 end
  44. if b==keys.enter then break end
  45. end
  46. return n --return the value
  47. end
  48.  
  49. function FileAccess()
  50. Clear()
  51. print("[ os/System/Client/Files ]")
  52. local List = fs.list("os/System/Client/Files")
  53. local options = {}
  54. for i = 1, #List do
  55.     if fs.isDir(fs.combine("os/System/Client/Files",List[i])) == false then options[#options + 1] = List[i] end
  56. end
  57. options[#options + 1] = "new file"
  58. options[#options + 1] = "exit"
  59. local n = CUI(options)
  60. if options[n] == "exit" then
  61.     Menu()
  62. elseif options[n] == "new file" then
  63.     CreateFile()
  64. else
  65.     shell.run("os/System/Programs/TextEditor.lua","direct",fs.combine("os/System/Client/Files",options[n]))
  66.     FileAccess()
  67. end
  68. end
  69.  
  70. function Local_Net()
  71. Clear()
  72. print("connected devices")
  73. local List = peripheral.getNames()
  74. List[#List + 1] = "return"
  75. local n = CUI(List)
  76. if List[n] == "return" then
  77.     Menu()
  78. else
  79.     local Target = List[n]
  80.     local Comp = peripherals.find(Target)
  81.     local TarPath = fs.combine(Comp.getMountPath,"os/System/Client/Files")
  82.     Clear()
  83.     print("Options")
  84.     local options = {"upload","download"}
  85.     local n = CUI(options)
  86.     local Items
  87.     local Act
  88.     if options[n] == "upload" then
  89.         Act = "upload"
  90.         Items = fs.list("os/System/Client/Files")
  91.     elseif options[n] == "download" then
  92.         Act = "download"
  93.         Items = fs.list(TarPath)
  94.     end
  95.     local n = CUI(Items)
  96.     if Act == "upload" then
  97.         fs.copy(fs.combine("os/System/Client/Files",Items[n]),fs.combine(TarPath,Items[n]))
  98.     elseif Act == "download" then
  99.         fs.copy(fs.combine(TarPath,Items[n]), fs.combine("os/System/Client/Files",Items[n]))
  100.     end
  101.     Menu()
  102. end
  103. end
  104.  
  105. function Menu()
  106. term.setBackgroundColor(Background)
  107. Clear()
  108. print("Workers Terminal Program")
  109. print("options")
  110. local options = {"Files","Local_Network","Settings","Logout"}
  111. local n = CUI(options)
  112. if options[n] == "Files" then
  113.     FileAccess()
  114. elseif options[n] == "Local_Network" then
  115.     Local_Net()
  116. elseif options[n] == "Settings" then
  117.     Menu()
  118. elseif options[n] == "Logout" then
  119.     Login()
  120. end
  121. end
  122.  
  123. function Login()
  124. GetUser()
  125. Clear()
  126. print("Login")
  127. local input
  128. while true do
  129.     local event = {os.pullEvent("key")}
  130.     if event[2] == keys.enter then break end
  131.     input = read()
  132. end
  133. if Username == input then
  134.     Menu()
  135. else
  136.     Login()
  137. end
  138. end
  139.  
  140. Login()
  141.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement