Skip to content

Terminal text renderer

QRCodeTextRenderer returns a string with no trailing newline. It exposes only the dimensions a terminal can represent through QRCodeTextStyle; graphical colors, shapes, and finder or alignment styles are not accepted. Every dark module, including finder and alignment modules, prints as a dark cell.

import {QRCodeTextRenderer, qrcode} from '@qrcodesdk/core';
const text = qrcode('HELLO WORLD').render(
QRCodeTextRenderer({
style: {moduleSize: 1, quietZone: 2},
layout: 'compact',
ansi: true,
}),
);
Option Default Effect
style.moduleSize 5 Positive integer module scale
style.quietZone 4 Non-negative integer border in modules
layout 'compact' 'compact' packs two rows per line; 'full' uses two cells per module
ansi false true, false, or an ANSI options object
ansi.mode 'blocks' 'blocks' uses glyphs; 'background' uses colored spaces
ansi.foreground '#000000' RGB or RGBA hexadecimal dark color
ansi.background '#ffffff' RGB or RGBA hexadecimal light color

An ANSI object enables ANSI output. Background mode has fixed full-cell geometry, so its option type does not accept layout. The renderer does not inspect TTY state or NO_COLOR; callers such as the CLI choose that policy before creating it.

Terminals have no alpha channel. RGBA background colors are composited over white, then RGBA foreground colors are composited over that resolved background before 24-bit ANSI sequences are written. Alpha is therefore deterministic and never silently discarded.

For S = (matrix width + 2 × quietZone) × moduleSize, compact output is S cells wide and ceil(S / 2) lines high. Full and ANSI-background output are 2 × S cells wide and S lines high.

Renderer options are validated and copied at factory creation. Invalid dimensions and colors throw immediately. TypeScript rejects unknown keys and unsupported combinations; the renderer does not repeat those checks at runtime.

Support QRCodeSDK

If you find QRCodeSDK useful, please consider sponsoring the project!