Advertisement
Marlingaming

TextField API

Nov 3rd, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. local function TextField(settings)
  2. local C
  3. if settings[1] == true then C = "*" else C = nil end --censor text
  4. local E = true
  5. if settings[2] ~= nil then E = settings[2] end --allow use to cancel?
  6. local X
  7. local Y
  8. local TX, TY = term.getCursorPos()
  9. if E == true then
  10. X = TX
  11. Y = TY + 1
  12. paintutils.drawPixel(X,Y,colors.red())
  13. end
  14. term.setBackgroundColor(colors.white)
  15. term.setTextColor(colors.black)
  16. local input
  17. while true do
  18. term.setCursorPos(TX,TY)
  19. term.clearLine()
  20. local e, a, b, c = os.pullEvent()
  21. if e == "mouse_click" and b == X and c == Y and E == true then input = nil break end --cancel
  22. if e == "key" and a == keys.enter then break elseif e == "key" then input = read(C) end
  23. end
  24. return input
  25. end
  26.  
  27. return { TextField = TextField }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement