gaga2023

my testing thing

Dec 31st, 2023 (edited)
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. -- Find the printer
  2. local printer = peripheral.find("printer")
  3. if not printer then
  4. error("No printer connected")
  5. end
  6.  
  7. -- Function to print text
  8. local function printText(text)
  9. if printer.newPage() then
  10. printer.setPageTitle("Printed Page")
  11. printer.write(text)
  12. if not printer.endPage() then
  13. error("Failed to end the page. Check the printer for paper and ink.")
  14. end
  15. else
  16. error("Failed to start a new page. Check the printer for paper and ink.")
  17. end
  18. end
  19.  
  20. -- text editor
  21. local function textEditor()
  22. term.clear()
  23. term.setCursorPos(1,1)
  24. print("Enter your text below. Press Ctrl to print and exit.")
  25.  
  26. local inputText = ""
  27. while true do
  28. local event, key = os.pullEvent("key")
  29. if key == keys.leftCtrl or key == keys.rightCtrl then
  30. -- Print command
  31. if inputText ~= "" then
  32. printText(inputText)
  33. print("Text sent to printer.")
  34. break
  35. end
  36. else
  37. local char = string.char(key)
  38. inputText = inputText .. char
  39. term.write(char)
  40. end
  41. end
  42. end
  43.  
  44. -- Run the text editor
  45. textEditor()
  46.  
Advertisement
Add Comment
Please, Sign In to add comment