Skip to content

Commit 927172c

Browse files
committed
Add hotkey to expand TXT records
1 parent f94d515 commit 927172c

3 files changed

Lines changed: 33 additions & 9 deletions

File tree

internal/display/dns.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
// RenderDNS returns a lipgloss-styled string for DNS records. nsResolutions
1313
// (optional) adds expanded IP/rDNS info under each NS host.
14-
func RenderDNS(records *dns.Records, nsResolutions []dnsutil.HostResolution) string {
14+
func RenderDNS(records *dns.Records, nsResolutions []dnsutil.HostResolution, txtExpanded bool) string {
1515
var b strings.Builder
1616

1717
b.WriteString(domainSectionTitle("DNS Records"))
@@ -97,16 +97,22 @@ func RenderDNS(records *dns.Records, nsResolutions []dnsutil.HostResolution) str
9797
b.WriteString("\n")
9898
b.WriteString(section("TXT"))
9999
for i, txt := range records.TXT {
100-
// Truncate long TXT records for display
101-
display := txt
102-
if len(display) > 60 {
103-
display = display[:57] + "..."
104-
}
105100
// Alternate shades so adjacent records are easy to tell apart.
106101
style := txtStyle
107102
if i%2 == 1 {
108103
style = txtStyleAlt
109104
}
105+
if txtExpanded {
106+
for _, line := range wrapText(txt, valueWidth()) {
107+
b.WriteString(row("", style.Render(line)))
108+
}
109+
continue
110+
}
111+
// Truncate long TXT records for display
112+
display := txt
113+
if len(display) > 60 {
114+
display = display[:57] + "..."
115+
}
110116
b.WriteString(row("", style.Render(display)))
111117
}
112118
}

internal/display/dns_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestRenderDNSNSResolution(t *testing.T) {
6565
{Host: "ns2.example.com", Err: "no such host"},
6666
}
6767

68-
out := RenderDNS(records, resolutions)
68+
out := RenderDNS(records, resolutions, false)
6969

7070
for _, want := range []string{"192.0.2.1", "a.example.com", "b.example.com", "no such host"} {
7171
if !strings.Contains(out, want) {
@@ -77,7 +77,7 @@ func TestRenderDNSNSResolution(t *testing.T) {
7777
func TestRenderDNSWithoutResolution(t *testing.T) {
7878
// Passing no resolutions renders the bare NS list (default behavior).
7979
records := &dns.Records{NS: []string{"ns1.example.com"}}
80-
out := RenderDNS(records, nil)
80+
out := RenderDNS(records, nil, false)
8181
if !strings.Contains(out, "ns1.example.com") {
8282
t.Errorf("RenderDNS output missing NS host\n%s", out)
8383
}

internal/display/interactive.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type Model struct {
8282
nsResolved []dnsutil.HostResolution
8383
nsExpanded bool
8484
nsResolving bool
85+
txtExpanded bool
8586
mailData *mail.Records
8687
mxResolved []dnsutil.HostResolution
8788
mxExpanded bool
@@ -328,6 +329,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
328329
}
329330
}
330331
case "x":
332+
if !m.isIP && m.active == tabDNS && m.dnsData != nil && len(m.dnsData.TXT) > 0 {
333+
m.txtExpanded = !m.txtExpanded
334+
m.updateViewport()
335+
return m, nil
336+
}
331337
if !m.isIP && m.active == tabMail && m.mailHasSPFTree() {
332338
max := spfMaxDepth(m.spfRoot())
333339
switch {
@@ -342,6 +348,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
342348
return m, nil
343349
}
344350
case "X":
351+
if !m.isIP && m.active == tabDNS && m.dnsData != nil && len(m.dnsData.TXT) > 0 {
352+
m.txtExpanded = !m.txtExpanded
353+
m.updateViewport()
354+
return m, nil
355+
}
345356
if !m.isIP && m.active == tabMail && m.mailHasSPFTree() {
346357
max := spfMaxDepth(m.spfRoot())
347358
if m.spfDepth == SPFExpandAll || m.spfDepth >= max {
@@ -630,7 +641,7 @@ func (m Model) contentForTab(t tab) string {
630641
if m.nsExpanded {
631642
res = m.nsResolved
632643
}
633-
return RenderDNS(m.dnsData, res)
644+
return RenderDNS(m.dnsData, res, m.txtExpanded)
634645
}
635646
case tabTLS:
636647
if m.loading {
@@ -756,6 +767,13 @@ func (m Model) View() tea.View {
756767
footerParts = append(footerParts, "i resolve mx")
757768
}
758769
}
770+
if !m.isIP && m.active == tabDNS && m.dnsData != nil && len(m.dnsData.TXT) > 0 {
771+
if m.txtExpanded {
772+
footerParts = append(footerParts, "x/X truncate txt")
773+
} else {
774+
footerParts = append(footerParts, "x/X full txt")
775+
}
776+
}
759777
if !m.isIP && m.active == tabMail && m.mailHasSPFTree() {
760778
max := spfMaxDepth(m.spfRoot())
761779
switch {

0 commit comments

Comments
 (0)