Skip to content

Pear's 'init' command - hardcoded fallbacks override '_template.json' defaults for height and width. #747

@Acumen-Desktop

Description

@Acumen-Desktop

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

  1. Create a custom template with _template.json containing:
{
  "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"
    }
  ]
}
  1. Run pear init /path/to/custom/template
  2. 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

In cmd/init.js lines 28-29:

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:

  1. Load template first: Check the template's _template.json for existing defaults before setting fallback values
  2. Conditional defaults: Only set fallback values for parameters that don't have template defaults
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions