Larvix

pup_help

Mar 3rd, 2026
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. -- Display help pages, optionally search for key words
  2. function pup.help(query)
  3. local allPages = {
  4. [[===================================================
  5. SETUP
  6. ===================================================
  7. > Load an existing image
  8. | nfp = pup.loadImage(path)
  9. | nfp = pup.parseImage(string)
  10. -- NFP image from file or string; as in original
  11.  
  12. > Create a new image
  13. | nfp = pup.drawFilledBox(x,y,x2,y2,colour[,draw])
  14. | nfp = pup.drawBox(x,y,x2,y2,colour[,draw])
  15. -- returns image; if draw = false don't print
  16.  
  17. > Inspect image size
  18. | width, height = nfp:getSize()
  19.  
  20. * API must be loaded; e.g. 'pup = require("pup")']],
  21. [[===================================================
  22. MANIPULATE: IMAGE EDITING
  23. ===================================================
  24. > Resize the image canvas
  25. | nfp:resizeCanvas(width,height[,bgColour])
  26. -- crops or pads canvas to specified size
  27.  
  28. > Overlay an image on top of this one
  29. | nfp:overlay(topImage,xPos,yPos[,resize])
  30. -- default xPos/yPos = 1, resize = true
  31.  
  32. > Replace all instances of one colour with another
  33. | nfp:setColour(oldColour,newColour[,mutate])
  34. > Replace the colour of a specific pixel
  35. | nfp:setPixel(x,y,colour[,mutate])
  36.  
  37. * If mutate = true then original is edited]],
  38. [[===================================================
  39. MANIPULATE: TRANSFORMATION
  40. ===================================================
  41. > Flip an image on given axes
  42. | nfp:mirror("x"|"y"|"xy")
  43.  
  44. > Rotate an image 90 degrees clockwise
  45. | nfp:rotate()
  46.  
  47. > Make an image larger (multiplies each pixel)
  48. | nfp:enlarge([factor])
  49. -- default factor = 2]],
  50. [[===================================================
  51. MANIPULATE: FORMAT EDITING
  52. ===================================================
  53. > Convert NFP image into blit image (BIMG) format
  54. | nfp:blitImage()
  55. -- 1:1 pixel conversion
  56.  
  57. > Upscale image to compressed 2x3 pixel clusters
  58. | nfp:upscale([bgColour])
  59. -- default bgColour = current background
  60.  
  61. * Upscaling may add pixels to ensure w%2 and h%3]],
  62. [[===================================================
  63. OUTPUT
  64. ===================================================
  65. > Draw NFP to screen
  66. | nfp:drawImage(x,y)
  67. | pup.drawImage(image,x,y)
  68.  
  69. > Draw BIMG to screen
  70. | bimg:drawImage(x,y)
  71.  
  72. > Save to file
  73. | nfp:saveImage(path)
  74. | bimg:saveImage(path)
  75. -- BIMG is serialised
  76.  
  77. * File paths must not already exist]],
  78. }
  79.  
  80. -- Filter pages if query is provided
  81. local pages = {}
  82. if query then
  83. query = string.lower(query)
  84. for _, page in ipairs(allPages) do
  85. if string.find(string.lower(page), query, 1, true) then
  86. table.insert(pages, page)
  87. end
  88. end
  89.  
  90. if #pages == 0 then
  91. term.clear()
  92. term.setCursorPos(1,1)
  93. print("No help pages found for: "..query)
  94. print()
  95. print("Press any key to exit...")
  96. os.pullEvent("key")
  97. return
  98. end
  99. else
  100. pages = allPages
  101. end
  102.  
  103. local oldBg = term.getBackgroundColour()
  104. local oldFg = term.getTextColour()
  105. local w,h = term.getSize()
  106. local currentPage = 1
  107. local totalPages = #pages
  108.  
  109. local function restore()
  110. term.setBackgroundColour(oldBg)
  111. term.setTextColour(oldFg)
  112. term.clear()
  113. term.setCursorPos(1,1)
  114. end
  115.  
  116. local function drawPage(pageNum)
  117. term.clear()
  118. term.setCursorPos(1,1)
  119.  
  120. for line in pages[pageNum]:gmatch("[^\n]+") do
  121. local trimmed = line:match("^%s*(.-)%s*$") -- trim spaces
  122. if trimmed:sub(1,2) == "--" then
  123. term.setTextColour(colours.green) -- comment
  124. elseif trimmed:sub(1,1) == "*" then
  125. term.setTextColour(colours.red) -- warning
  126. elseif trimmed:sub(1,1) == "|" then
  127. term.setTextColour(colours.yellow) -- command
  128. elseif trimmed:sub(1,1) == ">" then
  129. term.setTextColour(colours.white) -- subtitle
  130. else
  131. term.setTextColour(colours.blue) -- default body
  132. end
  133. print(line:sub(1, w))
  134. end
  135.  
  136. -- Footer instructions
  137. term.setTextColour(colours.lightGrey)
  138. term.setCursorPos(1, h - 1)
  139. local footer = "[ < ] Page " .. pageNum .. "/" .. totalPages .. " [ > ]"
  140. term.write(footer:sub(1, w))
  141. term.setCursorPos(1, h)
  142. term.write("Press [ backspace ] to exit")
  143. end
  144.  
  145. drawPage(currentPage)
  146.  
  147. while true do
  148. local event, key = os.pullEvent("key")
  149. if key == keys.right then
  150. if currentPage < totalPages then
  151. currentPage = currentPage + 1
  152. drawPage(currentPage)
  153. end
  154. elseif key == keys.left then
  155. if currentPage > 1 then
  156. currentPage = currentPage - 1
  157. drawPage(currentPage)
  158. end
  159. elseif key == keys.backspace then
  160. break
  161. end
  162. end
  163.  
  164. restore()
  165. end
Advertisement
Add Comment
Please, Sign In to add comment