Terminal API
term provides runtime/session helpers in addition to shell commands.
The built-in pkg package manager is a shell command (invoked through runCommand), not a dedicated term.* API method.
Reference
readLine()Blocks the running script until the user submits a line of text in the terminal input bar, then returns that text as a string. If the script is canceled while waiting, an error is raised.readLine(prompt: String)Printspromptinline (no newline) then blocks as above.readPassword()LikereadLine()but the input bar displays typed characters as*and the console echoes stars instead of the real text. Use for passwords and other sensitive input.readPassword(prompt: String)Printspromptinline then blocks with masked input.
Example:
local name = term.readLine("Enter your name: ")
local pass = term.readPassword("Password: ")
print("Hello, " .. name)
start()stop()reboot()handleInput(input)registerCommand(name, callback)Registers Lua command callback in shell.unregisterCommand(name)Removes a command from the shell (built-in or custom).hasCommand(name)Checks whether a command currently exists.wrapCommand(name, callback)Wraps an existing command with a callback. Wrapper signature:callback(args, next)wherenext(nextArgs)executes original behavior.getPreviousCommand()getNextCommand()setCurrentInput(input)runCommand(commandLine)isBusy()Returns whether scripts are currently executing.
Example:
term.runCommand("pkg search vector")
httpGet(url)HTTP GET helper (subject to server config/trusted domains).setPromptTemplate(template)Placeholders:{name},{display},{hostname},{dir}.getPromptTemplate()resetPromptTemplate()setAutoPrompt(enabled)isAutoPromptEnabled()getScrollMode()setScrollMode(mode)wheremodeis one ofNONE,HORIZONTAL,VERTICAL,BOTHisMaskedEnterForwardingEnabled()setMaskedEnterForwardingEnabled(enabled)
Wiring Commands To Game Logic
registerCommand callbacks run inside the same Lua environment as your script, so they can directly call:
peripheralto access nearby blocks/modulesnetfor messaging and coordinationfsfor persistence/configconsole/printfor operator feedback
Example: custom command that updates a display block and broadcasts a status event.
term.registerCommand("status", function(args)
local text = (args == nil or args == "") and "OK" or args
local block = peripheral.getSelf()
if block and block.isDisplayModule and block:isDisplayModule() then
block:setText("STATUS: " .. text)
end
net.sendComputer("status", text)
print("status set:", text)
end)
Override/Wrap Patterns
Hard override:
term.registerCommand("reboot", function(args)
print("Reboot blocked by policy")
end)
Wrap existing command:
term.wrapCommand("rm", function(args, next)
print("AUDIT rm", args)
next(args)
end)
Remove command:
term.unregisterCommand("wget")