Advertisement
Guest User

Rgb

a guest
Mar 24th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.78 KB | None | 0 0
  1.  
  2. root = "/"
  3. scroll = 0
  4. allowScroll = false
  5. scrollText = ""
  6. rendLine = true
  7. fileSelected = ""
  8. clickDoubleTimer = false
  9. lasClickDoubleTimer = false
  10. cdTimer = 0
  11. cdLasTimer = 0
  12. cdTotalTimer = 0
  13. copyFile = ""
  14. deleteFiles = true
  15. openWith = ""
  16. Who = "By Luker"
  17. instaClose = true
  18. Version = "NextSoft V1"
  19. timeX = ""
  20. renderTime = true
  21. dragLasY = 0
  22. changepos = true
  23. --TEXT ENTER VAR
  24. enterText = false
  25. textData = ""
  26. textPurpose = ""
  27. --END
  28. fSetFile = true
  29. loopRun = true
  30. w, h = term.getSize()
  31. h = h - 1
  32. renderXX = true
  33. --DEBUG FEATURE REMOVE
  34. renstr = ""
  35. --END
  36. blackStr = ""
  37. for i=1,w do
  38.     blackStr = blackStr.." "
  39. end
  40. menuVisible = false
  41. menuX = w + 50
  42. menuY = h + 51
  43. menuWidth = 10
  44. menuHeight = 7
  45. menuItems = {}
  46. menuItemsRenX = {}
  47. filesx = {}
  48. directoriesx = {}
  49. xtra = 3
  50. screenpos = {}
  51. filepos = {}
  52. menuCheck = false
  53.  
  54. function startMain()
  55.    
  56.     function Even(number)
  57.         even = true
  58.         for i=1,number do
  59.             if even == true then
  60.                 even = false
  61.             else
  62.                 even = true
  63.             end
  64.         end
  65.         return even
  66.     end
  67.  
  68.     function displayError(errorA)
  69.         renderXX = false
  70.         term.clear()
  71.         term.setCursorPos(w / 2 + string.len(errorA) / 2, h + 1 / 2)
  72.         write(errorA)
  73.         os.pullEvent("key")
  74.         renderXX = true
  75.     end
  76.  
  77.     function keyPressWait()
  78.         print("[Luker] Premi Un Qualsiasi Tasto")
  79.         os.pullEvent("key")
  80.     end
  81.  
  82.     function fManRun(locationPath)
  83.         if fs.exists(locationPath) == true then
  84.             if openWith ~= "" then
  85.                 renderXX = false
  86.                 term.setBackgroundColor(colors.black)
  87.                 term.setTextColor(colors.white)
  88.                 term.clear()
  89.                 term.setCursorPos(1, 1)
  90.                 shell.run(locationPath, tostring(openWith))
  91.                 print("(Luker) Premi Un Qualsiasi Tasto...")
  92.                 os.pullEvent("key")
  93.                 renderXX = true
  94.                 openWith = ""
  95.             else
  96.                 renderXX = false
  97.                 term.setBackgroundColor(colors.black)
  98.                 term.setTextColor(colors.white)
  99.                 term.clear()
  100.                 term.setCursorPos(1, 1)
  101.                 shell.run(locationPath)
  102.                 print("[Luker] Premi Un Qualsiasi Tasto")
  103.                 os.pullEvent("key")
  104.                 renderXX = true
  105.             end
  106.         end
  107.     end
  108.  
  109.     function dataReader(data, sep, onelas, cooler)
  110.         if type(data) == "string" then
  111.             dataR = {}
  112.             dataR[1] = ""
  113.             readingIndex = 1
  114.             for i=1,string.len(data) do
  115.                 currChar = string.sub(data, i, i)
  116.                 if currChar == sep then
  117.                     readingIndex = readingIndex + 1
  118.                     dataR[readingIndex] = ""
  119.                 else
  120.                     dataR[readingIndex] = dataR[readingIndex]..currChar
  121.                 end
  122.             end
  123.         else
  124.             dataR[1] = ""
  125.         end
  126.         if onelas == 1 then
  127.             dataR[1] = dataR[readingIndex]
  128.         end
  129.         if cooler == 1 then
  130.             dataR[1] = readingIndex
  131.         end
  132.         return dataR
  133.     end
  134.  
  135.     function menuResolve(menuString, argsxx)
  136.         if menuString == "Avvia" then
  137.             if fs.isDir(root..fileSelected) == false then
  138.                 fManRun(root..fileSelected)
  139.             else
  140.                 if changepos == true then
  141.                     root = root..fileSelected.."/"
  142.                 end
  143.                 fileSelected = ""
  144.             end
  145.         elseif menuString == "Edita" then
  146.             if fs.isDir(root..fileSelected) == false then
  147.                 renderXX = false
  148.                 term.setBackgroundColor(colors.black)
  149.                 term.setTextColor(colors.white)
  150.                 term.clear()
  151.                 term.setCursorPos(1, 1)
  152.                 shell.run("edita", root..fileSelected)
  153.                 renderXX = true
  154.             end
  155.         elseif menuString == "Copia" then
  156.             copyFile = root..fileSelected
  157.         elseif menuString == "Cancella" then
  158.             if fs.exists(root..fileSelected) == true then
  159.                 if deleteFiles == true then
  160.                     fs.delete(root..fileSelected)
  161.                     fileSelected = nil
  162.                 end
  163.             end
  164.         elseif menuString == "Diss" then
  165.             if changepos == true then
  166.                 fileSelected = ""
  167.             end
  168.         elseif menuString == "Apri Con" then
  169.             if openWith == "" then
  170.                 openWith = root..fileSelected
  171.             else
  172.                 openWith = ""
  173.             end
  174.         elseif menuString == "Si" then
  175.             loopRun = false
  176.             term.setBackgroundColor(colors.black)
  177.             term.setTextColor(colors.white)
  178.             term.clear()
  179.             term.setCursorPos(1, 1)
  180.             loopRun = false
  181.         elseif menuString == "No" then
  182.             fSetFile = true
  183.             if fileSelected == "" then
  184.                 menuItems = {"Incolla", "Nuovo", "nfx"}
  185.                 menuItemsRenX = {"  Incolla   ", "   Nuovo    ", "New Cartella"}
  186.             else
  187.                 menuItems = {"Avvia", "----------", "Edita", "Copia", "Cancella", "Diss",  "Apri Con", "rnm"}
  188.                 menuItemsRenX = {"   Avvia    ", "----------", "   Edita   ", "   Copia   ", " Cancella ", " Diss ",  "Apri Con", "  Rinomina  "}
  189.             end
  190.         elseif menuString == "nfx" then
  191.             enterText = true
  192.             textData = ""
  193.             textPurpose = "nf"
  194.         elseif menuString == "nf" then
  195.             if argsxx ~= nil then
  196.                 if fs.exists(root..argsxx) == false then
  197.                     fs.makeDir(argsxx)
  198.                     fileSelected = argsxx
  199.                 end
  200.             end
  201.         elseif menuString == "Incolla" then
  202.             if fs.exists(copyFile) == true then
  203.                 copyFileString = dataReader(copyFile, "/", 1)[1]
  204.                 if fs.exists(root..copyFileString) == true then
  205.                    
  206.                 else
  207.                    
  208.                 end
  209.                 copyFileRoot = ""
  210.                 rootsX = tostring(dataReader(copyFile, "/", 0, 1)[1])
  211.                 --rootsX = 3
  212.                 for i=2,rootsX - 1 do
  213.                     copyFileRoot = copyFileRoot.."/"..dataReader(copyFile, "/", 0, 0)[i]
  214.                 end
  215.                 copyFileRoot = copyFileRoot.."/"
  216.                 rnn = copyFileString
  217.                 num = 2
  218.                 errorX = false
  219.                 if fs.exists(root..rnn) == true then
  220.                     while true do
  221.                         if fs.exists(root..rnn) == true then
  222.                             rnn = copyFileString
  223.                             rnn = rnn..tostring(num)
  224.                             num = num + 1
  225.                         else
  226.                             break
  227.                         end
  228.                     end
  229.                 end
  230.                 if fs.isDir(copyFile) == true then
  231.                     fs.copy(copyFile, root..rnn)
  232.                 else
  233.                     readerX = fs.open(copyFile, "r")
  234.                     copyDataX = readerX.readAll()
  235.                     readerX.close()
  236.                     writerX = fs.open(root..rnn, "w")
  237.                     writerX.write(copyDataX)
  238.                     writerX.close()
  239.                 end
  240.             end
  241.         elseif menuString == "rnm" then
  242.             changepos = false
  243.             enterText = true
  244.             textData = ""
  245.             textPurpose = "rinomina"
  246.         elseif menuString == "rename" then
  247.             if fileSelected ~= nil and fileSelected ~= "" then
  248.                 if fs.exists(root..tostring(argsxx)) == false then
  249.                     fs.copy(root..fileSelected, root..tostring(argsxx))
  250.                     fs.delete(root..fileSelected)
  251.                     fileSelected = nil
  252.                 end
  253.                 changepos = true
  254.             end
  255.         elseif menuString == "New" then
  256.             enterText = true
  257.             textData = ""
  258.             textPurpose = "Nuovo"
  259.         elseif menuString == "nw" then
  260.             if fs.exists(root..argsxx) == false then
  261.                 fileNew = fs.open(root..argsxx, "w")
  262.                 fileNew.write("")
  263.                 fileNew.close()
  264.                 fileSelected = argsxx
  265.             end
  266.         else
  267.        
  268.         end
  269.     end
  270.  
  271.     function backUpRoot(rootP)
  272.         if rootP ~= "/" then
  273.             rootx = rootP
  274.             lef = string.len(rootP) - 1
  275.             for i=1,string.len(rootP) do
  276.                 check = i + lef
  277.                 check = check - 1
  278.                 if check > 0 then
  279.                     --DO CHECK HERE
  280.                     if string.sub(rootP, check, check) == "/" then
  281.                         break
  282.                     end
  283.                     --END CHECK HERE
  284.                     lef = lef - 2
  285.                 end
  286.             end
  287.             rootx = string.sub(rootx, 1, check)
  288.         else
  289.             rootx = rootP
  290.         end
  291.         return rootx
  292.     end
  293.  
  294.     function getFiles(path, many)
  295.         files = {"", ""}
  296.         mIndex = 1
  297.         cout = 0
  298.         sDir = shell.resolve( path )
  299.         local tAll = fs.list( sDir )
  300.         for n, sItem in pairs( tAll ) do
  301.             local sPath = fs.combine( sDir, sItem )
  302.             if fs.isDir( sPath ) == false then
  303.                 files[mIndex] = dataReader(sPath, "/", 1)[1]
  304.                 mIndex = mIndex + 1
  305.                 files[mIndex] = ""
  306.                 cout = cout + 1
  307.             end
  308.         end
  309.         if many == 1 then
  310.             files[1] = cout
  311.         end
  312.         return files
  313.     end
  314.  
  315.     function getDirectories(path, many)
  316.         directories = {"", ""}
  317.         mIndex = 1
  318.         cout = 0
  319.         sDir = shell.resolve( path )
  320.         local tAll = fs.list( sDir )
  321.         for n, sItem in pairs( tAll ) do
  322.             local sPath = fs.combine( sDir, sItem )
  323.             if fs.isDir( sPath ) then
  324.                 directories[mIndex] = dataReader(sPath, "/", 1)[1]
  325.                 mIndex = mIndex + 1
  326.                 directories[mIndex] = ""
  327.                 cout = cout + 1
  328.             end
  329.         end
  330.         if many == 1 then
  331.             directories[1] = cout
  332.         end
  333.         return directories
  334.     end
  335.  
  336.     function updateList()
  337.         filesMany = getFiles(root, 1)[1]
  338.         directoriesMany = getDirectories(root, 1)[1]
  339.         filesx = getFiles(root, 0)
  340.         directoriesx = getDirectories(root, 0)
  341.         scrollText = ""
  342.         for i=1,w / 2 do
  343.             scrollText = scrollText.."v"
  344.         end
  345.         for i=1,w / 2 do
  346.             scrollText = scrollText.."^"
  347.         end
  348.         if fileSelected == nil or fileSelected == " " then
  349.             fileSelected = ""
  350.         end
  351.         menuVisible = true
  352.         menuX = w - menuWidth - 1
  353.         menuY = 2
  354.         renstr = openWith
  355.         if fSetFile == true then
  356.             if fileSelected == "" or fileSelected == nil or fileSelected == " " then
  357.                 menuItems = {"Incolla", "Nuovo", "nfx"}
  358.                 menuItemsRenX = {"  Incolla   ", " Nuovo File ", "Nuova Cartella"}
  359.             else
  360.                 menuItems = {"Avvia", "----------","Edita","Copia", "Cancella",    "Deselect",    "Apri Con", "rnm"}
  361.                 menuItemsRenX = {"   Avvia    ", "----------", "   Edita   ", "   Copia   ", "  Cancella  ", " Deselect ",   "Apri Con", "  Rinomina  "}
  362.             end
  363.         end
  364.         menuHeight = table.getn(menuItems)
  365.         timeX = tostring(textutils.formatTime(os.time(), false))
  366.         if string.sub(root, string.len(root) - 1, string.len(root)) == "//" then
  367.             root = string.sub(root, 1, string.len(root) - 1)
  368.         end
  369.     end
  370.    
  371.     function render()
  372.         while loopRun == true do
  373.             sleep(0)
  374.             if loopRun == false then
  375.                 term.setBackgroundColor(colors.black)
  376.                 term.setTextColor(colors.white)
  377.                 term.clear()
  378.                 term.setCursorPos(1, 1)
  379.             end
  380.             if renderXX == true then
  381.                 if clickDoubleTimer ~= lasClickDoubleTimer then
  382.                     if clickDoubleTimer == true then
  383.                         cdTimer = os.time()
  384.                         cdLasTimer = os.time()
  385.                     else
  386.                         cdTotalTimer = 0
  387.                     end
  388.                     lasClickDoubleTimer = clickDoubleTimer
  389.                 end
  390.                 if clickDoubleTimer == true then
  391.                     cdTimer = os.time()
  392.                     cdTotalTimer = cdTimer - cdLasTimer
  393.                     if cdTotalTimer > 0.003 then
  394.                         clickDoubleTimer = false
  395.                     end
  396.                 end
  397.                 term.setBackgroundColor(colors.white)
  398.                 term.clear()
  399.                 ind = 1
  400.                 allowScroll = true
  401.                 for i=4,h do
  402.                     term.setCursorPos(1, i)
  403.                     --RENDER AND DOCUMENT ALL FILES!!
  404.                     if directoriesx[i - 3 + scroll] ~= nil and directoriesx[i - 3 + scroll] ~= "" then
  405.                         term.setBackgroundColor(colors.gray)
  406.                         term.setTextColor(colors.white)
  407.                         write("[=]")
  408.                         term.setBackgroundColor(colors.white)
  409.                         term.setTextColor(colors.gray)
  410.                         screenpos[i] = directoriesx[i - 3 + scroll]
  411.                         if directoriesx[i - 3 + scroll] == fileSelected then
  412.                             term.setBackgroundColor(colors.lightBlue)
  413.                             write(" "..directoriesx[i - 3 + scroll]..string.sub(blackStr, 1, w))
  414.                         else
  415.                             write(" "..directoriesx[i - 3 + scroll])
  416.                         end
  417.                     end
  418.                     if ind > directoriesMany - scroll then
  419.                         if filesx[ind - directoriesMany + scroll] ~= nil and filesx[ind - directoriesMany + scroll] ~= "" then
  420.                             term.setBackgroundColor(colors.gray)
  421.                             if openWith ~= "" then
  422.                                 if openWith ~= root..filesx[ind - directoriesMany + scroll] then
  423.                                     term.setTextColor(colors.orange)
  424.                                 else
  425.                                     term.setTextColor(colors.lime)
  426.                                 end
  427.                             else
  428.                                 term.setTextColor(colors.lime)
  429.                             end
  430.                             write("-~-")
  431.                             term.setBackgroundColor(colors.white)
  432.                             term.setTextColor(colors.gray)
  433.                             filepos[i] = filesx[ind - directoriesMany + scroll]
  434.                             if filesx[ind - directoriesMany + scroll] == fileSelected then
  435.                                 term.setBackgroundColor(colors.lightBlue)
  436.                                 write(" "..filesx[ind - directoriesMany + scroll]..string.sub(blackStr, 1, w))
  437.                             else
  438.                                 write(" "..filesx[ind - directoriesMany + scroll])
  439.                             end
  440.                         end
  441.                     end
  442.                     --END
  443.                     ind = ind + 1
  444.                 end
  445.                 term.setBackgroundColor(colors.lightBlue)
  446.                 term.setCursorPos(1, 1)
  447.                 term.clearLine()
  448.                 term.setTextColor(colors.white)
  449.                 write("[Chiudi]")
  450.                 if renderTime == true then
  451.                     term.setCursorPos(w - string.len(timeX), 1)
  452.                     write(timeX)
  453.                 end
  454.                 term.setTextColor(colors.lightGray)
  455.                 term.setBackgroundColor(colors.white)
  456.                 term.setCursorPos(1, 2)
  457.                 write(root..string.sub(blackStr, 1, w))
  458.                 term.setCursorPos(1, 3)
  459.                 term.setBackgroundColor(colors.gray)
  460.                 term.setTextColor(colors.lightBlue)
  461.                 write("<< ")
  462.                 if fileSelected == ".." then
  463.                     term.setBackgroundColor(colors.lightBlue)
  464.                 else
  465.                     term.setBackgroundColor(colors.white)
  466.                 end
  467.                 term.setTextColor(colors.lightGray)
  468.                 write(" .."..string.sub(blackStr, 1, w))
  469.                 term.setCursorPos(1, h + 1)
  470.                 term.setBackgroundColor(colors.yellow)
  471.                 term.clearLine()
  472.                 term.setTextColor(colors.cyan)
  473.                 if enterText == false then
  474.                     write(Version.." "..Who)
  475.                 else
  476.                     write(textData.."|")
  477.                 end
  478.                 if allowScroll == true then
  479.                     term.setCursorPos(w, h + 1)
  480.                     term.setBackgroundColor(colors.gray)
  481.                     term.setTextColor(colors.white)
  482.                     if scroll < directoriesMany + filesMany - h + 3 then
  483.                         write("v")
  484.                     else
  485.                         write(" ")
  486.                     end
  487.                     term.setCursorPos(w, 2)
  488.                     if scroll ~= 0 then
  489.                         write("^")
  490.                     else
  491.                         write(" ")
  492.                     end
  493.                     term.setCursorPos(w - 1, h + 1)
  494.                     term.setBackgroundColor(colors.gray)
  495.                     term.setTextColor(colors.white)
  496.                     if scroll < directoriesMany + filesMany - h + 3 then
  497.                         write("v")
  498.                     else
  499.                         write(" ")
  500.                     end
  501.                     term.setCursorPos(w - 1, 2)
  502.                     if scroll ~= 0 then
  503.                         write("^")
  504.                     else
  505.                         write(" ")
  506.                     end
  507.                     if scroll < directoriesMany + filesMany - h + 3 or scroll ~= 0 then
  508.                         switch = 1
  509.                         for i=3,h do
  510.                             if switch == 1 then
  511.                                 switch = 1
  512.                                 term.setBackgroundColor(colors.gray)
  513.                             else
  514.                                 switch = 1
  515.                                 term.setBackgroundColor(colors.lightGray)
  516.                             end
  517.                             term.setCursorPos(w, i)
  518.                             write(" ")
  519.                             term.setCursorPos(w - 1, i)
  520.                             write(" ")
  521.                         end
  522.                     else
  523.                         for i=3,h do
  524.                             term.setBackgroundColor(colors.gray)
  525.                             term.setCursorPos(w, i)
  526.                             write(" ")
  527.                             term.setCursorPos(w - 1, i)
  528.                             write(" ")
  529.                         end
  530.                     end
  531.                 end
  532.                 if menuVisible == true then
  533.                     if fSetFile == true then
  534.                         term.setBackgroundColor(colors.cyan)
  535.                     else
  536.                         term.setBackgroundColor(colors.green)
  537.                     end
  538.                     term.setTextColor(colors.black)
  539.                     for i=1,table.getn(menuItems) do
  540.                         term.setCursorPos(menuX, menuY + i - 1)
  541.                         if menuItemsRenX[i] ~= nil then
  542.                             write(menuItemsRenX[i])
  543.                         end
  544.                     end
  545.                     for i=table.getn(menuItems) + 1,h + 1 do
  546.                         term.setCursorPos(menuX, menuY + i - 1)
  547.                         write("          ")
  548.                     end
  549.                 end
  550.             end
  551.             if loopRun == false then
  552.                 term.setBackgroundColor(colors.black)
  553.                 term.setTextColor(colors.white)
  554.                 term.clear()
  555.                 term.setCursorPos(1, 1)
  556.             end
  557.         end
  558.     end
  559.    
  560.     function input()
  561.         while true do
  562.             local event, p1, p2, p3 = os.pullEvent()
  563.             if event == "mouse_click" then
  564.                 if menuVisible == false then
  565.                     menuCheck = true
  566.                 else
  567.                     if p2 > menuX - 1 and p2 < menuX - 1 + menuWidth + 1 and p3 > menuY - 1 and p3 < menuY - 1 + menuHeight + 1 then
  568.                         menuCheck = false
  569.                         itM = p3 - menuY + 1
  570.                         if menuItems[itM] ~= nil then
  571.                             if fSetFile == true then
  572.                                 if fileSelected ~= nil and fileSelected ~= "" then
  573.                                     menuResolve(tostring(menuItems[itM]))
  574.                                 end
  575.                                 if fileSelected == "" then
  576.                                     menuResolve(tostring(menuItems[itM]))
  577.                                 end
  578.                             else
  579.                                 menuResolve(tostring(menuItems[itM]))
  580.                             end
  581.                         else
  582.                             break
  583.                         end
  584.                     else
  585.                         menuCheck = true
  586.                     end
  587.                 end
  588.                 if menuCheck == true then
  589.                     if p3 == 1 then
  590.                         if p1 == 1 then
  591.                             if p2 < 8 then
  592.                                 if instaClose == true then
  593.                                     menuResolve("Si")
  594.                                 else
  595.                                     fSetFile = false
  596.                                     menuItems = {"Si", "No"}
  597.                                     menuItemsRenX = {"   Si    ", "    No    "}
  598.                                 end
  599.                             end
  600.                         end
  601.                     elseif p3 == 3 then
  602.                         if changepos == true then
  603.                             fileSelected = ".."
  604.                         end
  605.                         if cdTotalTimer ~= 0 then
  606.                             if changepos == true then
  607.                                 root = backUpRoot(root)
  608.                             end
  609.                             scroll = 0
  610.                         end
  611.                         clickDoubleTimer = true
  612.                     elseif p3 < h + 1 then
  613.                         if p3 ~= 2 then
  614.                             if p2 <= w - menuWidth - 2 then
  615.                                 pe = p3 - 4
  616.                                 file11 = false
  617.                                 if pe >= directoriesMany - scroll then
  618.                                     --Clicked On A File
  619.                                     if filepos[p3] ~= nil and filepos[p3] ~= "" then
  620.                                         file11 = true
  621.                                         --renderXX = false
  622.                                         --term.setBackgroundColor(colors.black)
  623.                                         --term.setTextColor(colors.white)
  624.                                         --term.clear()
  625.                                         --term.setCursorPos(1, 1)
  626.                                         --shell.run(root..filepos[p3])
  627.                                         --renderXX = true
  628.                                         if p1 == 1 then
  629.                                             if changepos == true then
  630.                                                 fileSelected = filepos[p3]
  631.                                             end
  632.                                             if cdTotalTimer ~= 0 then
  633.                                                 fManRun(root..fileSelected)
  634.                                                 end
  635.                                                 clickDoubleTimer = true
  636.                                             end
  637.                                         else
  638.                                             if changepos == true then
  639.                                                 fileSelected = filepos[p3]
  640.                                             end
  641.                                         end
  642.                                     else
  643.                                     --Clicked On A Folder
  644.                                     if screenpos[p3] ~= nil and screenpos[p3] ~= "" then
  645.                                         if p1 == 1 then
  646.                                             if changepos == true then
  647.                                                 fileSelected = screenpos[p3]
  648.                                             end
  649.                                             if cdTotalTimer ~= 0 then
  650.                                                 if changepos == true then
  651.                                                     root = root..screenpos[p3].."/"
  652.                                                 end
  653.                                                 if changepos == true then
  654.                                                     fileSelected = ""
  655.                                                 end
  656.                                             end
  657.                                             clickDoubleTimer = true
  658.                                         else
  659.                                             if changepos == true then
  660.                                                 fileSelected = screenpos[p3]
  661.                                             end
  662.                                         end
  663.                                     end
  664.                                 end
  665.                             end
  666.                         else
  667.                             if p2 >= w - 1 then
  668.                                 if allowScroll == true then
  669.                                     if scroll ~= 0 then
  670.                                         scroll = scroll - 1
  671.                                     end
  672.                                 end
  673.                             end
  674.                         end
  675.                     elseif p3 == h + 1 then
  676.                         if p2 >= w - 1 then
  677.                             if allowScroll == true then
  678.                                 if scroll < directoriesMany + filesMany - h + 3 then
  679.                                     scroll = scroll + 1
  680.                                 end
  681.                             end
  682.                         end
  683.                     end
  684.                 end
  685.             elseif event == "mouse_drag" then
  686.                 if allowScroll == true then
  687.                     if p2 >= w - 1 then
  688.                         if dragLasY ~= p3 then
  689.                             if p3 > dragLasY then
  690.                                 if scroll < directoriesMany + filesMany - h + 3 then
  691.                                     scroll = scroll + 1
  692.                                 end
  693.                             else
  694.                                 if scroll ~= 0 then
  695.                                     scroll = scroll - 1
  696.                                 end
  697.                             end
  698.                         end
  699.                         dragLasY = p3
  700.                     end
  701.                 end
  702.             elseif event == "key" then
  703.                 if enterText == true then
  704.                     if p1 == 28 then
  705.                         local ok, err = (menuResolve(textPurpose, textData))
  706.                         textData = ""
  707.                         textPurpose = ""
  708.                         enterText = false
  709.                     elseif p1 == 14 then
  710.                         textData = string.sub(textData, 1, string.len(textData) - 1)
  711.                     end
  712.                 end
  713.             elseif event == "char" then
  714.                 if enterText == true then
  715.                     textData = textData..p1
  716.                 end
  717.             end
  718.             updateList()
  719.         end
  720.     end
  721.     updateList()
  722.    
  723.     parallel.waitForAny(render, input)
  724.  
  725. end
  726.  
  727. while true do
  728. local ok, err = pcall(startMain)
  729.     if not ok then
  730.         term.setBackgroundColor(colors.blue)
  731.         for i=-5,5 do
  732.             term.setCursorPos(1, h / 2 + i)
  733.             term.clearLine()
  734.         end
  735.         term.setTextColor(1)
  736.         term.setCursorPos(math.floor(w-string.len(" Runtime Error! "))/2, h / 2 - 4)
  737.         term.setBackgroundColor(colors.white)
  738.         term.setTextColor(colors.blue)
  739.         write(" Runtime Error! ")
  740.         term.setCursorPos(math.floor(w-string.len(err))/2, h / 2 - 2)
  741.         term.setBackgroundColor(colors.blue)
  742.         term.setTextColor(1)
  743.         write(err)
  744.         term.setCursorPos(math.floor(w-string.len("A/?? - Continue Program"))/2, h / 2 + 2)
  745.         write("A/?? - Continue Program")
  746.         term.setCursorPos(math.floor(w-string.len("B - Terminate Program"))/2, h / 2 + 4)
  747.         write("B - Terminate Program")
  748.         local event, p1 = os.pullEvent("char")
  749.         if p1 == "B" or p1 == "b" then
  750.             term.setBackgroundColor(colors.black)
  751.             term.setTextColor(colors.white)
  752.             term.setCursorPos(1, 1)
  753.             term.clear()
  754.             break
  755.         else
  756.             changepos = true
  757.             enterText = false
  758.             textData = ""
  759.             textPurpose = ""
  760.             updateList()
  761.         end
  762.     else
  763.         break
  764.     end
  765. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement