Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Find the printer
- local printer = peripheral.find("printer")
- if not printer then
- error("No printer connected")
- end
- -- Function to print text
- local function printText(text)
- if printer.newPage() then
- printer.setPageTitle("Printed Page")
- printer.write(text)
- if not printer.endPage() then
- error("Failed to end the page. Check the printer for paper and ink.")
- end
- else
- error("Failed to start a new page. Check the printer for paper and ink.")
- end
- end
- -- text editor
- local function textEditor()
- term.clear()
- term.setCursorPos(1,1)
- print("Enter your text below. Press Ctrl to print and exit.")
- local inputText = ""
- while true do
- local event, key = os.pullEvent("key")
- if key == keys.leftCtrl or key == keys.rightCtrl then
- -- Print command
- if inputText ~= "" then
- printText(inputText)
- print("Text sent to printer.")
- break
- end
- else
- local char = string.char(key)
- inputText = inputText .. char
- term.write(char)
- end
- end
- end
- -- Run the text editor
- textEditor()
Advertisement
Add Comment
Please, Sign In to add comment