A dynamic form user interface library for ComputerCraft that provides interactive forms with various field types, validation, and peripheral detection. Features: Text and number input fields, select dropdowns and peripheral selection, checkbox/toggle fields, multi-select dropdowns, list fields with item management, built-in validation system, labels and buttons, real-time peripheral detection, keyboard navigation with arrow keys, and form submission and cancellation.
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 = {"formui"} -- 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 formui = require(libDir .. "formui")
-- 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 = {"formui"} -- 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 formui = require(libDir .. "formui")
-- Use the library
local FormUI = require("formui")
local form = FormUI.new("Configuration")
local nameField = form:text("Name", "default")
local portField = form:number("Port", 8080)
local modemField = form:peripheral("Modem", "modem")
local enabledField = form:checkbox("Enabled", true)
local featuresField = form:multiselect("Features", {"feature1", "feature2", "feature3"})
local itemsField = form:list("Items", {"item1", "item2"}, "string")
form:addSubmitCancel()
local result = form:run()
if result then
print("Name:", nameField())
print("Port:", portField())
print("Enabled:", enabledField())
print("Features:", table.concat(featuresField(), ", "))
end
FormUI.new(title?)Create a new FormUI instance
title? (string): The form title (defaults to "Form")FormUI:addField(field)Add a field to the form and return a getter function
field (FormField): The field definition to addFormUI:text(label, default?, validator?)Add a text input field
label (string): The field labeldefault? (string): Default valuevalidator? (ValidationFunction): Custom validation functionFormUI:number(label, default?, validator?)Add a number input field
label (string): The field labeldefault? (number): Default valuevalidator? (ValidationFunction): Custom validation functionFormUI:select(label, options?, defaultIndex?, validator?)Add a select dropdown field
label (string): The field labeloptions? (string[]): Available optionsdefaultIndex? (number): Index of default selection (1-based)validator? (ValidationFunction): Custom validation functionFormUI:peripheral(label, filterType?, validator?, defaultValue?)Add a peripheral selector field that automatically detects peripherals
label (string): The field labelfilterType? (string): Peripheral type to filter by (e.g., "modem", "monitor")validator? (ValidationFunction): Custom validation functiondefaultValue? (string|number): Default peripheral (name or index)FormUI:label(text)Add a non-interactive label for display purposes
text (string): The label text to displayFormUI:button(text, action?)Add a button that can trigger actions
text (string): The button textaction? (string): Action identifier (defaults to lowercase text)FormUI:checkbox(label, default?)Add a checkbox/toggle field
label (string): The field labeldefault? (boolean): Default value (true/false)FormUI:multiselect(label, options, defaultIndices?)Add a multi-select dropdown field
label (string): The field labeloptions (string[]): Available optionsdefaultIndices? (number[]): Indices of default selections (1-based)FormUI:list(label, default?, itemType?)Add a list field (string or number list, with item reordering)
label (string): The field labeldefault? (table): Default list valueitemType? (string): "string" or "number"FormUI:validateField(i)Validate a specific field by index
i (number): The field index to validateFormUI:isValid()Validate all fields in the form
FormUI:get(label)Get the current value of a field by label
label (string): The field labelFormUI:setValue(label, value)Set the value of a field by label
label (string): The field labelvalue (any): The new value to setFormUI:edit(index)Edit a field at the specified index
index (number): The field index to editFormUI:nextSelectableField(from)Find the next selectable field index (skips labels)
from (number): Starting field indexFormUI:prevSelectableField(from)Find the previous selectable field index (skips labels)
from (number): Starting field indexFormUI:run()Run the form's main input loop