-
Notifications
You must be signed in to change notification settings - Fork 20
Description
Summary
When using custom templates with pear init, the template's default values for height and width parameters are being overridden by hardcoded fallback values (540 and 720) in the init command, preventing custom templates from setting their own GUI dimension defaults.
Steps to Reproduce
- Create a custom template with
_template.jsoncontaining:
{
"params": [
{
"name": "height",
"default": 1080,
"validation": "(value) => Number.isInteger(+value)",
"prompt": "height",
"msg": "must be an integer"
},
{
"name": "width",
"default": 800,
"validation": "(value) => Number.isInteger(+value)",
"prompt": "width",
"msg": "must be an integer"
}
]
}- Run
pear init /path/to/custom/template - Observe the prompted default values
Expected Behavior
The template's default values (1080 for height, 800 for width) should be used as the defaults in the prompts.
Actual Behavior
The hardcoded fallback values (540 for height, 720 for width) are used instead of the template defaults.
Example Output
height: (540) # Should show (1080)
width: (720) # Should show (800)
Root Cause
const height = cfg.gui ? cfg.gui.height : 540;
const width = cfg.gui ? cfg.gui.width : 720;These hardcoded values are passed as defaults to the init process, and in lib/interact.js line 50, the logic prioritizes passed defaults over template defaults:
const deflt = defaults[param.name] ?? param.default;Proposed Solution
The init command should only provide fallback defaults when no template defaults exist. Possible approaches:
- Load template first: Check the template's
_template.jsonfor existing defaults before setting fallback values - Conditional defaults: Only set fallback values for parameters that don't have template defaults
- Change precedence: Modify the interaction logic to prioritize template defaults over passed defaults
Environment
- Pear version: Latest
- OS: macOS 22.6.0
- Template type: Custom template with height/width defaults
Additional Context
This affects anyone creating custom templates who wants to set different default GUI dimensions than the built-in 540x720 values.
Current workaround: Remove the default values from the template's _template.json file (making it behave like the built-in desktop template), but this limits template customization capabilities.
The built-in desktop template works around this by not specifying defaults for height/width at all, relying entirely on the hardcoded fallbacks.
Written by Claude-4-sonnet, reviewed by me.