This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
cptdeath58's profile picture

Simple Printing Program (WIP)

Started by cptdeath58, 05 May 2014 - 09:11 PM
cptdeath58 #1
Posted 05 May 2014 - 11:11 PM
Just a simple printing program I made.
For use with people who want to write something and don't want to print it out like this:
SpoilerHello, My name is Joh
n. and I like pie.
So, just to be safe I made this.
Spoiler
--[[
Printer Program by
cptdeath58
--]]
local pSide = "left" -- change "left" to whatever side the printer is on.
local tCursor = "2"
function testSize()
local px , py = printer.getCursorPos()
local tx , ty = term.getCursorPos()
if px > 25 then
  write( "You must enter a max of 25 characters:" )
  write( px )
  printer.setCursorPos(1,py)
  printer.write("							   ")
  term.setCursorPos(1,ty + 1)
  printer.setCursorPos(1,py - 1)
elseif py > 21 then
  printer.newPage()
  printer.setCursorPos( 1,2 )
  setPrinter()
end
end
function setPrinter()
while true do
  term.clear()
  term.setCursorPos(1,1)
  term.write( "Please input Title: " )
  local title = read()
  if title == nil then
   term.setCursorPos(1,2)
   term.write( "You must enter a Title!" )
   sleep(1)
   setPrinter()
  else
   printer.newPage()
   printer.setPageTitle( title )
   break
  end
end
end
function testInk()
local ink = printer.getInkLevel()
if ink < 1 then
  repeat
   term.clear()
   sleep(1)
   term.setCursorPos( 1,1 )
   term.write( "Please Insert Ink!" )
   sleep(1)
   startPrinter()
  until ink > 1
end
end
function startPrinter()
printer = peripheral.wrap( pSide)
testInk()
setPrinter()
term.clear()
term.setCursorPos(1,1)
term.write( "Input the Text you want to print." )
term.setCursorPos(1,2)
term.write( "To start a new page, type 'new page'." )
term.setCursorPos(1,3)
term.write( "To end, enter 'quit'." )
term.setCursorPos( 1,4 )
term.write( "To Erase last line, type 'erase'." )
term.setCursorPos ( 1,5 )
printer.setCursorPos(1,2)
while true do
  local input = read()
  if input == "quit" then
   printer.endPage()
   term.clear()
   term.setCursorPos(5,1)
   write( "Thank you for using the Printer Program" )
   term.setCursorPos(15,2)
   write( "By cptdeath58" )
   term.setCursorPos(1,3)
   break
  elseif input == "new page" then
   printer.endPage()
   setPrinter()
  elseif input == "erase" then
   local px , py = printer.getCursorPos()
   printer.setCursorPos( 1,py - 1 )
   printer.write( "						 " )
   term.setCursorPos( 1,py + 2 )
  else
   local px , py = printer.getCursorPos()
   printer.setCursorPos( 1,py + 1)
   printer.write( input )
   testSize()
  end
end
end
startPrinter()
[Features]
Ink Detection.
Automatically starts a new page when it is full.
Stops you from writing the page like above.
[Notes]
* The number after the sentence of "You must enter a max of 25 characters:" is how many characters was entered.
* The title check for nil is buggy, But the rest of the program still works. :D/>
* Does not have color yet
[Plans]
* Fix the nil bug
* Add some color
* If possible, Try to make the program more lighter.
[Pictures]
SpoilerInput Title
[attachment=1635:2014-05-06_15.39.52.png]
The Editor
[attachment=1636:2014-05-06_15.40.08.png]
The Result
[attachment=1637:2014-05-06_15.40.18.png]
FAQ:
SpoilerQ. There is no color.
A. Look up.
Q. This program is copyright!
A. How am I supposed to know that and what kind of person puts
copyright on a printer program… (No Offense)
Q. This program has a bug.
A. Post the bug and I will try and fix it.
Q. This program sucks.
A. I said it was simple. Plus it is for certain people who don't know
how big a page really is.
Q. How do you install it?
A. pastebin get sZKRNNKF Printer
Q. Printer:42: attempt to index ? ( a nil value )
A. Now, how are you gonna print a piece of paper without a printer?
Q. Printer:36: Page not Started
A. Now, how are you gonna print a piece of paper without a piece of paper?!?!?!?
Before you ask any of these Questions, look at the FAQ.
Edited on 06 May 2014 - 10:22 PM
Lyqyd #2
Posted 06 May 2014 - 01:04 AM
You should probably provide support for installing your program here in your topic, rather than sending people off to Ask a Pro. It is awfully dismissive to just tell people to go elsewhere for support.
Agoldfish #3
Posted 06 May 2014 - 01:06 AM
-A pastebin installer would be nice.
-That code in a spoiler would be nice too.
cptdeath58 #4
Posted 06 May 2014 - 11:13 PM
-A pastebin installer would be nice.
-That code in a spoiler would be nice too.
You should probably provide support for installing your program here in your topic, rather than sending people off to Ask a Pro. It is awfully dismissive to just tell people to go elsewhere for support.

Done.
Sorry about that part.
Just had to gather a bit more info on the ways of installing the program.
Still getting the pastebin part
Edited on 06 May 2014 - 09:21 PM