Guide-Adding-New-Field-Types
Guide: Adding a New Field Type to the TUI
When extending the configuration schema, touch these layers in order so the new field stays coherent across pour-design-spec and the running app:
- Config Layer (
src/config.rs): Add the new variant to theFieldTypeenum. Updatevalidate()if the field requires specific properties, likestatic_selectrequiringoptions, or if a write mode can't hold it (updatemodules rejectcomposite_arrayand body-targeted fields). A few config writers turn the type back into a string fortoml_editwith exhaustive matches, so the compiler points you at each one. - State Layer (
src/app.rs): UpdateApp::init_form()to handle any default state population for the new field, andApp::validate_form()if it requires custom validation logic before submission. - Presentation Layer (
src/tui/form/render/): Add a match arm torender_fields()infields.rs. Decide whether it renders inline like text or needs an overlay like the select list (render_select_options) or the textarea popout (render_textarea_editor). The footer key hint for the focused field lives inrender/mod.rs. - Input Handling (
src/tui/form/key/):dispatch()inkey/mod.rsroutes each key by the active field's type. Character filtering for typed input is inkey/text.rs(handle_char), and select behavior is inkey/select.rs. - Output Layer (
src/output/):partition_fields()inoutput/mod.rsroutes the value tofrontmatterorbodythroughFieldConfig::effective_target(). Value formatting is inoutput/frontmatter.rs, andupdate-mode writes are inoutput/update.rs. - Configure Editor: Add the type's string to the type cycler in
build_field_settings()(src/tui/configure/init.rs) and to the string-to-enum match insrc/config_updates.rs. The compiler doesn't check these string lists, and the parse falls back totext, so skipping them makes auto-save quietly rewrite the new type astext. - Server and PWA: Add the wire name to
field_type_wire()insrc/server/dto/mapping.rs, value checks tosrc/server/handlers/submit/validate.rs, and a widget tobuildFieldInput()inweb/app.js. Without one, the PWA renders the field as a plain text input. - One-shot (
src/oneshot.rs): Only if the type should be writable aspour <module> <field> [value]. Today that coverstoggleandcounteronupdatemodules.
Tests go in tests/, mirroring src/ (see CONTRIBUTING.md). Document the type, its keys, and its validation rules in field-types.
For the current TUI shape and event routing, see System-Architecture-Overview.