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

Help with Printers

Started by CastleMan2000, 24 September 2012 - 01:59 PM
CastleMan2000 #1
Posted 24 September 2012 - 03:59 PM
Hello, I am making a program called PrInterface. I want it to be a live suite for creating pages and printing them as soon as they are done. I have most of the stuff down, with one problem: I have no idea how to make it input text! I don't want to use io.read() because you have to press enter when you are done, and you can't change the cursor while things are being input. Can anyone come up with some code that will do this? I would like it to be as smooth as the built in edit program, if you can.
OmegaVest #2
Posted 24 September 2012 - 05:41 PM
Hmm… Well, I won't write it for you, mostly because I don't have the time, but I can get you started with some ideas.

From what I understand of the edit program (which you can actually look up by opening it. ie edit edit), it captures the keys/chars, then dumps them to a table. Or. . . might be an array of strings. Can't quite recall. Either way, you can do the same thing. Everytime they type a character, it captures it via pullEvent(), drops it into a table, places that character on screen, pushes the cursor over (or forces a return escape for end-of-line), and waits for another key.

For delete and return, and the arrow keys, you will need to capture the key values, also through pullEvent(), then execute the command, ie. for delete, string.sub(tab[#], 1, tab[#].len-1).


And, the cursor position is mostly cosmetic, though changing each character in a string is harder when it is actually a string. Making the document a table until it prints is probably simpler, because you can just make the cursor position the table coords.
CastleMan2000 #3
Posted 24 September 2012 - 08:04 PM
Yeah, thank you. That is a good idea.
ChaddJackson12 #4
Posted 26 September 2012 - 02:56 PM
Don't know if it is answered yet, but the API for them is on the wiki…
OmegaVest #5
Posted 27 September 2012 - 10:40 PM
Don't know if it is answered yet, but the API for them is on the wiki…

He was trying to figure out a way to use what is in the API in a manner that suits a higher-level user base.
ChaddJackson12 #6
Posted 28 September 2012 - 12:41 AM
Don't know if it is answered yet, but the API for them is on the wiki…

He was trying to figure out a way to use what is in the API in a manner that suits a higher-level user base.
Ah, thanks for clarifying that. XD