Keep terminal pairing QR codes scannable (#2381)

* fix(pairing): keep terminal QR codes scannable

Prompt framing could wrap dense QR codes and alter long pairing links. Print pairing instructions directly, add the standard quiet zone, and suppress codes that cannot fit without auto-wrapping.

* fix(pairing): contain terminal QR background
This commit is contained in:
Mohamed Boudra
2026-07-24 18:47:23 +08:00
committed by GitHub
parent 609f81bc11
commit afcd972dd0
6 changed files with 119 additions and 47 deletions
+30
View File
@@ -0,0 +1,30 @@
import { describe, expect, it } from "vitest";
import { formatPairingInstructions } from "./pairing.js";
const QR = "\u001b[47m\u001b[30m \n ████ \n \u001b[0m";
const URL = "https://app.paseo.sh/#offer=pairing-offer";
describe("formatPairingInstructions", () => {
it("prints the QR and an unmodified pairing-link line when the terminal is wide enough", () => {
const output = formatPairingInstructions({ qr: QR, url: URL, columns: 7 });
expect(output).toContain(QR);
expect(output.split("\n")).toContain(URL);
});
it("does not print a QR that would reach the terminal edge", () => {
const output = formatPairingInstructions({ qr: QR, url: URL, columns: 6 });
expect(output).not.toContain(QR);
expect(output).toContain("Resize the terminal to at least 7 columns");
expect(output.split("\n")).toContain(URL);
});
it("does not risk printing a QR when terminal width is unknown", () => {
const output = formatPairingInstructions({ qr: QR, url: URL });
expect(output).not.toContain(QR);
expect(output).toContain("terminal width could not be detected");
expect(output.split("\n")).toContain(URL);
});
});