Skip to content

Commit

Permalink
improve output
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 12, 2023
1 parent 8ede6b4 commit c5a1f7f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/listen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ export async function listen(

const urls = getURLs(showURLOptions);

const firstLocalUrl = urls.find((u) => u.type === "local");
const firstPublicUrl = urls.find((u) => u.type !== "local");

const typeMap: Record<ListenURL["type"], [string, ColorName]> = {
local: ["Local", "green"],
tunnel: ["Tunnel", "yellow"],
Expand All @@ -196,26 +199,25 @@ export async function listen(
const label = getColor(type[1])(
` ➜ ${(type[0] + ":").padEnd(8, " ")}${nameSuffix} `,
);
const suffix = url.type === "local" ? copiedToClipboardMessage : "";
const suffix = url === firstLocalUrl ? copiedToClipboardMessage : "";
lines.push(`${label} ${formatURL(url.url)} ${suffix}`);
}

if (!listhenOptions.public) {
if (!firstPublicUrl) {
lines.push(
colors.gray(` > Network: use ${colors.white("--host")} to expose`),
);
}

const firstPublic = urls.find((u) => u.type !== "local");
if (firstPublic && (showURLOptions.qr ?? listhenOptions.qr) !== false) {
if (firstPublicUrl && (showURLOptions.qr ?? listhenOptions.qr) !== false) {
const space = " ".repeat(15);
lines.push(" ");
lines.push(
...renderQRCode(String(firstPublic))
...renderQRCode(firstPublicUrl.url)
.split("\n")
.map((line) => space + line),
);
lines.push(space + formatURL(firstPublic.url));
lines.push(space + formatURL(firstPublicUrl.url));

Check warning on line 220 in src/listen.ts

View check run for this annotation

Codecov / codecov/patch

src/listen.ts#L213-L220

Added lines #L213 - L220 were not covered by tests
}

// eslint-disable-next-line no-console
Expand Down

0 comments on commit c5a1f7f

Please sign in to comment.