Pager utility for ComputerCraft that displays long output with pagination Similar to 'less' or 'more' on Unix systems. Allows scrolling through content that exceeds the terminal height. Features: Page-by-page navigation, line-by-line scrolling, search/skip to end, dynamic terminal size detection, works with both strings and tables of lines.
Recommended: Install via installer (handles dependencies automatically):
This pattern downloads and runs libraries at runtime, automatically installing any that are missing:
-- Auto-install and require libraries
local libs = {"pager"} -- Add more libraries as needed
local libDir = (fs.exists("disk") and "disk/lib/" or "/lib/")
local allExist = true
for _, lib in ipairs(libs) do
if not fs.exists(libDir .. lib .. ".lua") then
allExist = false
break
end
end
if not allExist then
shell.run("wget", "run", "https://raw.githubusercontent.com/Twijn/cc-misc/main/util/installer.lua", table.unpack(libs))
end
local pager = require(libDir .. "pager")
-- Use the library
-- (your code here)
Alternative: Direct download via wget:
This example shows how to download and use libraries with automatic installation:
-- Auto-install and require libraries
local libs = {"pager"} -- Add more libraries as needed
local libDir = (fs.exists("disk") and "disk/lib/" or "/lib/")
local allExist = true
for _, lib in ipairs(libs) do
if not fs.exists(libDir .. lib .. ".lua") then
allExist = false
break
end
end
if not allExist then
shell.run("wget", "run", "https://raw.githubusercontent.com/Twijn/cc-misc/main/util/installer.lua", table.unpack(libs))
end
local pager = require(libDir .. "pager")
-- Use the library
local pager = require("pager")
-- Display a table of lines
local lines = {"Line 1", "Line 2", ...}
pager.display(lines, "My Title")
-- Use the pager collector to build output
local p = pager.new("Results")
p:print("Some text")
p:write("partial ")
p:print("line")
p:setColor(colors.lime)
p:print("Green text")
p:show()
pager.new(title?)Create a new pager collector for building pageable output
title? (string): Optional title to show at the topPagerCollector:setColor(color)Set the current text color for subsequent writes
color (number): The color constant (e.g., colors.red)PagerCollector:write(text)Write text without a newline (can be called multiple times per line)
text (string): The text to writePagerCollector:print(text?)Print text with a newline (completes the current line)
text? (string): Optional text to print before the newlinePagerCollector:needsPaging()Check if paging is needed based on terminal height
PagerCollector:show()Display the collected content with pagination if needed If content fits on screen, just prints it directly
pager.display(lines, title?)Display a table of strings or pre-formatted lines with pagination This is a simpler interface for when you just have plain strings
lines (string[]): Array of strings to displaytitle? (string): Optional titlepager.create(title?)Create a pager that acts like term for easy integration Returns an object with print, write, setTextColor that collects output
title? (string): Optional title for the pager