feat(instances): allow disabling prefixes in aliases and TUI
Release / release (push) Canceled after 0s

This commit is contained in:
Sebastian Unterschütz committed 2026-11-16 22:13:05 +01:00
1 parent d9060a6eb7
commit 3804c33669
12 files changed
+298 -19

No files matched your search

+37 -9
View File
@@ -63,14 +63,20 @@ type searchResultMsg struct {
// --- list item ---
type hostItem struct {
name string
id int
ip string
kind string
tags []string
label string // display only; name remains the canonical target
name string
id int
ip string
kind string
tags []string
}
func (h hostItem) Title() string { return h.name }
func (h hostItem) Title() string {
if h.label != "" {
return h.label
}
return h.name
}
func (h hostItem) Description() string { return fmt.Sprintf("%s [%s]", h.ip, h.kind) }
func (h hostItem) FilterValue() string { return h.name }
@@ -91,7 +97,7 @@ func (d compactDelegate) Render(w io.Writer, m list.Model, index int, item list.
if d.marked[h.key()] {
mark = "● "
}
line := fmt.Sprintf(" %s%s %s", mark, h.name, lipgloss.NewStyle().Foreground(lipgloss.Color("240")).Render(h.ip))
line := fmt.Sprintf(" %s%s %s", mark, h.Title(), lipgloss.NewStyle().Foreground(lipgloss.Color("240")).Render(h.ip))
if index == m.Index() {
line = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("86")).Render("> " + strings.TrimPrefix(line, " "))
}
@@ -181,7 +187,8 @@ type Model struct {
editMode bool // Ctrl+E on the selected item
forwardMode bool // Ctrl+T on the selected item
marked map[string]bool // hostItem.key() of hosts marked with space
markOrder []string // targets in the order they were marked
hostLabel func(string) string
markOrder []string // targets in the order they were marked
}
func New(client *netbox.Client, c *cache.Cache, defaultUser string, defaultPorts ...int) *Model {
@@ -678,12 +685,27 @@ func (m *Model) updateListItems(entries []netbox.HostEntry) {
f := parseFilter(m.filterInput.Value())
filtered := applyFilter(entries, f)
items := make([]list.Item, len(filtered))
labels := make([]string, len(filtered))
counts := make(map[string]int, len(filtered))
canonical := make(map[string]bool, len(filtered))
for i, e := range filtered {
labels[i] = e.Target()
canonical[strings.ToLower(e.Target())] = true
if m.hostLabel != nil {
labels[i] = m.hostLabel(e.Target())
}
counts[strings.ToLower(labels[i])]++
}
for i, e := range filtered {
ip := e.PrimaryIP4
if ip == "" {
ip = e.PrimaryIP6
}
items[i] = hostItem{id: e.ID, name: e.Target(), ip: ip, kind: e.Kind, tags: e.Tags}
label := labels[i]
if label != e.Target() && (counts[strings.ToLower(label)] > 1 || canonical[strings.ToLower(label)]) {
label = e.Target()
}
items[i] = hostItem{label: label, id: e.ID, name: e.Target(), ip: ip, kind: e.Kind, tags: e.Tags}
}
m.list.SetItems(items)
m.resizeList()
@@ -819,3 +841,9 @@ func parseForwards(input string, available []string) ([]string, error) {
}
return fields, nil
}
// SetHostLabel sets the display name formatter without changing host identity.
// Configure it before the program starts, just like SetNotes and SetForwards.
func (m *Model) SetHostLabel(format func(string) string) {
m.hostLabel = format
}