Advertisement
shadowkat1010

print.lua

May 18th, 2014
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.37 KB | None | 0 0
  1. --A very simplistic printing program.
  2. --Originally by ShadowKatStudios
  3. --Increased usability and various other improvements by Technokami
  4.  
  5. local component = require("component")
  6. local computer = require("computer")
  7.  
  8. if not component.isAvailable("openprinter") then
  9.   io.stderr:write("Can't print without a printer!")
  10.   return
  11. end
  12.  
  13. local args = {...}
  14.  
  15. if #args == 0 or (#args == 1 and args[1] == "-g") then
  16.   io.write("Usage: print [-g] <filename>\n")
  17.   io.write(" -g: Global path - Use a global path for the target file instead of a local path.")
  18.   return
  19. end
  20.  
  21. if args[1] == "-g" then
  22.   path = args[2]
  23.   name = args[2]
  24. else
  25.   path = os.getenv("PWD").."/"..args[1]
  26.   name = args[1]
  27. end
  28.  
  29. local lines = {}
  30. local component = require "component"
  31. local op = component.openprinter
  32.  
  33. print "Opening file..."
  34. local fobj = io.open(path,"rb")
  35.  
  36. print "Reading file..."
  37. for l in fobj:lines() do
  38.   done = false
  39.   while done == false do
  40.     if l:len() > 30 then
  41.       table.insert(lines,l:sub(1,30))
  42.       l=">"..l:sub(31)
  43.     else
  44.       table.insert(lines,l)
  45.       done = true
  46.     end
  47.   end
  48. end
  49.  
  50. fobj:close()
  51. local counter = 0
  52.  
  53. print "Beginning to print..."
  54. for key,value in pairs(lines) do
  55.   if counter == 20 then
  56.     op.setTitle(name)
  57.     op.print()
  58.     counter = 0
  59.   end
  60.   op.writeln(value)
  61.   counter = counter + 1
  62. end
  63.  
  64. op.setTitle(name)
  65. op.print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement