Skip to content

Commit 0fe3935

Browse files
committed
simplify image name
1 parent a62f85e commit 0fe3935

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

internal/tui/model.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,14 @@ func (m *Model) moveContainerCursor(delta int) {
374374

375375
// simplifyImage strips registry/org prefixes, returning only the last path
376376
// segment (image name + tag). e.g. docker.io/library/postgres:16 → postgres:16
377+
// SHA digests are shortened to 12 hex chars: sha256:a1b2c3d4e5f6
377378
func simplifyImage(img string) string {
378379
parts := strings.Split(img, "/")
379-
return parts[len(parts)-1]
380+
last := parts[len(parts)-1]
381+
if after, ok := strings.CutPrefix(last, "sha256:"); ok && len(after) > 12 {
382+
return "sha256:" + after[:12]
383+
}
384+
return last
380385
}
381386

382387
// buildImageRows produces filtered image rows.

internal/tui/model_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ func TestRenderContainerSelectedRow_fillsModelWidth(t *testing.T) {
4545
assert.Equal(t, result.width, lipgloss.Width(line))
4646
}
4747

48+
func TestSimplifyImage(t *testing.T) {
49+
cases := []struct{ input, want string }{
50+
{"docker.io/library/postgres:16", "postgres:16"},
51+
{"nginx:latest", "nginx:latest"},
52+
{"nginx", "nginx"},
53+
{"<none>", "<none>"},
54+
{"gcr.io/google-containers/pause:3.1", "pause:3.1"},
55+
{"sha256:a1b2c3d4e5f6789012345678901234567890123456789012345678901234", "sha256:a1b2c3d4e5f6"},
56+
{"sha256:abc", "sha256:abc"},
57+
}
58+
for _, c := range cases {
59+
assert.Equal(t, c.want, simplifyImage(c.input), "input: %s", c.input)
60+
}
61+
}
62+
4863
func windowSize(width, height int) tea.WindowSizeMsg {
4964
return tea.WindowSizeMsg{Width: width, Height: height}
5065
}

0 commit comments

Comments
 (0)