From 4d9749bf7cd4d6e00b6414d870e0aa188e2f0027 Mon Sep 17 00:00:00 2001 From: Kien La Date: Tue, 10 Sep 2024 19:01:54 -0400 Subject: [PATCH] short port text --- src/app_list.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/app_list.ts b/src/app_list.ts index 591e1e4..bd80499 100644 --- a/src/app_list.ts +++ b/src/app_list.ts @@ -12,6 +12,23 @@ function name(app: App, container: Container) { return app.name } +function shortenPorts(ports: string): string { + return ports + .replace(/0\.0\.0\.0/g, '') + .replace(/\/tcp/g, '') + .split(', ') + .map(port => { + const [local, container] = port.split('->') + if (container) { + const localPort = local.replace(/^:/, '') + const containerPort = container.replace(/^:/, '') + return localPort === containerPort ? localPort : `${localPort}->${containerPort}` + } + return port.replace(/^:/, '') + }) + .join(', ') +} + export default function list(apps: App[]) { const table = new Table({ head: ['', 'App', 'Status', 'Uptime', 'Port(s)', 'Source'], @@ -31,12 +48,17 @@ export default function list(apps: App[]) { table.push([ icons[app.state], app.name, '', '', '', source ]) app.containers.forEach((container) => { + const originalPorts = container.attributes.Ports + const shortenedPorts = shortenPorts(originalPorts) + console.log('Original ports:', originalPorts) + console.log('Shortened ports:', shortenedPorts) + table.push([ icons[container.state] || icons.unknown, name(app, container), container.state, container.uptime, - container.attributes.Ports, + shortenedPorts, app.containers.length == 1 ? source : '', ]) })