cmd/tailscale/cli, util/qrcodes: format QR codes on Linux consoles (#18182)

Raw Linux consoles support UTF-8, but we cannot assume that all UTF-8
characters are available. The default Fixed and Terminus fonts don’t
contain half-block characters (`▀` and `▄`), but do contain the
full-block character (`█`).

Sometimes, Linux doesn’t have a framebuffer, so it falls back to VGA.
When this happens, the full-block character could be anywhere in
extended ASCII block, because we don’t know which code page is active.

This PR introduces `--qr-format=auto` which tries to heuristically
detect when Tailscale is printing to a raw Linux console, whether
UTF-8 is enabled, and which block characters have been mapped in the
console font.

If Unicode characters are unavailable, the new `--qr-format=ascii`
formatter uses `#` characters instead of full-block characters.

Fixes #12935

Signed-off-by: Simon Law <sfllaw@tailscale.com>
This commit is contained in:
Simon Law
2026-01-07 18:12:06 -08:00
committed by GitHub
parent e66531041b
commit 522a6e385e
6 changed files with 259 additions and 20 deletions
+14
View File
@@ -0,0 +1,14 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
//go:build !linux
package qrcodes
import "io"
func detectFormat(w io.Writer, inverse bool) (Format, error) {
// Assume all terminals can support the full set of UTF-8 block
// characters: (█, ▀, ▄). See tailscale/tailscale#12935.
return FormatSmall, nil
}