Documentation
¶
Overview ¶
Package qr is a dependency-free QR code encoder.
It is a module-for-module port of the dashboard's ui/src/lib/qr.ts, so the daemon can print the same pairing code in a terminal that the pairing screen draws in the browser. Rule 4 is the reason it exists at all: the pairing URL carries a code that lets a device in, and it must not leave the machine to be drawn, so no image service and no third-party library.
Deliberately narrow, exactly as qr.ts is: byte mode, error correction level M, versions 1 to 10 (up to MaxBytes bytes of UTF-8). Keeping the two encoders identical, including the mask choice, means a code scanned from the terminal and one scanned from the screen are the same symbol, and testdata/vectors.json (generated from qr.ts) proves it.
Index ¶
Constants ¶
const MaxBytes = 213
MaxBytes is the longest UTF-8 input a version-10, level-M code in byte mode holds: 216 data codewords less 2.5 bytes of mode and length header.
Variables ¶
var ErrTooLong = errors.New("qr: text too long for a QR code here")
ErrTooLong is returned for input longer than MaxBytes.
Functions ¶
This section is empty.
Types ¶
type Code ¶
type Code struct {
// Size is the width and height in modules, without a quiet zone.
Size int
// contains filtered or unexported fields
}
Code is a square of modules.
func (*Code) Dark ¶
Dark reports whether the module at column x, row y is dark. Coordinates outside the symbol are light, which is what a quiet zone is.
func (*Code) Terminal ¶
Terminal renders the code with Unicode half blocks, two module rows per line, inside a quiet zone of quiet modules on every side (the standard asks for 4; a negative value is treated as 0).
The drawing is inverted on purpose: a dark module is a space and a light module is a block, as `qrencode -t utf8` does. A space takes the terminal's background and a block its foreground, and on the usual dark terminal that makes the light modules light and the dark modules dark, which is what a scanner needs. Drawing dark modules as blocks instead gives a negative code on a dark terminal, which many phone cameras refuse to read. On a light terminal (dark text on white) this drawing comes out as a negative; the common iOS and Android scanners read inverted codes, and the drawn quiet zone keeps the symbol framed either way. A rendering that is positive on every background would need ANSI colours, which not every output keeps.