kd2bwzgen

Printerm API

Jun 25th, 2017
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. local function stub() return end
  2. local function stubonearg(a) return end
  3.  
  4. function getTerm(sSide)
  5. local printer = peripheral.wrap(sSide)
  6. local onPage = false
  7. if not printer then error("PrintermAPI: No printer on side "..sSide) end
  8. local tx,ty = 1,1
  9. local function checkStatus()
  10. if printer.getPaperLevel()==0 then error("PrintermAPI: No paper in the printer!",0) end
  11. if printer.getInkLevel()==0 then error("PrintermAPI: No ink in the printer",0) end
  12. end
  13. checkStatus()
  14. local ret = {}
  15. for k,v in pairs(printer) do
  16. ret[k] = v
  17. end
  18. ret.newPage = function()
  19. onPage = true
  20. printer.newPage()
  21. end
  22. ret.endPage = function()
  23. onPage = false
  24. printer.endPage()
  25. end
  26. ret.write = function(s)
  27. if not onPage then
  28. ret.newPage()
  29. end
  30. checkStatus()
  31. printer.write(s)
  32. tx,ty = printer.getCursorPos()
  33. end
  34. ret.blit = function(s,tc,bc)
  35. ret.write(s)
  36. end
  37. ret.clear = stub
  38. ret.clearLine = stub
  39. ret.setCursorBlink = stub
  40. ret.isColor = function() return false end
  41. ret.getSize = printer.getPageSize
  42. ret.scroll = stubonearg
  43. ret.setTextColor = stubonearg
  44. ret.getTextColor = function() return colors.black end
  45. ret.setBackgroundColor = stubonearg
  46. ret.getBackgroundColor = function() return colors.white end
  47. ret.setTextColour = stubonearg
  48. ret.getTextColour = function() return colors.black end
  49. ret.setBackgroundColour = stubonearg
  50. ret.getBackgroundColour = function() return colors.white end
  51. return ret
  52. end
Advertisement
Add Comment
Please, Sign In to add comment