The UI helpers inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/PrinceOfCookies/CookieOS/llms.txt
Use this file to discover all available pages before exploring further.
cosUtils cover everything needed to build a polished CookieOS interface: clearing and resetting windows, drawing bordered boxes with CC:Tweaked box-drawing characters, printing centered text, rendering boxed menus with optional slow-print animation, displaying the top menu bar, animated loading bars, the blue-screen-of-death error display, safe function execution, color interpolation, monitor slow-print, flashing text, and a full touch-driven on-screen keyboard for attached monitors.
cosUtils.resetScreen(win)
Clears the given window, moves the cursor to position(1, 1), and resets colours to white text on a black background. Call this before drawing any new screen to ensure a clean slate.
A CC:Tweaked window object or
term (the main terminal).cosUtils.drawBox(win, x, y, width, height, fgColor, bgColor)
Draws a bordered rectangle using CC:Tweaked box-drawing characters. The box has a top border, bottom border, and left/right vertical bars. The top-right corner uses a colour-swap trick to achieve a two-tone shadow effect.The window or terminal to draw on.
Left edge of the inner content area (the box border is drawn one column to the left).
Top edge of the inner content area (the box border is drawn one row above).
Width of the inner content area in characters.
Height of the inner content area in rows.
Foreground (border line) colour. Defaults to
colors.white.Background colour inside the box. Defaults to
colors.black.cosUtils.centerPrint(yPos, w, text, col, win)
Prints a string centred horizontally at a specified row. The horizontal position is computed asfloor((w - #text) / 2).
The row at which to print the text.
The width of the screen or window (used for centring calculation).
The string to print.
Background colour for the printed text. Defaults to
colors.black.The window to print to. Defaults to
term.cosUtils.centerPrintTable(y, w, items, numOp, slowPrint, backgroundColor, boxmargins, window, textColors)
Draws a centred, boxed menu from a table of strings. The function calculates the longest line to determine box dimensions, draws the outer box viacosUtils.drawBox(), then prints each item centred inside. Per-item text colours are supported via textColors.
The starting row of the box.
Screen or window width, used for horizontal centring.
Ordered table of strings. Empty strings
"" act as blank spacer rows.Index of the currently selected item. The caller is responsible for highlighting the selected entry (e.g. by wrapping the text in brackets before passing to this function).
If
true, each item is written with textutils.slowWrite at speed 9 for a typewriter effect.Background colour applied to all menu items.
If
true, adds 4-character horizontal padding and 2-row vertical padding around the menu items inside the box.The window to draw on.
Optional table of
colors.* values indexed by item position. Items without an entry default to colors.white.cosUtils.drawMenu(device)
Draws the CookieOS top bar: the version string (cosv) in yellow on the left and the current time in HH:MM AM/PM format on the right. Rendering is done into an internal off-screen drawMenuWin window and then made visible in a single step, preventing flicker. The bar always occupies row 1 and spans the full terminal width.
Accepted for convention — the function uses the internal
drawMenuWin window regardless of the value passed. Pass term as the conventional argument.cosUtils.menuKeyUpDownManagement(key, num, max, min)
Handles Up/Down arrow-key navigation for menus with wrap-around at both ends. Pass the rawkey value from os.pullEvent("key") and the current selected index; the function returns the updated index.
The key code received from
os.pullEvent("key"). The function checks for keys.up and keys.down.The current selected index.
The maximum valid index. When
num == max and Down is pressed, wraps to min.The minimum valid index. When
num == min and Up is pressed, wraps to max.number.
cosUtils.loadingBar(device, y, col)
Draws an animated loading bar that fills from right to left across 10 characters. The total animation duration is proportional tocosUtils.fileCount(""), so the bar takes longer on computers with more files — visually reflecting the OS boot workload. A percentage counter is shown in the centre of the bar as it animates.
The terminal or window to draw on.
device.getSize() is called to centre the bar.The vertical row at which the bar is rendered.
The fill colour of the loading bar.
cosUtils.BSOD(err, device)
Displays a blue screen of death. The error message is uppercased and spaces are replaced with underscores. Five random memory addresses (via the module-localRMA() function) are generated for the STOP: technical information line. After the user presses any key, the error is logged to OS.log via cosUtils.logToOS() and the computer reboots.
The error message to display. Will be transformed to
UPPER_SNAKE_CASE on screen.The terminal to draw the blue screen on.
cosUtils.safeRun(func, …)
Wraps a function call inpcall. If the function throws an error, cosUtils.BSOD(err, term) is called automatically. This is the recommended way to run top-level program logic in CookieOS applications.
Returns status (boolean), err (string | nil).
The function to execute inside
pcall.Any additional arguments are forwarded to
func.cosUtils.waterMark(win)
Prints thecosv global (the CookieOS version string) in yellow on the given window, then resets the text colour to white.
The window to print the watermark on. Defaults to
term.cosUtils.goodByeSetup(device)
Centres the cursor on the screen and resets colours to white-on-black. Called internally by the overriddenos.reboot() and os.shutdown() before printing “Goodbye”. You can call it directly before any graceful exit.
The terminal whose size is used to compute the centre position.
cosUtils.colorLerp(startColor, endColor, speed)
Linearly interpolates between two RGB colour tables. Thespeed value is clamped to 1.0 so the result never overshoots endColor.
An
{r, g, b} table where each component is in your chosen range (e.g. 0–255).Target
{r, g, b} table.Interpolation factor from
0.0 (fully at startColor) to 1.0 (fully at endColor). Values above 1.0 are clamped to 1.0.{r, g, b} table.
cosUtils.monSlowPrint(txt, delay)
Writes a string to an attached monitor peripheral one character at a time, pausingdelay seconds between each character. Errors with assert if no monitor is found.
The text to print character by character.
Seconds to wait between each character. Defaults to
0.3.cosUtils.textFlash(x, y, text, delay)
Repeatedly writestext at position (x, y) and then clears it, creating a blinking effect. If a monitor is attached, it flashes on the monitor; otherwise it flashes on term. The function runs an infinite loop and should be executed inside a coroutine or via parallel.waitForAny.
Horizontal cursor position for the text.
Vertical cursor position for the text.
The string to flash.
Seconds between write and clear operations. Defaults to
0.3.cosUtils.onScreenKeyboard()
Displays a colour-coded QWERTY keyboard layout on an attached monitor. The user interacts with it viamonitor_touch events. The keyboard supports Shift (toggles case for all keys), Backspace (deletes the last character), Space, and Enter (finishes input and exits the loop). Each key is rendered with a random foreground/background colour pair for a distinctive look.
Returns the typed string when Enter is pressed.
This function requires a monitor peripheral. It calls
assert and errors if none is found.