Build a Live TUI App in Phosphor: A Beginner's Guide to the Layout Language

November 13, 2026

Want to build a text-mode app that shows live information and reacts to keys — without learning Java or a framework first? Phosphor doors let you do that with one small file of script code. This guide starts from zero and builds a real app: NetStats, a board monitor that shows who’s online, a news “tape”, a scrolling event log, a live filter box, and updates that arrive on their own.

Everything here was tested on the real runtime — the finished file lives in the repo at samples/netstats.phos, and automated tests open it, press its keys, and check the exact screen it draws. If a rule is stated below, the machine enforces it.

First, some words

  • TUI = text user interface. Instead of buttons and windows made of pixels, a TUI app is made of characters in a fixed grid — like old DOS programs or your terminal.
  • A door = an app on the BBS you launch from the Games menu (that name is a BBS tradition: the program is a “door” you walk through from the board).
  • A widget = one building block on screen: a box, a list, an input field, a progress bar. You place widgets on a screen, and the runtime draws them.
  • The layout language = the small script (a .phos file) where you describe what goes on screen and what happens when keys and events arrive.

The neat part: you describe what the screen looks like; the runtime figures out how to draw it, every time the screen changes. You never write drawing code.

What you’ll build

                                    NETSTATS
╭─ Who's online ─────────╮┌─ Board pulse ────────────────┐
│sysop — lobby           ││General · 42 posts            │
╰────────────────────────╯│Network · 17 posts            │
                          │███████████████████░░░░░░░░72%│
                          └──────────────────────────────┘
                          ┌─ Tape ──────────────────────────────────────────────
                          │PHOSPHOR 1.0 • TIER-4 SHIPPED • CP437 WIRE
                          └─────────────────────────────────────────────────────
┌─ Event log ──────┐
│0m  monitor opened│
└──────────────────┘
[]
             [F] filter  ·  [T] tick  ·  [J]/[K] scroll  ·  [Q]uit

That’s an actual frame the runtime drew — not a mock-up. Let’s build it piece by piece.

What you need

  • A running Phosphor server (the Server app, or a locally buildable copy of jterm-bbs).
  • A folder of door scripts, called PHOS_DIR (usually bbs/). Drop .phos files in there.
  • Any text editor. No compiler, no Java knowledge — the script file is the whole app.

Heads-up for later: doors are registered when the server starts. Adding a brand-new door file takes one restart at the very end of the process. Editing an existing file is picked up without one.

Step 1 — an empty door

Every Phosphor app starts the same way. Create a file called netstats.phos:

door "NetStats" {
    description = "Live board monitor."

    state {
        ticks = 0
    }

    layout {
    }

    on enter {
    }
}

Read it like a form with four sections:

  • door "NetStats" — your app’s name. It becomes a Games-menu entry.
  • state — variables your app remembers while someone is using it (ticks starts at 0).
  • layout — everything that gets drawn goes here.
  • on enter — code that runs when someone opens the door. (Code blocks like this are called handlers.)

Two rules the parser enforces from day one: layout only exists inside a door (or screen), and panel contents always go inside a content { } section — you’ll see that in Step 4.

Step 2 — draw a big title (the banner)

layout {
    banner id = "head" {
        text = "NETSTATS"
        fg = "bright_cyan"
        align = "center"
    }
}

Add that inside door { … } and you have your first widget:

  • id = "head" — a name you’ll use later to change this widget. Every widget you want to update needs an id.
  • fg means foreground color — the color of the letters. Sixteen standard colors are available (white, cyan, bright_cyan, green, …).
  • align = "center" centers the text on the line.

Save the file and your door shows a centered cyan NETSTATS heading. That’s the whole loop of this language: place a widget, give it an id, fill in a few settings.

Step 3 — boxes (regions)

Now a box with text inside:

region id = "who" {
    border = "rounded"
    title = "Who's online"
    fg = "cyan"
    width = 26
}

Regions are your boxes. The frame you see — ╭─╮ │ ╰─╯ — is the border; the style you pick decides which characters draw it. Choices: single, double, rounded, solid, or border = false for no box at all.

