QR code encoder for MoonBit - port of dbuenzli/qrc
moon install bobzhang/qrc///|
test {
// Generate a QR code with default settings
let qr = @bobzhang/qrc.encode("Hello, MoonBit!")
// Print QR code information
println(@bobzhang/qrc/render.info(qr))
// Render as text
println(@bobzhang/qrc/render.to_text(qr))
// Render as compact text (using Unicode block characters)
println(@bobzhang/qrc/render.to_compact_text(qr))
// Render as SVG
let svg = @bobzhang/qrc/render.to_svg(qr)
println(svg)
// Render as ANSI terminal output (with colors)
println(@bobzhang/qrc/render.to_ansi(qr))
}///|
test {
// Generate QR code with specific error correction level
let qr = @qrc.encode_with_ec("Important data", H)
// Manual mode detection
let mode = @qrc.detect_mode("12345") // Returns Mode::Numeric
let mode2 = @qrc.detect_mode("HELLO WORLD") // Returns Mode::Alphanumeric
let mode3 = @qrc.detect_mode("Hello, World!")
// Returns Mode::Byte
}QR Code Information:
Version: 1
Size: 21x21
Mode: Byte
Error Correction: M (~15%)
Data: "Hello, MoonBit!"
Text representation:
██████████████ ████ ██████████████
██ ██ ████ ██ ██
██ ██████ ██ ████ ██ ██████ ██
██ ██████ ██ ████ ██ ██████ ██
██ ██████ ██ ████ ██ ██████ ██
██ ██ ████ ██ ██
██████████████ ████ ██████████████
████
████████████████████████████████████
...# Clone the repository
git clone <repository-url>
cd qrc
# Run tests
moon test
# Run the example
moon run srcpub enum MaskPattern {
Pattern0
Pattern1
Pattern2
Pattern3
Pattern4
Pattern5
Pattern6
Pattern7
} derive(Eq)pub struct QRCode {
version : Int
error_correction : ErrorCorrectionLevel
mode : Mode
data : String
matrix : Matrix
}fn apply_error_correction(data : Array[Int], mode : Mode, version : Int, ec_level : ErrorCorrectionLevel) -> Array[Int]fn encode_with_mode_and_ec(data : String, mode : Mode, version : Int, ec : ErrorCorrectionLevel) -> QRCodeQR code encoder for MoonBit - port of dbuenzli/qrc