charmbracelet / freeze

Generate images of code and terminal output 📸
MIT License
3.45k stars 61 forks source link

Random orange-ish rectangles #156

Open b1t-ninja opened 5 days ago

b1t-ninja commented 5 days ago

Describe the bug When I run freeze file.swift it produces an image which always contains at least one orange-red rectangle that appears in the first 3 lines of code.

Here's an example freeze

If the file is just 3 lines of code it works fine.

To Reproduce Steps to reproduce the behavior:

  1. Create .swift file and put

    typealias PartOne = @Sendable (String) -> Int
    @available(macOS 13.0, *)
    let partOne: PartOne = { x in
    let digitPattern = /\d+/ // -- 1
    
    return x.split(separator: "\n").reduce(0) { acc, curr in // -- 2
    let matches = curr.matches(of: digitPattern) // -- 3
    guard let first = Int(matches.first!.0) else { return acc } // -- 3
    
    return acc + first + (matches.count > 1 ? Int(matches.last!.0)! : 0) // -- 4
    }
    }

    inside

  2. run freeze file.swift
  3. Tada !

Expected behavior There should be an output image freeze.png

Desktop (please complete the following information):

bashbunni commented 4 days ago

I was able to reproduce this as well on master. I also tested the svg output (freeze file.swift -o freeze.svg) and it didn't have this issue (attached) swift 1

Will have to take a look at the png conversion under the hood. Thanks for reporting this and providing us with steps to repro!