Four beginner-useful facts about boxes:

  1. title is written into the top edge of the box.
  2. If the box is too small for the title, the title silently disappears — a box needs room for the title plus a few extra characters, or it just draws the box without it. If your title vanishes, make the box wider.
  3. width = 26 makes the box exactly 26 characters wide.
  4. Unknown settings and misspelled colors don’t crash anything — the widget falls back to a sensible default. Typos won’t take your board down. (Do still fix them: the default may not be what you meant.)

How does text get into the box? Not here — from handlers, using update:

on enter {
    update("who", "sysop — lobby")
}

update("who", …) swaps the contents of the widget with id who. on enter runs the moment someone opens the door, so the box already has text when the screen first appears.

Step 4 — put things side by side (panels)

A panel holds several widgets and arranges them. direction = "row" means side by side; the default stacks them top to bottom:

panel {
    direction = "row"
    content {
        region id = "who" { … }
        panel {
            weight = 1
            content {
                region id = "pulse" { … }
                region id = "tape" { … }
            }
        }
    }
}

Three things to notice — panels are the part worth practicing:

  • Panels list their children inside content { }. This is easy to forget; without content the parser stops you with an error.
  • A row hands out widths in two passes. First pass: any child with a fixed width gets exactly that (our box: 26 characters). Second pass: everything else splits what’s left. weight = 1 says “I’ll share what remains.” With one weighted sibling, it gets all the leftover space — here, 80 minus 26 = 54 characters.
  • Panels nest. The inner panel sits in the right column and stacks Board pulse over Tape. Combine rows and nesting and you can lay out almost anything.

Plain-English summary of the width rules: fixed widths are reserved first, whatever is left is shared by weight, and if nothing is left, the last fixed-width child stretches to the edge.

Step 5 — lists, progress bars, and the tape

Inside the pulse region go three data widgets:

region id = "pulse" {
    border = "single"
    title = "Board pulse"
    fg = "green"
    list id = "boards" {
        fg = "green"
    }
    progress id = "disk" {
        width = 30
        value = 72
        total = 100
    }
}

region id = "tape" {
    border = "single"
    title = "Tape"
    fg = "bright_yellow"
    ticker id = "tape" {
        items = ["PHOSPHOR 1.0", "TIER-4 SHIPPED", "CP437 WIRE"]
    }
}
  • A list shows lines you add while the app runs. It starts empty.
  • A progress bar is the classic one: filled blocks █, empty blocks ░, and a percentage on the right. value / total control the fill.
  • A ticker shows its items joined with dots — PHOSPHOR 1.0 • TIER-4 SHIPPED • CP437 WIRE — on one line, like a news ticker at the bottom of a TV screen: if the line is too long for the space, it gets cut off at the edge. Two more ready-made widgets exist, card and stats (see the gallery sample at the end).

Step 6 — making things change (the one concept that matters most)

Here’s the most important thing to understand:

Everything in layout is fixed. The layout describes the shape of the screen; it does not do math or read variables. If you write text = "Hi ${user.name}" you will literally see the characters {user.name} on screen — the runtime doesn’t evaluate that.

All changes happen through four commands, called from handlers:

update("id", "text")     // replace what a widget shows
append("id", "text")     // add a line to a list (bottom)
prepend("id", "text")    // add a line to a list (top)
hide("id")               // make a widget vanish (show("id") brings it back)

So the pattern is always: draw once in layout, change through update/append in handlers. The who-box gets update("who", …); the boards-list gets append("boards", "General · 42 posts"); a log widget gets append too.

If a widget isn’t showing your change, learn the order of precedence: a list’s accumulated lines win, then the last update(…), then the text written in layout. Knowing that order saves an hour of confusion.

Step 7 — the filter box (and the one honest surprise)

Now something interactive:

input id = "query" {
    clear_on_enter = "true"
    on_submit {
        log_event("filter set: " + input_value)
    }
}
  • The user types; the widget keeps track of the text.
  • Enter runs on_submit, and the typed text is available as input_value.
  • clear_on_enter = "true" empties the field after Enter.
  • Escape clears the field without submitting.

To type in the box, the user first focuses it — our status bar hints at that with [F] filter, wired by:

on key 'F' { set_focus("query") }

