CoderJohn

ComputerCraft Print - ENET

Nov 12th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. local t_args = {...};
  2. if(not t_args[1])then
  3. print("Usage: print <filename> <pagename>");
  4. return false;
  5. end
  6. local pageName = t_args[2] or t_args[1];
  7. local hPrinter = peripheral.wrap("top");
  8. local hFile = fs.open(t_args[1],'r');
  9. local text = hFile.readAll():gsub('\r',''):gsub('\n','');
  10. hPrinter.newPage();
  11. local width, height = hPrinter.getPageSize();
  12. local totalPages = math.ceil(#text/(width*height-1));
  13. local y = 1;
  14. local page = 1;
  15.  
  16. while(#text>=width)do
  17. local subText = text:sub(1,width-1);
  18. hPrinter.write(subText);
  19. y = y + 1;
  20. if(y >= height)then
  21. hPrinter.setPageTitle(pageName.." "..page.."/"..totalPages);
  22. hPrinter.endPage();
  23. hPrinter.newPage();
  24. y = 1;
  25. page = page + 1;
  26. end
  27. hPrinter.setCursorPos(1,y);
  28. text = text:sub(width);
  29. end
  30. hPrinter.write(text);
  31. hPrinter.setPageTitle(pageName.." "..page.."/"..totalPages);
  32. hPrinter.endPage();
Advertisement
Add Comment
Please, Sign In to add comment