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:

┌─────────────────────────────┐
│ cli-expander │
├─────────────────────────────┤
│ Tab next | / search ... │
│ ───────────────────────── │
│ 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
/Open search dialog (when choice/list field focused)

Form Help Bar

Every form shows a help bar at the top:

Tab next | / search dropdown | Enter select | Esc cancel

This reminds you of the available controls while filling out the form.

Hierarchical Sections

Forms can be organized into sections by adding non-field lines in the layout text. Any line that does not contain a [[field]] placeholder is treated as a section heading.

params:
layout: |
Find Smart

Scope
- Path: [[path]]

Search Criteria
- Use case: [[usecase]]
- Preset: [[preset]]
- Extra predicate: [[extra]]

Output Action
- Action: [[action]]

The form renders with blank separators between sections:

Find Smart
────────────────────────────────────
Tab next | / search dropdown | Enter select | Esc cancel
-----------------------------------------------

Scope
- Path:
[value widget]

Search Criteria
- Use case:
[value widget]
- Preset:
[value widget]
- Extra predicate:
[value widget]

Output Action
- Action:
[value widget]

Each field label is cleaned of leading/trailing box-art characters and formatted with a - Label: prefix. Field value widgets are indented underneath their labels with 3 spaces.

Searchable Dropdowns

Choice and list fields can be filtered by pressing / when focused. This opens a dialog with a live search input:

Search: Preset
─────────────────
Query: log

3 matches
- -type f -name '*.log'
- -type f -name '*.log.*'
- -type f -path '*/logs/*'

Enter select | Esc close

The search is case-insensitive and matches by substring. When the query field is blank, all options are shown. If no options match, "No matches" is displayed. Selecting a result or pressing Esc returns to the form with the selection applied or unchanged.

What's Next

Learn about the different Form Field Types you can use.