[ANN] QRCode.jl: Create QR Code within Julia

That’s the idea - wrap it in a struct and override Base.show. Though there’s an attractive simplicity in just returning a BitArray :slight_smile:

If you do want to go with a wrapper type you might use QRCode though you’d have to rename your package to QRCodes.jl (module name pluralization is an ecosystem convention to deal with this, eg Colors.Color, Dates.Date, Rotations.Rotation etc etc)

If you made a wrapper, what interface would you want it to conform to other than having a nice default show method? Eg, is it a graphical object, an AbstractMatrix or something else entirely? Perhaps best to keep it simple:

struct QRCode
    data::BitMatrix
    # Add more things here, eg the code version,
    # original source data string, etc
end

function Base.show(io::IO, code::QRCode)
    # You can include the original text in a header line too if it's part of QRCode
    # Minimal ANSI color text representation:
    for i=1:size(code.data,1)
        println(io, join([code.data[i,j] ? "\e[30m██" : "\e[97m██" for j=1:size(code.data,2)]))
    end
end

# possibly also `show(io::IO, ::MIME"text/html", qrc::QRCode)` for IJulia and the like?
1 Like