Advertisement
BlueMond

Testing

Dec 17th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. --credit to CraniumKid22 for limitRead
  2. function limitRead(limX, rChar)
  3. term.setCursorBlink(true)
  4. local origX, origY = term.getCursorPos()
  5. local returnString = ""
  6. while true do
  7. local xPos, yPos = term.getCursorPos()
  8. local event, p1, p2 = os.pullEvent()
  9. if event == "char" then
  10. returnString = returnString..p1
  11. if not rChar then
  12. if not limX then
  13. write(p1)
  14. else
  15. if string.len(returnString) >= limX then
  16. term.setCursorPos(origX, origY)
  17. write(string.sub(returnString, (string.len(returnString)-limX)+1))
  18. elseif string.len(returnString) < limX then
  19. write(p1)
  20. end
  21. end
  22. else
  23. if not limX then
  24. write(rChar)
  25. else
  26. if string.len(returnString) >= limX then
  27. term.setCursorPos(origX, origY)
  28. write(string.rep(rChar, limX))
  29. elseif string.len(returnString) < limX then
  30. write(rChar)
  31. end
  32. end
  33. end
  34. elseif event == "key" and p1 == 14 then --backspace
  35. returnString = string.sub(returnString, 1, (string.len(returnString))-1)
  36. term.setCursorPos(xPos-1,yPos)
  37. write(" ")
  38. term.setCursorPos(origX, origY)
  39. if string.len(returnString) >= limX then
  40. if not rChar then
  41. write(string.sub(returnString, (string.len(returnString)-limX)+1))
  42. else
  43. write(string.rep(rChar,limX))
  44. end
  45. else
  46. if not rChar then
  47. write(returnString)
  48. else
  49. write(string.rep(rChar, string.len(returnString)))
  50. end
  51. end
  52. elseif event == "key" and p1 == 28 then --enter
  53. break
  54. end
  55. end
  56. term.setCursorBlink(false)
  57. return returnString
  58. end
  59.  
  60. --paste the screen for user to enter password
  61. function pastePasswordScreen()
  62. shell.run("clear")
  63. term.setTextColor(colors.red)
  64. print("+---+-----------------------+")
  65. print("| | Private Archives |")
  66. print("| +-----------------------+")
  67. print("| | Password: |")
  68. print("| | > |")
  69. print("+---+-----------------------+")
  70. term.setTextColor(colors.lime)
  71. term.setCursorPos(2,2)
  72. print("C T")
  73. term.setCursorPos(2,3)
  74. print("u e")
  75. term.setCursorPos(2,4)
  76. print("b c")
  77. term.setCursorPos(2,5)
  78. print("e h")
  79. --temp
  80. wait(10)
  81. end
  82.  
  83. --start
  84. pastePasswordScreen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement