Advertisement
Guest User

Untitled

a guest
Feb 16th, 2014
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local fs = require("filesystem")
  4. local keyboard = require("keyboard")
  5. local shell = require("shell")
  6. local term = require("term")
  7. local text = require("text")
  8. local unicode = require("unicode")
  9. local sides = require("sides")
  10. local colors=require("colors")
  11. local line = " "
  12.  
  13. --getString:
  14. -- Given a row and col, and an initial string, edit a string
  15. -- len is the maximum number of characters allowed in the string
  16. local function getString (row, col, start, len)
  17. local currLine = start
  18. if string.len(currLine) > 0 then
  19. currLine = currLine:gsub("^%s*(.-)%s*$", "%1")
  20. end
  21. local finished = false
  22.  
  23. while not finished do
  24. local event, address, char, code, arg3 = event.pull()
  25. term.setCursor(col, row)
  26. if string.len(currLine) <= len then
  27. print(currLine)
  28. end
  29. if type(address) == "string" and component.isPrimary(address) then
  30. if event == "key_down" then
  31. if code == keyboard.keys.back then
  32. if string.len(currLine) > 0 then
  33. currLine = string.sub(currLine, 1, (string.len(currLine) - 1))
  34. if currPos > 0 then
  35. currPos = currPos - 1
  36. end
  37. end
  38. elseif code == keyboard.keys.enter then
  39. finished = true
  40. elseif not keyboard.isControl(char) then
  41. if string.len(currLine) < len then
  42. currLine = currLine..string.char(char)
  43. end
  44. end
  45. end
  46. end
  47. end
  48. return (currLine)
  49. end
  50.  
  51. line = getString (5, 10, line, 30)
  52. term.setCursor(7, 10)
  53. print(line)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement