From c5a1f7f28b116da996d90571783fab8864efd58a Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 13 Aug 2023 00:01:18 +0200 Subject: [PATCH] improve output --- src/listen.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/listen.ts b/src/listen.ts index f77c80e..434f5e6 100644 --- a/src/listen.ts +++ b/src/listen.ts @@ -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 = { local: ["Local", "green"], tunnel: ["Tunnel", "yellow"], @@ -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)); } // eslint-disable-next-line no-console