And here’s the heads-up that will save you a confused hour: while the box is focused, it owns every keystroke. Including Q. Try to quit while the filter box has focus and you’ll get a Q typed into the box, not a quit. That’s not a bug — it’s how “typing” has to work — but it means you design the way out: our sample’s Q only works before you focus the box (Escape clears, and Enter submits and moves on). Once you’ve internalized “one thing owns the typing at a time,” input widgets are easy.

(Two extras: bind = "name" on the input stores the typed value in a variable for later handlers, and an on_change { } section runs on every keystroke — live-as-you-type updates for free.)

Step 8 — a log that scrolls by itself

region id = "audit" {
    border = "single"
    title = "Event log"
    fg = "white"
    max_height = 6
    list id = "events" {}
}

Give a region max_height = 6 and it becomes a viewport — a window onto a longer list, six lines tall. New lines appear at the bottom and push old ones out of view, like a chat window. scroll("audit", 1) and scroll("audit", -1) let the user look back and forth (wired to [J]/[K] on the status bar).

The helper our handlers use:

function log_event(text) {
    append("events", ticks + "m  " + text)
}

Functions exist in .phos scripts too — define one, call it from any handler.

Step 9 — updates with no keypresses at all

So far, everything happened because a key was pressed. Two ways to have things happen on their own:

A timer:

on every 30s {
    ticks = ticks + 1
    update("who", "sysop — lobby  (" + ticks + " ticks)")
}

Every 30 seconds the handler runs and — this is the magic part — the screen redraws by itself. No key needed. You can watch the tick counter climb while sitting still.

Board events:

on board_post board "General" {
    append("boards", "General · +1")
    log_event("post on General")
}

When anyone posts (or saves mail, sends chat…), your handler runs and the screen refreshes. Think of it like a subscription: “whenever this happens, run my code.” Name check: board_reply fires when a thread is created, board_post when a reply is posted — historical names, keep them straight when you pick.

You never poll, never wait, never block — handlers run one at a time whenever their trigger happens, and drawing follows automatically.

Step 10 — keys and quitting

Keys are handled in on key 'X' blocks — one per key:

on key 'T' {
    ticks = ticks + 1
    log_event("manual tick")
}
on key 'J' { scroll("audit", 1) }
on key 'K' { scroll("audit", -1) }
on key 'Q' {
    say "See you."
    back()
}

say puts a message in the “message area” under your app, and back() exits the door. A status bar advertises your keys:

statusbar id = "status" {
    left = ""
    center = "[F] filter  ·  [T] tick  ·  [J]/[K] scroll  ·  [Q]uit"
}

The full finished file with everything wired together is samples/netstats.phos — read it top to bottom once you’ve walked through the steps above; it’s under 140 lines.

Step 11 — put it on your board

  1. Save the file as netstats.phos in your PHOS_DIR (usually bbs/).
  2. Add the door to your Games menu (a menu_items row under doors).
  3. Restart the board — door registration happens at boot.
  4. Log in, open Games, and NetStats is in the list.

There’s also an in-board editor with a live preview pane: edit the layout on one side, watch it render on the other, no restarts while you iterate.

Beginner cheat sheet

The four change commands (everything dynamic is one of these, called from a handler): update(id, text) · append(id, text) · prepend(id, text) · hide(id) / show(id)

Rules worth pinning to your monitor:

  • Layout is a snapshot; nothing in it computes. Changes happen only in handlers.
  • A box narrower than its title plus a few characters silently drops the title — widen the box.
  • Fixed widths are reserved first, the rest is split by weight; the last fixed child stretches if nothing is left.
  • Panel children go inside content { } — forgetting it is the most common first error.
  • A focused input owns every key, Q included; design your exits deliberately.
  • A max_height region is a viewport; new lines push old ones out (scroll with scroll(id, ±n)).
  • A declared timer redraws at fire time — live screens with no keypresses.
  • Typos in colors or settings degrade to defaults; they never crash the board. The parser’s errors only fire when the grammar is broken (a missing content, a missing bracket).

Where to go next:

Have fun — and if something doesn’t look right, it’s almost always one of the rules above, not the runtime.