pager v1.0.0

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.

Installation

Recommended: Install via installer (handles dependencies automatically):

wget run https://raw.githubusercontent.com/Twijn/cc-misc/main/util/installer.lua pager
View on GitHub →

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:

wget https://raw.githubusercontent.com/Twijn/cc-misc/main/util/pager.lua

Examples

Using with Runtime Installation

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

Usage Examples

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()

Functions

pager.new(title?)

View source on GitHub

Create a new pager collector for building pageable output

Parameters:
Returns: PagerCollector

PagerCollector:setColor(color)

View source on GitHub

Set the current text color for subsequent writes

Parameters:

PagerCollector:write(text)

View source on GitHub

Write text without a newline (can be called multiple times per line)

Parameters:

PagerCollector:print(text?)

View source on GitHub

Print text with a newline (completes the current line)

Parameters:

PagerCollector:newline()

View source on GitHub

Add a blank line

PagerCollector:lineCount()

View source on GitHub

Get the number of lines collected

Returns: number

PagerCollector:needsPaging()

View source on GitHub

Check if paging is needed based on terminal height

Returns: boolean

PagerCollector:show()

View source on GitHub

Display the collected content with pagination if needed If content fits on screen, just prints it directly

pager.display(lines, title?)

View source on GitHub

Display a table of strings or pre-formatted lines with pagination This is a simpler interface for when you just have plain strings

Parameters:

pager.create(title?)

View source on GitHub

Create a pager that acts like term for easy integration Returns an object with print, write, setTextColor that collects output

Parameters:
Returns: table Pager object with terminal-like interface