Advertisement
brony9TYNINE

NOT MINE coppied for testing

Dec 9th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. local tFiles = fs.list("/")
  2. local sInput = ""
  3. local nFilesDisplayed = 0
  4. local select = 0 -- 0 is the textField
  5.  
  6. local function clear() term.clear(); term.setCursorPos( 1, 1 ) end
  7.  
  8. local function getInputAndPredictText()
  9. while true do
  10. clear()
  11.  
  12. -- Predict the text --
  13. for i=4, nFilesDisplayed+3 do -- Clear the space where the text is drawn
  14. term.setCursorPos(3, i)
  15. term.write(string.rep(" ", 46))
  16. end
  17. for i=1, #tFiles do
  18. if string.sub(tFiles[i], 1, string.len(sInput)) == sInput then
  19. nFilesDisplayed = nFilesDisplayed+1
  20.  
  21. term.setCursorPos(3, nFilesDisplayed+4)
  22. if select == nFilesDisplayed then
  23. term.write(">"..tFiles[i])
  24. if not fs.isDir( tFiles[i] ) then sSelectedFile = tFiles[i] end
  25. else     term.write(" "..tFiles[i]) end
  26. end
  27. end
  28. term.setCursorPos(3, 4); term.write(string.rep(" ", string.len("No matches found.")))
  29. if nFilesDisplayed == 0 then term.setCursorPos(3, 4); term.write("No matches found.") end
  30.  
  31. term.setCursorPos(1, 1); term.write("> ")
  32. term.setCursorPos(3, 1)
  33. term.write(sInput)
  34. event, char = os.pullEvent()
  35.  
  36. if select == 0 then
  37. term.setCursorBlink(true)
  38. if event == "char" then sInput = sInput .. char
  39. elseif event == "key" and char == 14 then
  40. term.setCursorPos(3, 1); term.write(string.rep(" ", string.len(sInput)))
  41. sInput = string.sub(sInput, 1, string.len(sInput)-1)
  42. elseif event == "key" and char == 208 then term.setCursorBlink(false); select = select+1
  43.  
  44. elseif event == "key" and char == 28 and sInput == "exit" then term.setCursorBlink(false); break
  45. end
  46. else
  47. term.setCursorBlink(false)
  48. if event == "key" and char == 208 and select < nFilesDisplayed then select = select+1
  49. elseif event == "key" and char == 200 and select-1 == 0 then term.setCursorBlink(true); select = 0
  50. elseif event == "key" and char == 200 then select = select-1
  51. elseif event == "key" and char == 28 and sSelectedFile ~= "isDir" then os.run({ ["shell"] = shell }, sSelectedFile)
  52. end
  53. end
  54.  
  55. nFilesDisplayed = 0
  56. end
  57. end
  58.  
  59. clear()
  60. term.setCursorBlink(true)
  61. getInputAndPredictText()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement