Skip to content

Commit

Permalink
short port text
Browse files Browse the repository at this point in the history
  • Loading branch information
kla committed Sep 10, 2024
1 parent 910c49f commit 4d9749b
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/app_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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 : '',
])
})
Expand Down

0 comments on commit 4d9749b

Please sign in to comment.