Skip to content

Commit

Permalink
refactor: show qr code above listening urls (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Aug 27, 2023
1 parent 9bc3135 commit e47d221
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/listen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,18 @@ export async function listen(
const firstLocalUrl = urls.find((u) => u.type === "local");
const firstPublicUrl = urls.find((u) => u.type !== "local");

// QR Code
const showQR = (showURLOptions.qr ?? listhenOptions.qr) !== false;
if (firstPublicUrl && showQR) {
const space = " ".repeat(14);
lines.push(" ");
lines.push(
...renderQRCode(firstPublicUrl.url)
.split("\n")
.map((line) => space + line),
);
lines.push(" ");
}

const typeMap: Record<ListenURL["type"], [string, ColorName]> = {
local: ["Local", "green"],
Expand Down Expand Up @@ -241,18 +252,7 @@ export async function listen(
);
}

// Show QR code
if (firstPublicUrl && showQR) {
const space = " ".repeat(14);
lines.push(" ");
lines.push(
...renderQRCode(firstPublicUrl.url)
.split("\n")
.map((line) => space + line),
);
}

// eslint-disable-next-line no-console
// Print lines
console.log("\n" + lines.join("\n") + "\n");
};

Expand Down

0 comments on commit e47d221

Please sign in to comment.