-
Notifications
You must be signed in to change notification settings - Fork 0
Prompt Bar
The prompt bar at the bottom of the screen displays your MUD's prompt with colors preserved. Drag the separator line above the prompt bar to resize it vertically. MDW includes a trigger (MDW_PromptCapture) that automatically captures prompts. A game package can also declare a row of gauges above the prompt text and a settings button at the bar's right edge (below).
-- Capture the current prompt and display it in the prompt bar (call from a trigger)
mdw.capturePrompt() -- Capture, display in bar, delete from main window
mdw.capturePrompt(false) -- Same, but keep the line in the main window
mdw.capturePrompt(true, 2) -- Capture 2 lines (delete from main); see multi-line below
-- Set prompt bar text directly
mdw.setPrompt("<255,200,100>HP: 100") -- decho format (RGB)
mdw.setPromptCecho("<green>HP: <white>100") -- cecho format (named colors)
-- Clear the prompt bar
mdw.clearPrompt()mdw.capturePrompt(deleteFromMain, lineCount) - deleteFromMain defaults to true; lineCount defaults to mdw.config.promptLineCount. Background colors are stripped so the bar's own background shows through.
Mudlet's prompt trigger only fires on the final (GA) line of a prompt, so by default MDW captures just that one line. If your prompt spans multiple lines, use one of these config options:
-
promptPattern(recommended, no GMCP needed): a Lua pattern matching the upper line(s) of your prompt. When set, MDW captures lines above the GA line only while they match the pattern, so another game's single-line prompt or a disabled extra line is never swallowed.mdw = mdw or {} mdw.gameConfig = mdw.gameConfig or {} mdw.gameConfig.promptPattern = "^HP:"
-
promptLineCount: a blind fallback used only whenpromptPatternis nil. A value greater than 1 always grabs that many lines and can swallow a line above a shorter prompt, so preferpromptPatternunless your prompt is always exactly that many lines.mdw = mdw or {} mdw.gameConfig = mdw.gameConfig or {} mdw.gameConfig.promptLineCount = 2
If the default trigger doesn't suit your MUD, drive the prompt bar yourself. Disable MDW's built-in trigger with usePromptTrigger:
mdw = mdw or {}
mdw.gameConfig = mdw.gameConfig or {}
mdw.gameConfig.usePromptTrigger = falseThen either:
- Create your own trigger matching your MUD's prompt and call
mdw.capturePrompt()from it, or - Set the bar directly from a script with
mdw.setPrompt()/mdw.setPromptCecho().
usePromptTrigger is applied at setup and whenever you change it through mdw.configure().
You can also build a custom prompt from GMCP data:
-- In a script handling gmcp.Char.Vitals event
local v = gmcp.Char.Vitals
mdw.setPromptCecho(string.format(
"<green>HP:<white>%d/%d <blue>MP:<white>%d/%d",
v.health, v.health_max, v.mana, v.mana_max
))A game package can declare a row of real Geyser gauges (HP, mana, balance, whatever fits the game) rendered above the prompt text. MDW owns their geometry and lifecycle - equal widths capped at promptGaugeMaxWidth, relaid on every resize, cleaned up on teardown - while your package owns styles and values. Declare the row inside your onReady function so it is re-registered on every rebuild, exactly like widgets:
mdw.onReady["MyGame"] = function()
mdw.setPromptGauges({
{ id = "hp",
front = "background-color: rgba(60,160,80,60%); border-radius: 4px;",
back = "background-color: rgba(40,130,55,20%); border: 1px solid #333; border-radius: 4px;",
fgColor = "#dddddd", fontSize = 8 },
{ id = "mana", front = "...", back = "..." },
})
endEach entry is { id, front, back, text, fgColor, fontSize } where front, back, and text are Qt stylesheets for the fill, track, and label. Then feed it from your GMCP handlers - both calls are safe at any time, including while MDW rebuilds (a gauge that is not up is silently skipped):
mdw.setPromptGaugeValue("hp", vitals.hp, vitals.maxhp, "HP " .. vitals.hp)
mdw.setPromptGaugeStyle("hp", lowHpFillCss) -- e.g. color bands; nil keeps a partA call that changes nothing the gauge already shows - the same value, maximum and label, or the same stylesheets - is skipped, so feeding both from every payload costs nothing between changes.
mdw.setPromptGauges(nil) removes the row (call it from your package's uninstall handler). The declaration survives teardown the way onReady does, so a rebuild restores the row before your package re-declares it. Related options: promptGaugeHeight, promptGaugeGap, promptGaugeRowGap, promptGaugeMaxWidth in Configuration.
mdw.setPromptBarMenu(items, title) puts a vertical-ellipsis button at the bar's right edge that opens a context menu; pass a function as items for live checkbox states. The bar reserves a column for the button so the gauge row and the prompt text stop short of it. nil removes it; like the gauge row, the declaration survives rebuilds.
The player drags the separator; two calls let a package manage the height from content:
mdw.ensurePromptBarHeight(lines) -- grow, if needed, to fit `lines` prompt lines (default 1)
-- plus any gauge row; never shrinks a taller bar
mdw.fitPromptBarHeight(lines) -- size the bar to EXACTLY fit `lines` lines plus any gauge
-- row, shrinking as readily as growing; 0 lines with a
-- gauge row collapses the bar around the gaugesfitPromptBarHeight is the web-client model of a content-driven bar - call it when a settings toggle changes what the bar shows. The splitter still lets the player re-adjust by hand afterwards, and the gauge row raises the drag's floor so the prompt text can't be squeezed out.