// Example mod: a small form in a pane, with a text input, a select, markdown, and a button. // // `input` and `select` elements only take keys while their pane has focus: `/standup` opens the // pane with focus (dialog-like), and Alt+↑ focuses the newest open pane from the prompt. While // focused, Tab walks the fields, ←/→ choose an option, Enter submits or picks, and Esc goes // back to the prompt. Typing never reaches a pane that does not have focus. // // The values live in cmd.state, so they survive a hot reload and setting one repaints the pane. import type {ModApi} from '@commandcode/harness'; const MOODS = [ {label: 'Great', value: 'great'}, {label: 'Okay', value: 'okay'}, {label: 'Blocked', value: 'blocked'}, ] as const; export default function (cmd: ModApi): void { const note = (): string => cmd.state.get('note') ?? ''; const mood = (): string => cmd.state.get('mood') ?? 'okay'; cmd.ui.pane({ id: 'standup', title: 'Standup', render: () => [ { type: 'markdown', text: '**Today**: one line, then pick how it is going.', }, { type: 'input', key: 'note', placeholder: 'what are you working on?', value: note(), onSubmit: text => cmd.state.set('note', text.trim()), }, { type: 'select', key: 'mood', options: MOODS, value: mood(), onSelect: value => cmd.state.set('mood', value), }, { type: 'button', label: 'Post', hotkey: 's', onPress: () => { if (!note()) { cmd.ui.toast('Type a note first', {level: 'warning'}); return; } cmd.ui.notify(`standup (${mood()}): ${note()}`); cmd.ui.closePane('standup'); }, }, ], }); // /standup opens the form with the keyboard in it. cmd.addCommand({ name: 'standup', description: 'Post a one-line standup from a form pane', handler: () => { cmd.ui.openPane('standup', {focus: true}); }, }); }