This commit is contained in:
Meghdad committed 2026-07-12 23:06:00 +03:30
commit eb115daf3b
76 files changed
+22739

No files matched your search

File diff suppressed because it is too large. Load diff
+853
View File
@@ -0,0 +1,853 @@
package tui
import (
"context"
"errors"
"fmt"
"strings"
"testing"
"time"
tea "charm.land/bubbletea/v2"
"github.com/MeghdadFadaee/domainops/internal/app"
"github.com/MeghdadFadaee/domainops/internal/domain"
)
func TestModelRendersResponsiveOperationalViews(t *testing.T) {
backend := &fakeBackend{}
model := New(backend, Options{Version: "test"})
now := time.Now().UTC()
_, _ = model.Update(tea.WindowSizeMsg{Width: 132, Height: 38})
_, _ = model.Update(loadMsg{
dashboard: domain.DashboardSnapshot{GeneratedAt: now, Accounts: 2, Zones: 60, DNSRecords: 420, Certificates: 12, CertificatesDue: 2, Issues: []domain.HealthIssue{{ID: "i", Severity: domain.SeverityWarning, Title: "Certificate differs", Detail: "public endpoint is stale"}}},
credentials: []domain.Credential{{ID: "cred", Label: "Production", Provider: domain.ProviderCloudflare, Status: domain.CredentialValid}},
accounts: []domain.RemoteAccount{{ID: "account", Name: "Primary account"}},
zones: []domain.Zone{{ID: "zone", AccountID: "account", PreferredCredentialID: "cred", Name: "example.com", Status: domain.ZoneActive, Plan: "Pro"}},
records: []domain.DNSRecord{{ID: "record", ZoneID: "zone", Type: domain.RecordA, Name: "example.com", Content: "192.0.2.1", TTL: 1, Proxied: true}},
})
view := model.View().Content
for _, expected := range []string{"DOMAINOPS", "Dashboard", "ACTION QUEUE", "Certificate differs", "60"} {
if !strings.Contains(view, expected) {
t.Fatalf("dashboard does not contain %q", expected)
}
}
model.screen = screenDNS
view = model.View().Content
for _, expected := range []string{"DNS · example.com", "192.0.2.1", "proxied"} {
if !strings.Contains(view, expected) {
t.Fatalf("DNS view does not contain %q", expected)
}
}
model.screen = screenZones
view = model.View().Content
for _, expected := range []string{"Primary account", "Production"} {
if !strings.Contains(view, expected) {
t.Fatalf("zone ownership view does not contain %q", expected)
}
}
_, _ = model.Update(tea.WindowSizeMsg{Width: 50, Height: 12})
if view = model.View().Content; !strings.Contains(view, "terminal is too small") {
t.Fatalf("small-terminal fallback missing: %q", view)
}
}
func TestUndersizedTerminalRejectsAllHiddenInteractiveInput(t *testing.T) {
backend := &fakeBackend{}
model := New(backend, Options{})
model.width, model.height = 50, 12
model.screen = screenDNS
model.zones = []domain.Zone{{ID: "zone", Name: "example.com"}}
model.activeDNSZoneID = "zone"
model.records = []domain.DNSRecord{{ID: "record", ZoneID: "zone", Type: domain.RecordA, Name: "example.com"}}
_, cmd := model.Update(tea.KeyPressMsg{Code: 'd', Text: "d"})
if cmd != nil || model.confirmDelete {
t.Fatalf("undersized view opened hidden delete confirmation: cmd=%v confirm=%v", cmd != nil, model.confirmDelete)
}
// A modal that became hidden after a resize must not accept confirmation input.
model.confirmDelete = true
_, cmd = model.Update(tea.KeyPressMsg{Code: tea.KeyEnter})
if cmd != nil || backend.deleteCalls != 0 || !model.confirmDelete {
t.Fatalf("undersized hidden confirmation mutated state: cmd=%v calls=%d confirm=%v", cmd != nil, backend.deleteCalls, model.confirmDelete)
}
locked := &fakeBackend{locked: true}
unlockModel := New(locked, Options{})
unlockModel.width, unlockModel.height = 40, 10
unlockModel.unlockInputs[0].SetValue("secret")
_, cmd = unlockModel.Update(tea.KeyPressMsg{Code: tea.KeyEnter})
if cmd != nil || locked.unlockCalls != 0 || !unlockModel.unlock {
t.Fatalf("undersized hidden unlock accepted input: cmd=%v calls=%d unlock=%v", cmd != nil, locked.unlockCalls, unlockModel.unlock)
}
}
func TestRecordFormBuildsStructuredCAAAndSRVData(t *testing.T) {
model := New(&fakeBackend{}, Options{})
model.zones = []domain.Zone{{ID: "zone", Name: "example.com"}}
model.openRecordForm(false)
model.recordInputs[0].SetValue("CAA")
model.recordInputs[1].SetValue("@")
model.recordInputs[2].SetValue("0 issue letsencrypt.org")
model.recordInputs[3].SetValue("300")
record, err := model.recordFromForm()
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(record.Data), `"tag":"issue"`) || !strings.Contains(string(record.Data), `"value":"letsencrypt.org"`) {
t.Fatalf("CAA data = %s", record.Data)
}
model.recordInputs[2].SetValue(`0 issue "letsencrypt.org"`)
record, err = model.recordFromForm()
if err != nil || !strings.Contains(string(record.Data), `"value":"letsencrypt.org"`) || strings.Contains(string(record.Data), `\\"letsencrypt.org\\"`) {
t.Fatalf("quoted CAA value was not normalized: data=%s err=%v", record.Data, err)
}
model.recordInputs[0].SetValue("SRV")
model.recordInputs[1].SetValue("_https._tcp")
model.recordInputs[2].SetValue("10 5 443 target.example.com")
record, err = model.recordFromForm()
if err != nil {
t.Fatal(err)
}
if record.Priority == nil || *record.Priority != 10 || !strings.Contains(string(record.Data), `"port":443`) {
t.Fatalf("SRV record = %#v data=%s", record, record.Data)
}
model.recordInputs[2].SetValue("10 5 0 .")
if _, err := model.recordFromForm(); err != nil {
t.Fatalf("valid SRV port zero was rejected: %v", err)
}
model.records = []domain.DNSRecord{{
ID: "srv", ZoneID: "zone", Type: domain.RecordSRV, Name: "_https._tcp.example.com",
Priority: record.Priority, TTL: 300, Data: record.Data,
}}
model.openRecordForm(true)
if got := model.recordInputs[2].Value(); got != "10 5 443 target.example.com" {
t.Fatalf("structured SRV edit value = %q", got)
}
}
func TestCertificateSelectionClampsAfterFiltering(t *testing.T) {
model := New(&fakeBackend{}, Options{})
model.screen = screenCertificates
model.lineages = []domain.CertificateLineage{{ID: "first", Name: "first.example"}, {ID: "second", Name: "second.example"}}
model.rowOffset = 1
model.searchInput.SetValue("first")
model.clampSelection()
if model.rowOffset != 0 {
t.Fatalf("filtered certificate selection = %d, want 0", model.rowOffset)
}
model.openCertificateForm("export")
if model.certificateAction != "export" {
t.Fatalf("certificate action = %q", model.certificateAction)
}
}
func TestRecordFormOpensReviewBeforeMutation(t *testing.T) {
model := New(&fakeBackend{}, Options{})
model.screen = screenDNS
model.zones = []domain.Zone{{ID: "zone", Name: "example.com"}}
model.activeDNSZoneID = "zone"
model.openRecordForm(false)
model.recordInputs[0].SetValue("A")
model.recordInputs[1].SetValue("www")
model.recordInputs[2].SetValue("192.0.2.10")
model.recordInputs[3].SetValue("300")
model.recordFocus = len(model.recordInputs) - 1
_, cmd := model.Update(tea.KeyPressMsg{Code: tea.KeyEnter})
if cmd != nil || !model.confirmRecord || model.busy || model.editRecord {
t.Fatalf("record skipped review: cmd=%v confirm=%v busy=%v edit=%v", cmd != nil, model.confirmRecord, model.busy, model.editRecord)
}
if view := model.View().Content; !strings.Contains(view, "APPLY DNS CHANGE?") || !strings.Contains(view, "192.0.2.10") {
t.Fatalf("record review is incomplete: %q", view)
}
}
func TestDNSFilterKeepsActiveZoneAndUsesStructuredContent(t *testing.T) {
model := New(&fakeBackend{}, Options{})
model.screen = screenDNS
model.zones = []domain.Zone{{ID: "zone", Name: "example.com"}}
model.activeDNSZoneID = "zone"
model.records = []domain.DNSRecord{{
ID: "caa", ZoneID: "zone", Type: domain.RecordCAA, Name: "example.com", TTL: 300,
Data: []byte(`{"flags":0,"tag":"issue","value":"letsencrypt.org"}`),
}}
model.searchInput.SetValue("letsencrypt")
view := model.View().Content
if !strings.Contains(view, "DNS · example.com") || !strings.Contains(view, "letsencrypt.org") {
t.Fatalf("DNS filter lost active zone or structured content: %q", view)
}
}
func TestFiltersCoverVisibleOperationalFields(t *testing.T) {
model := New(&fakeBackend{}, Options{})
model.accounts = []domain.RemoteAccount{{ID: "account", Name: "Customer Production"}}
model.credentials = []domain.Credential{{ID: "credential", Label: "Write Token", Kind: domain.CredentialAccountToken, Capabilities: []string{"dns:write"}}}
model.zones = []domain.Zone{{ID: "zone", Name: "example.com", AccountID: "account", PreferredCredentialID: "credential", Plan: "Business"}}
model.searchInput.SetValue("customer production")
if len(model.filteredZones()) != 1 {
t.Fatal("zone filter ignored visible account name")
}
model.searchInput.SetValue("dns:write")
if len(model.filteredCredentials()) != 1 {
t.Fatal("account filter ignored visible capability")
}
model.lineages = []domain.CertificateLineage{{ID: "lineage", Name: "example.com"}}
model.certificateItems = []app.CertificateInventoryItem{{Lineage: model.lineages[0], Environment: "production", Status: "valid", Current: &domain.CertificateVersion{Issuer: "Example Issuer"}}}
model.searchInput.SetValue("example issuer")
if len(model.filteredLineages()) != 1 {
t.Fatal("certificate filter ignored visible issuer")
}
model.jobs = []domain.Job{{ID: "job", Kind: "cloudflare.sync", Message: "Loaded zones"}}
model.searchInput.SetValue("loaded zones")
if len(model.filteredJobs()) != 1 {
t.Fatal("activity filter ignored visible job message")
}
}
func TestLongZoneListKeepsSelectionVisible(t *testing.T) {
model := New(&fakeBackend{}, Options{})
model.screen = screenZones
for index := range 60 {
model.zones = append(model.zones, domain.Zone{ID: fmt.Sprintf("zone-%d", index), Name: fmt.Sprintf("zone-%02d.example", index)})
}
model.zoneIndex = 59
model.width, model.height = 120, 18
if view := model.View().Content; !strings.Contains(view, "zone-59.example") {
t.Fatalf("selected zone is outside viewport: %q", view)
}
}
func TestCertificateExportRequiresExplicitDestination(t *testing.T) {
model := New(&fakeBackend{}, Options{})
model.lineages = []domain.CertificateLineage{{ID: "lineage", Name: "example.com"}}
model.openCertificateForm("export")
if cmd := model.submitCertificateForm(); cmd != nil || model.err == nil || model.busy || model.certificateAction != "export" {
t.Fatalf("empty export destination was accepted: cmd=%v err=%v busy=%v action=%q", cmd != nil, model.err, model.busy, model.certificateAction)
}
}
func TestRevokeRequiresManuallyTypedExactLineageName(t *testing.T) {
backend := &fakeBackend{}
model := New(backend, Options{})
model.screen = screenCertificates
model.lineages = []domain.CertificateLineage{{ID: "lineage", Name: "example.com"}}
model.certificateItems = []app.CertificateInventoryItem{{Lineage: model.lineages[0], Environment: "production"}}
model.openCertificateForm("revoke")
if got := model.certificateInputs[1].Value(); got != "" {
t.Fatalf("exact-name revocation confirmation was prefilled: %q", got)
}
if view := model.View().Content; !strings.Contains(view, "Expected exact name:") || !strings.Contains(view, "example.com") {
t.Fatalf("revocation form does not render expected name separately: %q", view)
}
if cmd := model.submitCertificateForm(); cmd != nil || model.certificateAction != "revoke" || model.err == nil {
t.Fatalf("blank revocation confirmation was accepted: cmd=%v action=%q err=%v", cmd != nil, model.certificateAction, model.err)
}
model.certificateInputs[1].SetValue("example.com")
cmd := model.submitCertificateForm()
if cmd == nil {
t.Fatalf("exact revocation confirmation did not submit: err=%v", model.err)
}
_ = cmd()
if len(backend.revokeLineages) != 1 || backend.revokeLineages[0] != "lineage" || backend.revokeConfirmations[0] != "example.com" {
t.Fatalf("revocation call = lineages:%v confirmations:%v", backend.revokeLineages, backend.revokeConfirmations)
}
}
func TestDuplicateZoneNamesRequireIDsAndSelectedIssueRetainsLocalID(t *testing.T) {
backend := &fakeBackend{}
model := New(backend, Options{})
model.screen = screenCertificates
model.zones = []domain.Zone{
{ID: "zone-account-a", AccountID: "account-a", Name: "shared.example"},
{ID: "zone-account-b", AccountID: "account-b", Name: "shared.example"},
}
if _, err := model.resolveZoneValues([]string{"shared.example"}); err == nil || !strings.Contains(err.Error(), "ambiguous") {
t.Fatalf("duplicate-name zone resolution = %v, want ambiguity", err)
}
if ids, err := model.resolveZoneValues([]string{"zone-account-a"}); err != nil || len(ids) != 1 || ids[0] != "zone-account-a" {
t.Fatalf("explicit zone ID resolution = %v, %v", ids, err)
}
model.zoneIndex = 1
model.openCertificateForm("issue")
if got := model.certificateInputs[0].Value(); got != "zone-account-b" || model.certificateIssueZoneID != "zone-account-b" {
t.Fatalf("selected issue zone was not retained by local ID: input=%q retained=%q", got, model.certificateIssueZoneID)
}
model.certificateInputs[2].SetValue("ops@example.com")
cmd := model.submitCertificateForm()
if cmd == nil {
t.Fatalf("selected-ID issue did not submit: %v", model.err)
}
_ = cmd()
if len(backend.issueRequests) != 1 || len(backend.issueRequests[0].ZoneIDs) != 1 || backend.issueRequests[0].ZoneIDs[0] != "zone-account-b" {
t.Fatalf("issue request routed to wrong zone: %#v", backend.issueRequests)
}
}
func TestBusyModelRejectsOverlappingMutation(t *testing.T) {
model := New(&fakeBackend{}, Options{})
model.screen = screenDNS
model.busy = true
model.zones = []domain.Zone{{ID: "zone", Name: "example.com"}}
_, cmd := model.Update(tea.KeyPressMsg{Code: 'n', Text: "n"})
if cmd != nil || model.editRecord {
t.Fatalf("busy model opened another mutation: cmd=%v edit=%v", cmd != nil, model.editRecord)
}
}
func TestZonesNavigationLoadsTheHighlightedZoneInsteadOfOldDNSZone(t *testing.T) {
for _, test := range []struct {
name string
key tea.KeyPressMsg
}{
{name: "enter", key: tea.KeyPressMsg{Code: tea.KeyEnter}},
{name: "next screen", key: tea.KeyPressMsg{Code: 'l', Text: "l"}},
{name: "DNS shortcut", key: tea.KeyPressMsg{Code: '4', Text: "4"}},
} {
t.Run(test.name, func(t *testing.T) {
backend := &fakeBackend{}
model := New(backend, Options{})
model.screen = screenZones
model.zones = []domain.Zone{{ID: "zone-old", Name: "old.example"}, {ID: "zone-new", Name: "new.example"}}
model.zoneIndex = 1
model.activeDNSZoneID = "zone-old"
_, cmd := model.Update(test.key)
if cmd == nil {
t.Fatal("navigation did not start DNS zone load")
}
_ = cmd()
if model.screen != screenDNS {
t.Fatalf("screen = %d, want DNS", model.screen)
}
if len(backend.dnsZones) == 0 || backend.dnsZones[len(backend.dnsZones)-1] != "zone-new" {
t.Fatalf("DNS load zones = %#v, want zone-new", backend.dnsZones)
}
})
}
}
func TestPaletteZonesNavigationLoadsHighlightedDNSZone(t *testing.T) {
backend := &fakeBackend{}
model := New(backend, Options{})
model.screen = screenZones
model.zones = []domain.Zone{{ID: "zone-old", Name: "old.example"}, {ID: "zone-new", Name: "new.example"}}
model.zoneIndex = 1
model.activeDNSZoneID = "zone-old"
model.showPalette = true
model.paletteIndex = int(screenDNS)
_, cmd := model.Update(tea.KeyPressMsg{Code: tea.KeyEnter})
if cmd == nil {
t.Fatal("palette navigation did not start DNS zone load")
}
_ = cmd()
if model.screen != screenDNS || model.rowOffset != 0 {
t.Fatalf("palette navigation state = screen:%d offset:%d", model.screen, model.rowOffset)
}
if len(backend.dnsZones) == 0 || backend.dnsZones[len(backend.dnsZones)-1] != "zone-new" {
t.Fatalf("DNS load zones = %#v, want zone-new", backend.dnsZones)
}
}
func TestTLSNavigationToDNSCarriesTheActiveTLSZone(t *testing.T) {
backend := &fakeBackend{}
model := New(backend, Options{})
model.screen = screenTLS
model.zones = []domain.Zone{{ID: "zone-old", Name: "old.example"}, {ID: "zone-new", Name: "new.example"}}
model.activeDNSZoneID = "zone-old"
model.activeTLSZoneID = "zone-new"
model.zoneIndex = 1
_, cmd := model.Update(tea.KeyPressMsg{Code: '4', Text: "4"})
if cmd == nil || model.screen != screenDNS || model.activeDNSZoneID != "zone-new" {
t.Fatalf("TLS→DNS navigation state = cmd:%v screen:%d DNS:%q", cmd != nil, model.screen, model.activeDNSZoneID)
}
_ = cmd()
if len(backend.dnsZones) == 0 || backend.dnsZones[len(backend.dnsZones)-1] != "zone-new" {
t.Fatalf("TLS→DNS loaded stale zone: %v", backend.dnsZones)
}
}
func TestBackwardNavigationIntoTLSStartsZoneBoundLoad(t *testing.T) {
backend := &fakeBackend{}
model := New(backend, Options{})
model.screen = screenActivity
model.zones = []domain.Zone{{ID: "zone-a", Name: "alpha.example"}, {ID: "zone-b", Name: "beta.example"}}
model.zoneIndex = 1
_, cmd := model.Update(tea.KeyPressMsg{Code: 'h', Text: "h"})
if cmd == nil || model.screen != screenTLS || model.activeTLSZoneID != "zone-b" || !model.loading {
t.Fatalf("backward TLS navigation = cmd:%v screen:%d active:%q loading:%v", cmd != nil, model.screen, model.activeTLSZoneID, model.loading)
}
_ = cmd()
if len(backend.tlsZones) == 0 || backend.tlsZones[len(backend.tlsZones)-1] != "zone-b" {
t.Fatalf("backward TLS navigation loaded zones: %v", backend.tlsZones)
}
}
func TestStaleZoneLoadCannotOverwriteLatestRequest(t *testing.T) {
backend := &fakeBackend{}
model := New(backend, Options{})
first := model.startLoad("zone-old", true, false)
second := model.startLoad("zone-new", true, false)
_, _ = model.Update(first())
if !model.loading || model.tls.ZoneID != "" {
t.Fatalf("stale load was accepted: loading=%v tls=%#v", model.loading, model.tls)
}
_, _ = model.Update(second())
if model.loading || model.tls.ZoneID != "zone-new" {
t.Fatalf("latest load was not accepted: loading=%v tls=%#v", model.loading, model.tls)
}
}
func TestFailedTLSRefreshPreservesDraftButDisablesEditing(t *testing.T) {
backend := &fakeBackend{tlsErr: errors.New("Cloudflare unavailable")}
model := New(backend, Options{})
model.screen = screenTLS
model.zones = []domain.Zone{{ID: "zone", Name: "example.com"}}
model.activeTLSZoneID = "zone"
loadedAt := time.Now().UTC()
model.tls = domain.EdgeTLSSettings{ZoneID: "zone", Mode: "strict", AlwaysUseHTTPS: true, MinimumTLS: "1.2", TLS13: true}
model.tlsDraft = model.tls
model.tlsSnapshotReady = true
model.tlsSnapshotZone = "zone"
model.tlsSnapshotAt = loadedAt
refresh := model.startLoad("zone", true, false)
if model.tlsSnapshotReady {
t.Fatal("refresh left the old snapshot marked ready")
}
_, _ = model.Update(refresh())
if model.tlsDraft.Mode != "strict" || !model.tlsDraft.AlwaysUseHTTPS || !model.tlsDraft.TLS13 {
t.Fatalf("failed refresh overwrote the prior draft: %#v", model.tlsDraft)
}
if model.tlsSnapshotReady {
t.Fatal("failed refresh produced a ready snapshot")
}
_, cmd := model.Update(tea.KeyPressMsg{Code: 'm', Text: "m"})
if cmd != nil || model.tlsDraft.Mode != "strict" {
t.Fatalf("unready TLS draft was editable: cmd=%v draft=%#v", cmd != nil, model.tlsDraft)
}
_, cmd = model.Update(tea.KeyPressMsg{Code: 's', Text: "s"})
if cmd != nil || model.confirmTLS || len(backend.updateTLSZones) != 0 {
t.Fatalf("unready TLS snapshot was applicable: cmd=%v confirm=%v calls=%v", cmd != nil, model.confirmTLS, backend.updateTLSZones)
}
}
func TestTLSSnapshotIsZoneBoundAndTimestamped(t *testing.T) {
zones := []domain.Zone{{ID: "zone-a", Name: "alpha.example"}, {ID: "zone-b", Name: "beta.example"}}
backend := &fakeBackend{zones: zones, tlsSettings: map[string]domain.EdgeTLSSettings{
"zone-a": {Mode: "strict", AlwaysUseHTTPS: true, MinimumTLS: "1.2", TLS13: true},
}}
model := New(backend, Options{})
model.screen = screenTLS
model.zones = zones
model.activeTLSZoneID = "zone-a"
load := model.startLoad("zone-a", true, false)
_, _ = model.Update(load())
if !model.tlsSnapshotReadyForSelectedZone() || model.tlsSnapshotZone != "zone-a" || model.tls.ZoneID != "zone-a" || model.tlsSnapshotAt.IsZero() {
t.Fatalf("TLS snapshot metadata = ready:%v zone:%q settings:%#v at:%v", model.tlsSnapshotReady, model.tlsSnapshotZone, model.tls, model.tlsSnapshotAt)
}
model.activeTLSZoneID = "zone-b"
_, cmd := model.Update(tea.KeyPressMsg{Code: 's', Text: "s"})
if cmd != nil || model.confirmTLS {
t.Fatalf("zone-mismatched TLS snapshot was applicable: cmd=%v confirm=%v", cmd != nil, model.confirmTLS)
}
}
func TestTLSFilterZoneChangeReloadsAndEdgeFilterKeepsActiveZone(t *testing.T) {
zones := []domain.Zone{{ID: "zone-a", Name: "alpha.example"}, {ID: "zone-b", Name: "beta.example"}}
backend := &fakeBackend{zones: zones}
model := New(backend, Options{})
model.screen = screenTLS
model.zones = zones
model.activeTLSZoneID = "zone-a"
model.zoneIndex = 0
model.searching = true
model.searchInput.Focus()
model.searchInput.SetValue("bet")
_, cmd := model.Update(tea.KeyPressMsg{Code: 'a', Text: "a"})
if cmd == nil || model.activeTLSZoneID != "zone-b" || !model.loading {
t.Fatalf("TLS zone filter did not schedule reload: cmd=%v active=%q loading=%v", cmd != nil, model.activeTLSZoneID, model.loading)
}
message := cmd()
_, _ = model.Update(message)
if len(backend.tlsZones) == 0 || backend.tlsZones[len(backend.tlsZones)-1] != "zone-b" || !model.tlsSnapshotReadyForSelectedZone() {
t.Fatalf("TLS filter loaded zones=%v ready=%v snapshot=%q", backend.tlsZones, model.tlsSnapshotReady, model.tlsSnapshotZone)
}
model.edgeCertificates = []domain.EdgeCertificate{{ID: "edge", ZoneID: "zone-b", Type: "universal", Status: "active"}}
model.searchInput.SetValue("universal")
if reload := model.reloadTLSAfterFilterChange("zone-b"); reload != nil || model.activeTLSZoneID != "zone-b" {
t.Fatalf("edge-only TLS filter changed the active zone: reload=%v active=%q", reload != nil, model.activeTLSZoneID)
}
if view := model.View().Content; !strings.Contains(view, "universal") || strings.Contains(view, "No zone selected") {
t.Fatalf("edge-only filter hid the active TLS view: %q", view)
}
}
func TestLoadingModelRejectsMutations(t *testing.T) {
model := New(&fakeBackend{}, Options{})
model.screen = screenTLS
model.loading = true
model.zones = []domain.Zone{{ID: "zone", Name: "example.com"}}
_, cmd := model.Update(tea.KeyPressMsg{Code: 's', Text: "s"})
if cmd != nil || model.confirmTLS {
t.Fatalf("loading model opened TLS confirmation: cmd=%v confirm=%v", cmd != nil, model.confirmTLS)
}
if model.toast != "Loading the latest zone state" {
t.Fatalf("loading mutation toast = %q", model.toast)
}
}
func TestUnlockEnterCannotStartConcurrentRecovery(t *testing.T) {
backend := &fakeBackend{locked: true}
model := New(backend, Options{})
model.busy = true
model.unlockInputs[0].SetValue("password")
_, cmd := model.Update(tea.KeyPressMsg{Code: tea.KeyEnter})
if cmd != nil || backend.unlockCalls != 0 {
t.Fatalf("busy unlock started again: cmd=%v calls=%d", cmd != nil, backend.unlockCalls)
}
}
type nonFatalUnlockWarning struct{}
func (nonFatalUnlockWarning) Error() string { return "recovery warning" }
func (nonFatalUnlockWarning) NonFatal() bool { return true }
func TestNonFatalRecoveryWarningLeavesUnlockScreen(t *testing.T) {
model := New(&fakeBackend{locked: true}, Options{})
_, cmd := model.Update(unlockMsg{err: nonFatalUnlockWarning{}})
if cmd == nil || model.unlock || model.err == nil {
t.Fatalf("nonfatal recovery state = cmd:%v unlock:%v err:%v", cmd != nil, model.unlock, model.err)
}
if model.toast != "Vault unlocked; recovery requires attention" {
t.Fatalf("recovery warning toast = %q", model.toast)
}
}
func TestPersistedRecoveryIssueBlocksTUIAndPaletteMutations(t *testing.T) {
issue := domain.HealthIssue{Kind: "certificate_commit_recovery_failed", ResourceID: "certificate-commit-recovery"}
for _, palette := range []bool{false, true} {
model := New(&fakeBackend{}, Options{})
_, _ = model.Update(loadMsg{dashboard: domain.DashboardSnapshot{Issues: []domain.HealthIssue{issue}}})
model.screen = screenDashboard
if palette {
model.showPalette = true
model.paletteIndex = len(screens)
}
key := tea.KeyPressMsg{Code: 'a', Text: "a"}
if palette {
key = tea.KeyPressMsg{Code: tea.KeyEnter}
}
_, cmd := model.Update(key)
if cmd != nil || model.addCredential {
t.Fatalf("recovery-blocked mutation (palette=%v) = cmd:%v form:%v", palette, cmd != nil, model.addCredential)
}
if !strings.Contains(model.toast, "Crash recovery") {
t.Fatalf("recovery-blocked toast (palette=%v) = %q", palette, model.toast)
}
}
}
func TestRecoveryRetryUsesUnlockedVaultPathAndReloadsOnSuccess(t *testing.T) {
backend := &fakeBackend{}
model := New(backend, Options{})
model.recoveryBlocked = true
_, cmd := model.Update(tea.KeyPressMsg{Code: 'R', Text: "R"})
if cmd == nil || !model.busy {
t.Fatalf("recovery retry did not start: cmd=%v busy=%v", cmd != nil, model.busy)
}
message := cmd()
if backend.unlockNilCalls != 1 {
t.Fatalf("recovery retry did not call UnlockVault with nil password: nil calls=%d", backend.unlockNilCalls)
}
_, reload := model.Update(message)
if reload == nil || model.recoveryBlocked || !model.busy {
t.Fatalf("successful recovery did not clear/reload safely: reload=%v blocked=%v busy=%v", reload != nil, model.recoveryBlocked, model.busy)
}
_, _ = model.Update(reload())
if model.busy || model.recoveryBlocked {
t.Fatalf("recovery reload did not settle: busy=%v blocked=%v", model.busy, model.recoveryBlocked)
}
}
func TestRecoveryRetryWarningRetainsStickyBlockAndAdvertisesRetry(t *testing.T) {
backend := &fakeBackend{unlockErr: nonFatalUnlockWarning{}}
model := New(backend, Options{})
model.recoveryBlocked = true
if footer := model.renderFooter(); !strings.Contains(footer, "retry recovery") {
t.Fatalf("recovery footer does not advertise retry: %q", footer)
}
model.showHelp = true
if help := model.renderHelp(); !strings.Contains(help, "Retry blocked crash recovery") {
t.Fatalf("recovery help does not advertise retry: %q", help)
}
model.showHelp = false
_, cmd := model.Update(tea.KeyPressMsg{Code: 'R', Text: "R"})
if cmd == nil {
t.Fatal("recovery warning retry did not start")
}
_, reload := model.Update(cmd())
if reload != nil || !model.recoveryBlocked || model.busy || model.err == nil {
t.Fatalf("warning did not retain recovery block: reload=%v blocked=%v busy=%v err=%v", reload != nil, model.recoveryBlocked, model.busy, model.err)
}
}
func TestUnrelatedLoadDoesNotReleaseBusyMutation(t *testing.T) {
model := New(&fakeBackend{}, Options{})
model.busy = true
model.loading = true
_, _ = model.Update(loadMsg{})
if !model.busy {
t.Fatal("unrelated load released the active mutation lock")
}
if model.loading {
t.Fatal("completed load left the loading indicator active")
}
}
func TestOperationReloadReleasesBusyOnlyAfterItsLoad(t *testing.T) {
model := New(&fakeBackend{}, Options{})
model.busy = true
_, reload := model.Update(operationMsg{message: "saved", reload: true})
if reload == nil || !model.busy || !model.loading {
t.Fatalf("operation reload state = cmd:%v busy:%v loading:%v", reload != nil, model.busy, model.loading)
}
// A navigation/background load may finish before the operation's own reload.
_, _ = model.Update(loadMsg{})
if !model.busy {
t.Fatal("unrelated load released the operation reload lock")
}
message := reload()
completed, ok := message.(loadMsg)
if !ok || !completed.releasesBusy {
t.Fatalf("operation reload message = %#v", message)
}
_, _ = model.Update(completed)
if model.busy || model.loading {
t.Fatalf("operation reload did not release lock: busy:%v loading:%v", model.busy, model.loading)
}
}
func TestNavigationLoadInheritsPendingOperationBusyRelease(t *testing.T) {
model := New(&fakeBackend{}, Options{})
model.busy = true
_, operationReload := model.Update(operationMsg{message: "saved", reload: true})
if operationReload == nil || !model.busyReleasePending {
t.Fatalf("operation reload did not establish release obligation")
}
navigationLoad := model.startLoad("zone-new", true, false)
_, _ = model.Update(operationReload())
if !model.busy {
t.Fatal("stale operation reload released busy before the latest load")
}
latest := navigationLoad()
message, ok := latest.(loadMsg)
if !ok || !message.releasesBusy {
t.Fatalf("navigation load did not inherit busy release: %#v", latest)
}
_, _ = model.Update(message)
if model.busy || model.busyReleasePending {
t.Fatalf("latest navigation load left busy locked: busy=%v pending=%v", model.busy, model.busyReleasePending)
}
}
func TestBusyCommandPaletteRejectsMutationEntries(t *testing.T) {
for _, test := range []struct {
name string
index int
}{
{name: "add credential", index: len(screens)},
{name: "synchronize", index: len(screens) + 1},
} {
t.Run(test.name, func(t *testing.T) {
model := New(&fakeBackend{}, Options{})
model.busy = true
model.showPalette = true
model.paletteIndex = test.index
_, cmd := model.Update(tea.KeyPressMsg{Code: tea.KeyEnter})
if cmd != nil || !model.busy || model.addCredential {
t.Fatalf("busy palette mutation = cmd:%v busy:%v form:%v", cmd != nil, model.busy, model.addCredential)
}
if model.toast != "An operation is already running" {
t.Fatalf("busy palette toast = %q", model.toast)
}
})
}
}
func TestLoadingCommandPaletteRejectsMutationEntries(t *testing.T) {
model := New(&fakeBackend{}, Options{})
model.loading = true
model.showPalette = true
model.paletteIndex = len(screens) + 1
_, cmd := model.Update(tea.KeyPressMsg{Code: tea.KeyEnter})
if cmd != nil || model.busy {
t.Fatalf("loading palette started sync: cmd=%v busy=%v", cmd != nil, model.busy)
}
if model.toast != "Loading the latest zone state" {
t.Fatalf("loading palette toast = %q", model.toast)
}
}
func TestFirstRunVaultRequiresConfirmation(t *testing.T) {
backend := &fakeBackend{locked: true}
model := New(backend, Options{FirstRun: true})
if !model.unlock || len(model.unlockInputs) != 2 {
t.Fatalf("first-run unlock state = %#v", model)
}
view := model.View().Content
if !strings.Contains(view, "CREATE LOCAL VAULT") || !strings.Contains(view, "Confirm password") {
t.Fatalf("first-run view missing setup copy")
}
}
func TestFirstRunRejectsShortVaultPassword(t *testing.T) {
backend := &fakeBackend{locked: true}
model := New(backend, Options{FirstRun: true})
model.unlockInputs[0].SetValue("short")
model.unlockInputs[1].SetValue("short")
model.unlockFocus = 1
_, cmd := model.Update(tea.KeyPressMsg{Code: tea.KeyEnter})
if cmd != nil || model.err == nil || !strings.Contains(model.err.Error(), "at least 10") {
t.Fatalf("short first-run password was not rejected: err=%v cmd=%v", model.err, cmd != nil)
}
}
func TestExistingVaultAcceptsLegacyShortPassword(t *testing.T) {
backend := &fakeBackend{locked: true}
model := New(backend, Options{FirstRun: false})
model.unlockInputs[0].SetValue("short")
_, cmd := model.Update(tea.KeyPressMsg{Code: tea.KeyEnter})
if cmd == nil || model.err != nil {
t.Fatalf("legacy password should be sent to the vault: err=%v cmd=%v", model.err, cmd != nil)
}
message := cmd()
if result, ok := message.(unlockMsg); !ok || result.err != nil || backend.locked {
t.Fatalf("unlock result = %#v, locked=%v", message, backend.locked)
}
}
type fakeBackend struct {
locked bool
unlockCalls int
unlockNilCalls int
unlockErr error
dnsZones []string
zones []domain.Zone
deleteCalls int
tlsSettings map[string]domain.EdgeTLSSettings
tlsErr error
tlsZones []string
updateTLSZones []string
updateTLSDrafts []domain.EdgeTLSSettings
issueRequests []app.IssueZonesRequest
revokeLineages []string
revokeConfirmations []string
}
func (f *fakeBackend) VaultLocked() bool { return f.locked }
func (f *fakeBackend) UnlockVault(_ context.Context, password []byte) error {
f.unlockCalls++
if password == nil {
f.unlockNilCalls++
}
if f.unlockErr == nil {
f.locked = false
}
return f.unlockErr
}
func (f *fakeBackend) Dashboard(context.Context) (domain.DashboardSnapshot, error) {
return domain.DashboardSnapshot{}, nil
}
func (f *fakeBackend) Credentials(context.Context) ([]domain.Credential, error) { return nil, nil }
func (f *fakeBackend) Accounts(context.Context) ([]domain.RemoteAccount, error) { return nil, nil }
func (f *fakeBackend) Zones(context.Context) ([]domain.Zone, error) { return f.zones, nil }
func (f *fakeBackend) DNSRecords(_ context.Context, zoneID string) ([]domain.DNSRecord, error) {
f.dnsZones = append(f.dnsZones, zoneID)
return nil, nil
}
func (f *fakeBackend) Certificates(context.Context) ([]domain.CertificateLineage, error) {
return nil, nil
}
func (f *fakeBackend) CertificateInventory(context.Context) ([]app.CertificateInventoryItem, error) {
return nil, nil
}
func (f *fakeBackend) Jobs(context.Context, int) ([]domain.Job, error) { return nil, nil }
func (f *fakeBackend) Audit(context.Context, int) ([]domain.AuditEvent, error) { return nil, nil }
func (f *fakeBackend) AddCloudflareCredential(context.Context, app.AddCredentialInput) (domain.Credential, error) {
return domain.Credential{}, nil
}
func (f *fakeBackend) SyncAll(context.Context) ([]domain.Job, error) { return nil, nil }
func (f *fakeBackend) CreateDNSRecord(context.Context, string, domain.DNSRecord) (domain.DNSRecord, error) {
return domain.DNSRecord{}, nil
}
func (f *fakeBackend) PatchDNSRecord(context.Context, string, string, domain.DNSRecord) (domain.DNSRecord, error) {
return domain.DNSRecord{}, nil
}
func (f *fakeBackend) DeleteDNSRecord(context.Context, string, string) error {
f.deleteCalls++
return nil
}
func (f *fakeBackend) TLSSettings(_ context.Context, zoneID string, _ bool) (domain.EdgeTLSSettings, error) {
f.tlsZones = append(f.tlsZones, zoneID)
if f.tlsErr != nil {
return domain.EdgeTLSSettings{}, f.tlsErr
}
if settings, ok := f.tlsSettings[zoneID]; ok {
return settings, nil
}
return domain.EdgeTLSSettings{ZoneID: zoneID, Mode: "strict", MinimumTLS: "1.2", TLS13: true}, nil
}
func (f *fakeBackend) EdgeCertificates(context.Context, string) ([]domain.EdgeCertificate, error) {
return nil, nil
}
func (f *fakeBackend) UpdateTLSSettings(_ context.Context, zoneID string, draft domain.EdgeTLSSettings) (domain.EdgeTLSSettings, error) {
f.updateTLSZones = append(f.updateTLSZones, zoneID)
f.updateTLSDrafts = append(f.updateTLSDrafts, draft)
return draft, nil
}
func (f *fakeBackend) IssueCertificates(_ context.Context, request app.IssueZonesRequest) (app.IssueZonesResult, error) {
f.issueRequests = append(f.issueRequests, request)
return app.IssueZonesResult{}, nil
}
func (f *fakeBackend) ImportCertificateMetadata(context.Context, string, string, string) (domain.CertificateLineage, domain.CertificateVersion, error) {
return domain.CertificateLineage{}, domain.CertificateVersion{}, nil
}
func (f *fakeBackend) ExportCertificate(context.Context, string, string) (string, error) {
return "", nil
}
func (f *fakeBackend) RevokeCertificate(_ context.Context, lineageID, _ string, confirmation string, _ *uint) error {
f.revokeLineages = append(f.revokeLineages, lineageID)
f.revokeConfirmations = append(f.revokeConfirmations, confirmation)
return nil
}
func (f *fakeBackend) RenewCertificates(context.Context, string, bool) (app.IssueZonesResult, error) {
return app.IssueZonesResult{}, nil
}
+762
View File
@@ -0,0 +1,762 @@
package tui
import (
"bytes"
"encoding/json"
"fmt"
"sort"
"strings"
"time"
"charm.land/lipgloss/v2"
"github.com/MeghdadFadaee/domainops/internal/app"
"github.com/MeghdadFadaee/domainops/internal/domain"
)
func (m *Model) render() string {
if m.terminalUndersized() {
message := m.theme.modal.Width(min(52, max(20, m.width-4))).Render(
m.theme.brand.Render("DOMAINOPS") + "\n\n" +
"The terminal is too small for a safe operator view.\n" +
m.theme.mutedText.Render(fmt.Sprintf("Current %d×%d · minimum 64×18", m.width, m.height)),
)
return m.theme.app.Width(m.width).Height(m.height).Render(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, message))
}
if m.unlock {
return m.renderUnlock()
}
if m.addCredential {
return m.renderCredentialForm()
}
if m.editRecord {
return m.renderRecordForm()
}
if m.certificateAction != "" {
return m.renderCertificateForm()
}
if m.confirmRecord {
return m.renderRecordConfirmation()
}
if m.confirmDelete {
return m.renderDeleteConfirmation()
}
if m.confirmTLS {
return m.renderTLSConfirmation()
}
if m.showHelp {
return m.renderHelp()
}
if m.showPalette {
return m.renderPalette()
}
header := m.renderHeader()
foot := m.renderFooter()
bodyHeight := max(1, m.height-lipgloss.Height(header)-lipgloss.Height(foot))
sidebarWidth := 23
if m.width < 88 {
sidebarWidth = 15
}
mainWidth := max(20, m.width-sidebarWidth)
sidebar := m.renderSidebar(sidebarWidth, bodyHeight)
main := m.theme.app.Width(mainWidth).Height(bodyHeight).Padding(1, 1).Render(m.renderScreen(mainWidth-2, bodyHeight-2))
body := lipgloss.JoinHorizontal(lipgloss.Top, sidebar, main)
return m.theme.app.Width(m.width).Height(m.height).Render(header + "\n" + body + "\n" + foot)
}
func (m *Model) renderHeader() string {
brand := m.theme.brand.Render("◆ DOMAINOPS")
section := m.theme.mutedText.Render(" / " + screens[m.screen].name)
left := brand + section
state := m.theme.statusOK.Render("● READY")
if m.busy || m.loading {
state = m.theme.statusWarn.Render("◌ WORKING")
} else if m.err != nil {
state = m.theme.statusBad.Render("● ATTENTION")
}
version := m.options.Version
if version == "" {
version = "dev"
}
right := m.theme.mutedText.Render(version) + " " + state
space := strings.Repeat(" ", max(1, m.width-lipgloss.Width(left)-lipgloss.Width(right)-4))
return m.theme.header.Width(m.width).Render(left + space + right)
}
func (m *Model) renderFooter() string {
left := m.theme.key.Render("?") + " help " + m.theme.key.Render("Ctrl+K") + " commands " + m.theme.key.Render("/") + " filter"
right := m.theme.key.Render("r") + " sync " + m.theme.key.Render("q") + " quit"
if m.recoveryBlocked {
right = m.theme.key.Render("R") + " retry recovery " + m.theme.key.Render("q") + " quit"
}
if m.searching {
left = m.searchInput.View()
} else if m.filterValue() != "" {
left = m.theme.statusWarn.Render("FILTER: ") + m.searchInput.Value() + " " + m.theme.mutedText.Render("/ to edit")
}
if m.err != nil {
left = m.theme.statusBad.Render("! ") + truncate(m.err.Error(), max(16, m.width-lipgloss.Width(right)-8))
} else if m.toast != "" && time.Since(m.toastAt) < 12*time.Second {
left = m.theme.statusOK.Render("✓ ") + m.toast
}
space := strings.Repeat(" ", max(1, m.width-lipgloss.Width(left)-lipgloss.Width(right)-2))
return m.theme.header.Width(m.width).Render(left + space + right)
}
func (m *Model) renderSidebar(width, height int) string {
var lines []string
for i, item := range screens {
label := fmt.Sprintf("%d %s %s", i+1, item.icon, item.name)
if width < 18 {
label = fmt.Sprintf("%d %s %s", i+1, item.icon, truncate(item.name, 7))
}
style := m.theme.nav.Width(width - 3)
if screen(i) == m.screen {
style = m.theme.navActive.Width(width - 3)
}
lines = append(lines, style.Render(label))
}
lines = append(lines, "", m.theme.mutedText.Render("WORKSPACE"))
if zone, ok := m.selectedZone(); ok {
lines = append(lines, m.theme.panelTitle.Render(truncate(zone.Name, width-4)), m.theme.mutedText.Render(strings.ToUpper(string(zone.Status))))
} else {
lines = append(lines, m.theme.mutedText.Render("No zone selected"))
}
return m.theme.sidebar.Width(width).Height(height).Render(strings.Join(lines, "\n"))
}
func (m *Model) renderScreen(width, height int) string {
if m.loading && len(m.zones) == 0 && m.screen != screenDashboard {
return m.emptyState("Synchronizing local state…", "The view will update without blocking the terminal.", width, height)
}
switch m.screen {
case screenDashboard:
return m.renderDashboard(width, height)
case screenAccounts:
return m.renderAccounts(width, height)
case screenZones:
return m.renderZones(width, height)
case screenDNS:
return m.renderDNS(width, height)
case screenCertificates:
return m.renderCertificates(width, height)
case screenTLS:
return m.renderTLS(width, height)
case screenActivity:
return m.renderActivity(width, height)
default:
return ""
}
}
func (m *Model) renderDashboard(width, height int) string {
if len(m.credentials) == 0 {
body := m.theme.brand.Render("Welcome to DomainOps") + "\n\n" +
"Connect a scoped Cloudflare API token to build your live domain inventory.\n" +
m.theme.mutedText.Render("Recommended scopes: Zone Read, DNS Read/Write, and optional Zone Settings Read/Write.") + "\n\n" +
m.theme.key.Render("a") + " Add your first Cloudflare account"
return m.panel("GET STARTED", body, width, min(height, 12))
}
cardGap := 1
columns := 3
if width < 78 {
columns = 2
}
cardWidth := max(15, (width-(columns-1)*cardGap)/columns)
cards := []string{
m.statCard("ACCOUNTS", m.dashboard.Accounts, "connected", cardWidth),
m.statCard("ZONES", m.dashboard.Zones, "managed", cardWidth),
m.statCard("DNS RECORDS", m.dashboard.DNSRecords, "cached", cardWidth),
m.statCard("CERTIFICATES", m.dashboard.Certificates, "tracked", cardWidth),
m.statCard("RENEWAL DUE", m.dashboard.CertificatesDue, "action needed", cardWidth),
m.statCard("EXPIRED", m.dashboard.CertificatesExpired, "critical", cardWidth),
m.statCard("ACTIVE JOBS", m.dashboard.ActiveJobs, "background", cardWidth),
}
var rows []string
for i := 0; i < len(cards); i += columns {
end := min(i+columns, len(cards))
rows = append(rows, lipgloss.JoinHorizontal(lipgloss.Top, intersperse(cards[i:end], strings.Repeat(" ", cardGap))...))
}
stats := strings.Join(rows, "\n")
remaining := max(6, height-lipgloss.Height(stats)-1)
issues := m.renderIssues(width, remaining)
return stats + "\n" + issues
}
func (m *Model) statCard(label string, value int, note string, width int) string {
valueStyle := m.theme.brand.Copy().Bold(true)
body := m.theme.mutedText.Render(label) + "\n" + valueStyle.Render(fmt.Sprintf("%d", value)) + " " + m.theme.mutedText.Render(note)
return m.theme.panel.Width(width - 2).Height(3).Render(body)
}
func (m *Model) renderIssues(width, height int) string {
issues := append([]domain.HealthIssue(nil), m.dashboard.Issues...)
sort.SliceStable(issues, func(i, j int) bool { return severityRank(issues[i].Severity) > severityRank(issues[j].Severity) })
var rows []string
limit := max(1, height-3)
for i, issue := range issues {
if i >= limit {
break
}
marker := m.theme.mutedText.Render("●")
switch issue.Severity {
case domain.SeverityCritical:
marker = m.theme.statusBad.Render("●")
case domain.SeverityWarning:
marker = m.theme.statusWarn.Render("●")
default:
marker = m.theme.statusOK.Render("●")
}
rows = append(rows, marker+" "+truncate(issue.Title, width-10)+" "+m.theme.mutedText.Render(truncate(issue.Detail, max(0, width-len(issue.Title)-16))))
}
if len(rows) == 0 {
rows = []string{m.theme.statusOK.Render("✓ No urgent findings"), m.theme.mutedText.Render("Run a sync to refresh DNS and public certificate observations.")}
}
return m.panel("ACTION QUEUE", strings.Join(rows, "\n"), width, height)
}
func (m *Model) renderAccounts(width, height int) string {
values := m.filteredCredentials()
if len(values) == 0 {
return m.emptyState("No Cloudflare accounts", "Press a to add a scoped API token.", width, height)
}
header := row(width, []cell{{"LABEL", 28}, {"TOKEN", 18}, {"STATUS", 14}, {"CAPABILITIES", 40}})
rows := []string{m.theme.mutedText.Render(header)}
reserved := 0
if len(m.accounts) > 0 {
reserved = 4
}
limit := max(1, height-4-reserved)
start := viewportStart(m.rowOffset, limit, len(values))
for i := start; i < len(values) && i < start+limit; i++ {
value := values[i]
status := string(value.Status)
line := row(width, []cell{{value.Label, 28}, {string(value.Kind), 18}, {status, 14}, {strings.Join(value.Capabilities, ", "), 40}})
if i == m.rowOffset {
line = m.theme.selected.Width(width - 2).Render(line)
}
rows = append(rows, line)
}
if len(m.accounts) > 0 {
names := make([]string, 0, len(m.accounts))
for _, account := range m.accounts {
names = append(names, account.Name)
}
rows = append(rows, "", m.theme.panelTitle.Render(fmt.Sprintf("REMOTE ACCOUNTS · %d", len(m.accounts))), m.theme.mutedText.Render(truncate(strings.Join(names, " · "), max(1, width-6))))
}
return m.panel("CLOUDFLARE CONNECTIONS · a add · r sync", strings.Join(rows, "\n"), width, height)
}
func (m *Model) renderZones(width, height int) string {
values := m.filteredZones()
if len(values) == 0 {
return m.emptyState("No zones found", "Add an account or synchronize Cloudflare.", width, height)
}
header := row(width, []cell{{"ZONE", 32}, {"ACCOUNT", 24}, {"CONNECTION", 22}, {"STATUS", 14}, {"PLAN", 14}})
rows := []string{m.theme.mutedText.Render(header)}
limit := max(1, height-4)
start := viewportStart(m.zoneIndex, limit, len(values))
for i := start; i < len(values) && i < start+limit; i++ {
value := values[i]
line := row(width, []cell{{value.Name, 32}, {m.accountLabel(value.AccountID), 24}, {m.credentialLabel(value.PreferredCredentialID), 22}, {string(value.Status), 14}, {value.Plan, 14}})
if i == m.zoneIndex {
line = m.theme.selected.Width(width - 2).Render(line)
}
rows = append(rows, line)
}
return m.panel("ZONES · Enter open DNS · j/k select", strings.Join(rows, "\n"), width, height)
}
func (m *Model) accountLabel(id string) string {
for _, account := range m.accounts {
if account.ID == id {
return account.Name
}
}
return id
}
func (m *Model) credentialLabel(id string) string {
for _, credential := range m.credentials {
if credential.ID == id {
return credential.Label
}
}
return id
}
func (m *Model) renderDNS(width, height int) string {
zone, ok := m.selectedZone()
if !ok {
return m.emptyState("Select a zone", "Synchronize a Cloudflare account first.", width, height)
}
values := m.filteredRecords()
if len(values) == 0 {
return m.emptyState("No records in "+zone.Name, "Press n to create an A, AAAA, CNAME, TXT, MX, CAA, NS, or SRV record.", width, height)
}
header := row(width, []cell{{"TYPE", 8}, {"NAME", 34}, {"CONTENT", 42}, {"PROXY", 10}, {"TTL", 10}})
rows := []string{m.theme.mutedText.Render(header)}
limit := max(1, height-4)
start := 0
if m.recordIndex >= limit {
start = m.recordIndex - limit + 1
}
for i := start; i < len(values) && i < start+limit; i++ {
value := values[i]
proxy := "DNS only"
if value.Proxied {
proxy = "proxied"
}
ttl := fmt.Sprintf("%ds", value.TTL)
if value.TTL <= 1 {
ttl = "Auto"
}
line := row(width, []cell{{string(value.Type), 8}, {value.Name, 34}, {displayRecordContent(value), 42}, {proxy, 10}, {ttl, 10}})
if i == m.recordIndex {
line = m.theme.selected.Width(width - 2).Render(line)
}
if !value.Type.Editable() || value.Managed {
line = m.theme.mutedText.Render(line)
}
rows = append(rows, line)
}
title := fmt.Sprintf("DNS · %s · n new e edit d delete Ctrl+P proxy", zone.Name)
return m.panel(title, strings.Join(rows, "\n"), width, height)
}
func (m *Model) renderCertificates(width, height int) string {
values := m.filteredLineages()
if len(values) == 0 {
return m.emptyState("No certificates tracked", "Press n to issue a managed certificate or i to import PEM metadata.", width, height)
}
header := row(width, []cell{{"LINEAGE", 26}, {"ENV", 11}, {"STATUS", 11}, {"EXPIRES", 13}, {"ISSUER", 30}, {"IDENTIFIERS", 40}})
rows := []string{m.theme.mutedText.Render(header)}
limit := max(1, height-4)
start := viewportStart(m.rowOffset, limit, len(values))
for i := start; i < len(values) && i < start+limit; i++ {
value := values[i]
item := m.certificateItem(value.ID)
expires, issuer := "—", "—"
if item.Current != nil {
expires = item.Current.NotAfter.Local().Format("2006-01-02")
issuer = item.Current.Issuer
}
line := row(width, []cell{{value.Name, 26}, {item.Environment, 11}, {item.Status, 11}, {expires, 13}, {issuer, 30}, {strings.Join(value.Identifiers, ", "), 40}})
if i == m.rowOffset {
line = m.theme.selected.Width(width - 2).Render(line)
}
rows = append(rows, line)
}
return m.panel("CERTIFICATE INVENTORY · n issue u renew due i import x export d revoke", strings.Join(rows, "\n"), width, height)
}
func (m *Model) certificateItem(lineageID string) app.CertificateInventoryItem {
for _, item := range m.certificateItems {
if item.Lineage.ID == lineageID {
return item
}
}
for _, lineage := range m.lineages {
if lineage.ID == lineageID {
return app.CertificateInventoryItem{Lineage: lineage, Environment: "unknown", Status: "unknown"}
}
}
return app.CertificateInventoryItem{Environment: "unknown", Status: "unknown"}
}
func (m *Model) renderTLS(width, height int) string {
zone, ok := m.selectedZone()
if !ok {
return m.emptyState("No zone selected", "Cloudflare TLS settings are zone-specific.", width, height)
}
if !m.tlsSnapshotReadyForSelectedZone() {
detail := "A verified TLS snapshot has not loaded for this zone. Leave and reopen this view to retry."
if m.loading {
detail = "Loading a fresh, zone-bound Cloudflare TLS snapshot…"
}
return m.emptyState("TLS snapshot unavailable for "+zone.Name, detail, width, height)
}
value := func(enabled bool) string {
if enabled {
return m.theme.statusOK.Render("ENABLED")
}
return m.theme.mutedText.Render("DISABLED")
}
modeStyle := m.theme.statusOK
if m.tlsDraft.Mode == "flexible" || m.tlsDraft.Mode == "off" {
modeStyle = m.theme.statusWarn
}
body := m.theme.mutedText.Render("Cloudflare edge and origin controls are separate from your local Let’s Encrypt files.") + "\n" +
m.theme.mutedText.Render("Verified for "+zone.Name+" · loaded "+m.tlsSnapshotAt.Local().Format("Jan 02 15:04:05")) + "\n\n" +
row(width-8, []cell{{"Origin encryption mode", 34}, {modeStyle.Render(strings.ToUpper(m.tlsDraft.Mode)), 28}, {"m to cycle", 18}}) + "\n" +
row(width-8, []cell{{"Always Use HTTPS", 34}, {value(m.tlsDraft.AlwaysUseHTTPS), 28}, {"h to toggle", 18}}) + "\n" +
row(width-8, []cell{{"TLS 1.3", 34}, {value(m.tlsDraft.TLS13), 28}, {"t to toggle", 18}}) + "\n" +
row(width-8, []cell{{"Minimum TLS", 34}, {m.tlsDraft.MinimumTLS, 28}, {"v to cycle", 22}}) + "\n\n" +
m.theme.statusWarn.Render("Changes can interrupt proxied traffic. Review the diff, then press s to apply.")
edgeCertificates := m.filteredEdgeCertificates()
if len(edgeCertificates) > 0 {
body += "\n\n" + m.theme.panelTitle.Render("EDGE CERTIFICATE PACKS")
for _, certificate := range edgeCertificates {
expiry := "managed by Cloudflare"
if certificate.ExpiresAt != nil {
expiry = certificate.ExpiresAt.Local().Format("2006-01-02")
}
body += "\n" + row(width-8, []cell{{certificate.Type, 20}, {certificate.Status, 16}, {strings.Join(certificate.Hosts, ", "), 44}, {expiry, 18}})
}
}
return m.panel("CLOUDFLARE TLS · "+zone.Name, body, width, height)
}
func (m *Model) renderActivity(width, height int) string {
jobs, audit := m.filteredJobs(), m.filteredAudit()
if len(jobs) == 0 && len(audit) == 0 {
return m.emptyState("No activity yet", "Synchronization and certificate jobs will appear here.", width, height)
}
header := row(width, []cell{{"STATE", 14}, {"KIND", 24}, {"PROGRESS", 12}, {"MESSAGE", 48}, {"UPDATED", 20}})
rows := []string{m.theme.mutedText.Render(header)}
limit := max(1, height-4)
jobLimit := max(1, limit/2+1)
start := viewportStart(m.rowOffset, jobLimit, len(jobs))
for i := start; i < len(jobs) && i < start+jobLimit; i++ {
value := jobs[i]
line := row(width, []cell{{string(value.State), 14}, {value.Kind, 24}, {fmt.Sprintf("%d%%", value.Progress), 12}, {value.Message, 48}, {value.UpdatedAt.Local().Format("Jan 02 15:04"), 20}})
if i == m.rowOffset {
line = m.theme.selected.Width(width - 2).Render(line)
}
rows = append(rows, line)
}
if len(audit) > 0 {
rows = append(rows, "", m.theme.panelTitle.Render("AUDIT TRAIL"), m.theme.mutedText.Render(row(width, []cell{{"TIME", 18}, {"ACTION", 24}, {"RESOURCE", 34}, {"CHANGE", 56}})))
remaining := max(1, limit-len(rows)+2)
for i, event := range audit {
if i >= remaining {
break
}
rows = append(rows, row(width, []cell{{event.CreatedAt.Local().Format("Jan 02 15:04"), 18}, {event.Action, 24}, {event.ResourceID, 34}, {auditChange(event), 56}}))
}
}
return m.panel("DURABLE ACTIVITY & AUDIT", strings.Join(rows, "\n"), width, height)
}
func viewportStart(selected, limit, total int) int {
if limit <= 0 || total <= limit {
return 0
}
start := selected - limit + 1
if start < 0 {
start = 0
}
if start+limit > total {
start = total - limit
}
return start
}
func auditChange(event domain.AuditEvent) string {
compact := func(value []byte) string {
if len(value) == 0 {
return "∅"
}
var buffer bytes.Buffer
if json.Compact(&buffer, value) == nil {
return buffer.String()
}
return string(value)
}
return compact(event.Before) + " → " + compact(event.After)
}
func (m *Model) panel(title, body string, width, height int) string {
if height < 3 {
height = 3
}
return m.theme.panel.Width(max(8, width-2)).Height(max(1, height-2)).Render(m.theme.panelTitle.Render(title) + "\n" + body)
}
func (m *Model) emptyState(title, detail string, width, height int) string {
body := m.theme.brand.Render(title) + "\n\n" + m.theme.mutedText.Render(detail)
return m.theme.panel.Width(max(20, width-2)).Height(max(5, height-2)).Align(lipgloss.Center, lipgloss.Center).Render(body)
}
func (m *Model) renderUnlock() string {
title := "UNLOCK DOMAINOPS"
detail := "Enter your local vault password. It never leaves this machine."
if m.unlockFirst {
title = "CREATE LOCAL VAULT"
detail = "Protect Cloudflare tokens and private keys with a local password."
}
lines := []string{m.theme.brand.Render(title), "", m.theme.mutedText.Render(detail), ""}
labels := []string{"Password", "Confirm password"}
for i, input := range m.unlockInputs {
label := labels[i]
if i == m.unlockFocus {
label = m.theme.panelTitle.Render(label)
} else {
label = m.theme.mutedText.Render(label)
}
lines = append(lines, label, input.View(), "")
}
if m.err != nil {
lines = append(lines, m.theme.statusBad.Render("! "+m.err.Error()), "")
}
if m.busy {
lines = append(lines, m.theme.statusWarn.Render("Unlocking…"))
} else {
lines = append(lines, m.theme.mutedText.Render("Tab to move · Enter to continue · Ctrl+C to quit"))
}
modal := m.theme.modal.Width(min(62, m.width-8)).Render(strings.Join(lines, "\n"))
return m.theme.app.Width(m.width).Height(m.height).Render(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, modal))
}
func (m *Model) renderCredentialForm() string {
labels := []string{"Connection label", "Scoped API token", "Account ID (optional)"}
lines := []string{m.theme.brand.Render("ADD CLOUDFLARE CONNECTION"), "", m.theme.mutedText.Render("User tokens can discover multiple accounts. Add an Account ID only for account-owned tokens."), ""}
for i, input := range m.credentialInputs {
label := m.theme.mutedText.Render(labels[i])
if i == m.credentialFocus {
label = m.theme.panelTitle.Render(labels[i])
}
lines = append(lines, label, input.View(), "")
}
if m.err != nil {
lines = append(lines, m.theme.statusBad.Render("! "+m.err.Error()), "")
}
lines = append(lines, m.theme.mutedText.Render("Tab to move · Enter to verify and save · Esc to cancel"))
modal := m.theme.modal.Width(min(72, m.width-8)).Render(strings.Join(lines, "\n"))
return m.theme.app.Width(m.width).Height(m.height).Render(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, modal))
}
func (m *Model) renderRecordForm() string {
labels := []string{"Record type", "Name", "Content", "TTL", "Priority"}
title := "CREATE DNS RECORD"
if m.recordEditing {
title = "EDIT DNS RECORD"
}
lines := []string{m.theme.brand.Render(title), ""}
for i, input := range m.recordInputs {
label := m.theme.mutedText.Render(labels[i])
if i == m.recordFocus {
label = m.theme.panelTitle.Render(labels[i])
}
lines = append(lines, label, input.View())
}
proxy := m.theme.mutedText.Render("DNS only")
if m.recordProxied {
proxy = m.theme.statusOK.Render("Cloudflare proxied")
}
lines = append(lines, "", "Proxy: "+proxy+" "+m.theme.key.Render("Ctrl+P")+" toggle")
if m.err != nil {
lines = append(lines, "", m.theme.statusBad.Render("! "+m.err.Error()))
}
lines = append(lines, "", m.theme.mutedText.Render("Tab to move · Enter on Priority to review/apply · Esc to cancel"))
modal := m.theme.modal.Width(min(74, m.width-8)).Render(strings.Join(lines, "\n"))
return m.theme.app.Width(m.width).Height(m.height).Render(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, modal))
}
func (m *Model) renderCertificateForm() string {
var title string
var labels []string
switch m.certificateAction {
case "issue":
title = "ISSUE WILDCARD CERTIFICATES"
labels = []string{"Zones (local IDs or unique names)", "Environment", "Contact email", "Nested labels", "Key algorithm"}
case "import":
title = "IMPORT CERTIFICATE METADATA"
labels = []string{"PEM file", "Display name", "Zone"}
case "export":
title = "EXPORT CURRENT PEM FILES"
labels = []string{"Destination"}
case "revoke":
title = "REVOKE CERTIFICATE — IRREVERSIBLE"
labels = []string{"Environment", "Exact lineage name", "Reason code"}
case "renew":
title = "RENEW DUE CERTIFICATES"
labels = []string{"Environment"}
}
lines := []string{m.theme.brand.Render(title), ""}
for i, input := range m.certificateInputs {
label := m.theme.mutedText.Render(labels[i])
if i == m.certificateFocus {
label = m.theme.panelTitle.Render(labels[i])
}
lines = append(lines, label, input.View(), "")
}
if m.certificateAction == "issue" {
if zone, ok := m.zoneByID(m.certificateIssueZoneID); ok {
lines = append(lines, m.theme.mutedText.Render("Selected zone: "+zone.Name+" · local ID "+zone.ID), "")
}
terms := m.theme.mutedText.Render("not accepted")
if m.certificateAcceptTerms {
terms = m.theme.statusOK.Render("accepted")
}
production := m.theme.mutedText.Render("not confirmed")
if m.certificateConfirmProduction {
production = m.theme.statusWarn.Render("confirmed")
}
lines = append(lines,
"CA terms: "+terms+" "+m.theme.key.Render("Ctrl+T")+" toggle",
"Production: "+production+" "+m.theme.key.Render("Ctrl+P")+" toggle", "")
}
if m.certificateAction == "renew" {
production := m.theme.mutedText.Render("not confirmed")
if m.certificateConfirmProduction {
production = m.theme.statusWarn.Render("confirmed")
}
lines = append(lines, "Production: "+production+" "+m.theme.key.Render("Ctrl+P")+" toggle", "")
}
if m.certificateAction == "revoke" {
lines = append(lines,
m.theme.mutedText.Render("Expected exact name: ")+m.theme.panelTitle.Render(m.certificateExpectedName),
m.theme.statusWarn.Render("The CA revocation cannot be undone. Confirm by typing the exact lineage name."), "")
}
if m.err != nil {
lines = append(lines, m.theme.statusBad.Render("! "+m.err.Error()), "")
}
lines = append(lines, m.theme.mutedText.Render("Tab to move · Enter on final field to run · Esc to cancel"))
modal := m.theme.modal.Width(min(76, m.width-8)).Render(strings.Join(lines, "\n"))
return m.theme.app.Width(m.width).Height(m.height).Render(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, modal))
}
func (m *Model) renderDeleteConfirmation() string {
values := m.filteredRecords()
var detail string
if len(values) > 0 {
record := values[min(m.recordIndex, len(values)-1)]
detail = fmt.Sprintf("%s %s %s", record.Type, record.Name, record.Content)
}
return m.confirmation("DELETE DNS RECORD?", detail, "This change is sent immediately after a fresh remote read.")
}
func (m *Model) renderRecordConfirmation() string {
after := fmt.Sprintf("%s %s %s TTL=%d proxied=%t", m.recordDraft.Type, m.recordDraft.Name, displayRecordContent(m.recordDraft), m.recordDraft.TTL, m.recordDraft.Proxied)
detail := "Create\n " + after
if m.recordDraftEdit {
before := "current cached record"
for _, record := range m.records {
if record.ID == m.recordDraftID || record.ProviderID == m.recordDraftID {
before = fmt.Sprintf("%s %s %s TTL=%d proxied=%t", record.Type, record.Name, displayRecordContent(record), record.TTL, record.Proxied)
break
}
}
detail = "Before\n " + before + "\nAfter\n " + after
}
return m.confirmation("APPLY DNS CHANGE?", detail, "DomainOps will re-read the remote record and reject a concurrent change.")
}
func (m *Model) renderTLSConfirmation() string {
detail := fmt.Sprintf("Mode: %s → %s\nAlways HTTPS: %t → %t\nMinimum TLS: %s → %s\nTLS 1.3: %t → %t", m.tls.Mode, m.tlsDraft.Mode, m.tls.AlwaysUseHTTPS, m.tlsDraft.AlwaysUseHTTPS, m.tls.MinimumTLS, m.tlsDraft.MinimumTLS, m.tls.TLS13, m.tlsDraft.TLS13)
return m.confirmation("APPLY CLOUDFLARE TLS CHANGES?", detail, "A wrong origin mode can interrupt proxied traffic.")
}
func (m *Model) confirmation(title, detail, warning string) string {
body := m.theme.brand.Render(title) + "\n\n" + detail + "\n\n" + m.theme.statusWarn.Render(warning) + "\n\n" + m.theme.key.Render("y / Enter") + " apply " + m.theme.key.Render("n / Esc") + " cancel"
modal := m.theme.modal.Width(min(66, m.width-8)).Render(body)
return m.theme.app.Width(m.width).Height(m.height).Render(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, modal))
}
func (m *Model) renderHelp() string {
lines := []string{
m.theme.brand.Render("KEYBOARD REFERENCE"), "",
m.theme.key.Render("1…7") + " Navigate sections", m.theme.key.Render("j / k") + " Move selection",
m.theme.key.Render("/") + " Filter current view", m.theme.key.Render("Ctrl+K") + " Command palette",
m.theme.key.Render("r") + " Synchronize", m.theme.key.Render("a") + " Add Cloudflare connection",
m.theme.key.Render("n / e / d") + " New, edit, delete DNS record", m.theme.key.Render("?") + " Close this help",
m.theme.key.Render("n / u / i / x / d") + " Issue, renew due, import, export, revoke certificate",
"", m.theme.mutedText.Render("All operations are keyboard-accessible and safe over SSH."),
}
if m.recoveryBlocked {
lines = append(lines, "", m.theme.key.Render("R")+" Retry blocked crash recovery")
}
modal := m.theme.modal.Width(min(72, m.width-8)).Render(strings.Join(lines, "\n"))
return m.theme.app.Width(m.width).Height(m.height).Render(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, modal))
}
func (m *Model) renderPalette() string {
commands := paletteCommands()
lines := []string{m.theme.brand.Render("COMMAND PALETTE"), ""}
for i, command := range commands {
line := " " + command
if i == m.paletteIndex {
line = m.theme.selected.Width(48).Render("› " + command)
}
lines = append(lines, line)
}
lines = append(lines, "", m.theme.mutedText.Render("j/k select · Enter run · Esc close"))
modal := m.theme.modal.Width(min(58, m.width-8)).Render(strings.Join(lines, "\n"))
return m.theme.app.Width(m.width).Height(m.height).Render(lipgloss.Place(m.width, m.height, lipgloss.Center, lipgloss.Center, modal))
}
type cell struct {
value string
share int
}
func row(width int, cells []cell) string {
total := 0
for _, value := range cells {
total += value.share
}
if total == 0 {
return ""
}
available := max(1, width-len(cells)+1)
parts := make([]string, 0, len(cells))
used := 0
for i, value := range cells {
cellWidth := available * value.share / total
if i == len(cells)-1 {
cellWidth = available - used
}
used += cellWidth
text := truncate(stripLines(value.value), max(0, cellWidth-1))
parts = append(parts, text+strings.Repeat(" ", max(0, cellWidth-lipgloss.Width(text))))
}
return strings.Join(parts, " ")
}
func truncate(value string, width int) string {
if width <= 0 {
return ""
}
if lipgloss.Width(value) <= width {
return value
}
if width == 1 {
return "…"
}
runes := []rune(value)
for len(runes) > 0 && lipgloss.Width(string(runes))+1 > width {
runes = runes[:len(runes)-1]
}
return string(runes) + "…"
}
func stripLines(value string) string {
return strings.Join(strings.Fields(value), " ")
}
func intersperse(values []string, separator string) []string {
if len(values) <= 1 {
return values
}
result := make([]string, 0, len(values)*2-1)
for i, value := range values {
if i > 0 {
result = append(result, separator)
}
result = append(result, value)
}
return result
}
func severityRank(value domain.Severity) int {
switch value {
case domain.SeverityCritical:
return 3
case domain.SeverityWarning:
return 2
default:
return 1
}
}
+69
View File
@@ -0,0 +1,69 @@
package tui
import (
"image/color"
"charm.land/lipgloss/v2"
)
type theme struct {
bg color.Color
surface color.Color
surface2 color.Color
border color.Color
primary color.Color
secondary color.Color
text color.Color
muted color.Color
green color.Color
amber color.Color
red color.Color
app lipgloss.Style
header lipgloss.Style
brand lipgloss.Style
sidebar lipgloss.Style
nav lipgloss.Style
navActive lipgloss.Style
panel lipgloss.Style
panelTitle lipgloss.Style
mutedText lipgloss.Style
statusOK lipgloss.Style
statusWarn lipgloss.Style
statusBad lipgloss.Style
selected lipgloss.Style
modal lipgloss.Style
key lipgloss.Style
}
func newTheme() theme {
t := theme{
bg: lipgloss.Color("#0A0F1D"),
surface: lipgloss.Color("#11182A"),
surface2: lipgloss.Color("#172139"),
border: lipgloss.Color("#2A3858"),
primary: lipgloss.Color("#66E3D4"),
secondary: lipgloss.Color("#A78BFA"),
text: lipgloss.Color("#E8EEF8"),
muted: lipgloss.Color("#8190AA"),
green: lipgloss.Color("#6ED59A"),
amber: lipgloss.Color("#F3C969"),
red: lipgloss.Color("#FF7188"),
}
t.app = lipgloss.NewStyle().Background(t.bg).Foreground(t.text)
t.header = lipgloss.NewStyle().Background(t.surface).Foreground(t.text).Padding(0, 1)
t.brand = lipgloss.NewStyle().Foreground(t.primary).Bold(true)
t.sidebar = lipgloss.NewStyle().Background(t.surface).Foreground(t.muted).Padding(1, 1).BorderRight(true).BorderForeground(t.border)
t.nav = lipgloss.NewStyle().Foreground(t.muted).Padding(0, 1)
t.navActive = lipgloss.NewStyle().Background(t.surface2).Foreground(t.primary).Bold(true).Padding(0, 1)
t.panel = lipgloss.NewStyle().Background(t.surface).Foreground(t.text).Border(lipgloss.RoundedBorder()).BorderForeground(t.border).Padding(0, 1)
t.panelTitle = lipgloss.NewStyle().Foreground(t.primary).Bold(true)
t.mutedText = lipgloss.NewStyle().Foreground(t.muted)
t.statusOK = lipgloss.NewStyle().Foreground(t.green).Bold(true)
t.statusWarn = lipgloss.NewStyle().Foreground(t.amber).Bold(true)
t.statusBad = lipgloss.NewStyle().Foreground(t.red).Bold(true)
t.selected = lipgloss.NewStyle().Background(t.surface2).Foreground(t.text)
t.modal = lipgloss.NewStyle().Background(t.surface).Foreground(t.text).Border(lipgloss.DoubleBorder()).BorderForeground(t.secondary).Padding(1, 2)
t.key = lipgloss.NewStyle().Background(t.surface2).Foreground(t.primary).Padding(0, 1)
return t
}