Documentation
¶
Overview ¶
Package qrutil provides utilities for generating QR code images and terminal-printable QR codes from arbitrary string content such as URLs, pairing codes, or any text that needs to be shared visually.
This package wraps github.com/skip2/go-qrcode and provides convenience functions for common operations like saving a QR code as a PNG file and rendering a QR code as Unicode block characters for terminal display.
Without this package, each consumer (WhatsApp pairing, sharing links, etc.) would need to duplicate QR generation logic and handle error cases independently.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GeneratePNG ¶
GeneratePNG writes a QR code PNG image for the given content to the specified directory. The file is named "qr-code.png". Returns the full path to the written file, or an error if generation fails.
This function exists so that callers can provide a scannable QR image to end users, especially when the terminal does not render Unicode QR codes reliably.
func PrintToTerminal ¶
PrintToTerminal prints a QR code to stdout with a header box, the Unicode QR image, the saved file path, and an optional instruction message.
Parameters:
- content: the string to encode as a QR code
- dir: directory where the PNG image will be saved
- header: text displayed in the box above the QR code (e.g. "Scan this QR code with WhatsApp")
- instruction: text displayed below the QR code (e.g. "Open WhatsApp → Settings → ...")
This function exists to provide a consistent, polished QR code presentation across different features that need to show QR codes to the user.
func ToTerminalString ¶
ToTerminalString returns a compact Unicode block-character representation of the QR code suitable for printing to a terminal. The result uses half-block characters (▀▄█) that render as a scannable QR code in most modern terminal emulators. Returns the raw content string as a fallback if QR generation fails.
This function exists so that QR codes can be displayed inline in the terminal without requiring the user to open a separate image file.
Types ¶
This section is empty.