charmbracelet / freeze

Generate images of code and terminal output 📸
MIT License
2.98k stars 50 forks source link

User config file generated from interactive mode contains an incorrect field for line numbers #115

Open rezarajan opened 3 weeks ago

rezarajan commented 3 weeks ago

Describe the bug When the user.json file is generated from the interactive mode --interactive the field for line numbers is named line_numbers, and is set to false by default. However, this field should be named show_line_numbers as that is what is parsed by the utility.

To Reproduce Overview: Complete the interactive form on a test file to generate a default user.json config file. Modify the line_numbers field of this config file, and observe the changes in the output.

  1. Create a test file to freeze

    echo '{"test": true}' > testfile.json
  2. Freeze the file using interactive mode, naming the file testfile_default.png. Keep this file for comparison.

    # Select the testfile.json, and name the output testfile_default.png
    # Keep defaults otherwise
    freeze --interactive
  3. Open the user.json config. There will be a line_numbers field in the output, which is set to false.

    # Output should read "false"
    cat ~/.config/freeze/user.json | jq '.line_numbers'

N.b. the default line_numbers field here is the problem, but we continue testing for completeness

  1. Change the line_numbers field value from false to true

    # Set the value to true and verify. Output should read "true"
    sed -i 's/"line_numbers":false/"line_numbers":true/' ~/.config/freeze/user.json \
    && jq '.line_numbers' ~/.config/freeze/user.json
  2. Freeze the test file again, using this user config, naming it testfile_line_numbers.png

    freeze -c user testfile.json --output testfile_line_numbers.png

    You will notice that the output file does not contain line numbers, although we changed the line_numbers value from false to true; it is no different than the testfile_default.png file.

  3. Rename the line_numbers field to show_line_numbers

    # Output should read "true"
    sed -i 's/"line_numbers"/"show_line_numbers"/g' ~/.config/freeze/user.json \
    ∙ && jq '.show_line_numbers' ~/.config/freeze/user.json
  4. Repeat step 5, naming the output testfile_show_line_numbers.png

    freeze -c user testfile.json --output testfile_show_line_numbers.png

    You will notice that the line numbers now show, as compared to the other outputs.

Expected behavior Changing the line_numbers field to true or false should result in line numbers being shown or hidden in the output, respectively. Alternatively, this field should be named show_line_numbers as is consistent with the command-line flag, and is what actually fixes the issue.

Screenshots __testfile_default.png__ testfile_default Default output after running interactive mode

testfile_line_numbers.png testfile_line_numbers Output after setting line_numbers to true

__testfile_show_line_numbers.png__ testfile_show_line_numbers Output after changing line_numbers to show_line_numbers

Desktop