Skip to main content

Form Syntax

Forms are the signature feature of cli-expander. They collect user input before expansion — all rendered in your terminal via Cursive TUI.

How Forms Work

When a match has a form field instead of replace, cli-expander opens an interactive form dialog when the trigger is matched. The user fills in the fields and submits with Tab+Enter. The field values are then substituted into the form layout.

Shorthand Syntax

The simplest way to create a form uses inline [[field]] placeholders in the form field:

- trigger: ":greet"
form: |
Hello [[name]]!
You are [[age]] years old.
form_fields:
name:
placeholder: "Your name"
age:
placeholder: "Your age"

When expanded, the form shows:

┌─────────────────────────────┐
│ texpand │
├─────────────────────────────┤
│ Hello [[name]]! │
│ You are [[age]] years old. │
│ │
│ Your name: [____________] │
│ Your age: [____________] │
│ │
│ [Submit] [Cancel] │
└─────────────────────────────┘

Verbose Syntax

The verbose syntax uses vars to define the form as a variable. This enables variable chaining and shell integration.

- trigger: ":greet"
replace: "Hello {{form.name}}! You are {{form.age}}."
vars:
- name: form
type: form
params:
layout: |
Name: [[name]]
Age: [[age]]
fields:
name:
placeholder: "Enter name"
age:
type: choice
values:
- 18-25
- 26-35
- 36+

Field Configuration

Each field in form_fields can be configured with these options:

OptionTypeApplies toDescription
typestringalltext (default), choice, list, checkbox, password
multilinebooltextEnable multi-line input
defaultstringallPre-filled value
placeholderstringtext, passwordHint text when field is empty
valuesarray/mapchoice, listAvailable options (or depends map for cascades)
depends_onstringchoiceParent field name for cascading dropdowns

Form Controls

KeyAction
TabMove to next field
Shift+TabMove to previous field
EnterSubmit form (when Submit button focused)
EscCancel form
Arrow keysNavigate choice/list options

What's Next

Learn about the different Form Field Types you can use.