package statusview import ( "git.a-wan.net/alan/pipelines/internal/protocol" "net" "net/url" "strings" ) func Offline(endpoint string) *protocol.SystemStatus { s := &protocol.SystemStatus{Server: protocol.ServiceStatus{Health: "unreachable"}, Ntfy: protocol.ServiceStatus{Health: "unknown (server unavailable)"}} if u, err := url.Parse(endpoint); err == nil { s.Server.Port = u.Port() } return s } func ServerLines(s *protocol.SystemStatus) []string { if s == nil { return []string{"Checking server…"} } lines := []string{"Status: " + s.Server.Health} seen := map[string]bool{} for _, address := range s.Addresses { ip := net.ParseIP(strings.Split(address.IP, "%")[0]) if ip == nil || ip.IsLoopback() || ip.IsUnspecified() || ip.IsLinkLocalUnicast() || seen[address.IP] { continue } seen[address.IP] = true lines = append(lines, net.JoinHostPort(address.IP, s.Server.Port)) if len(seen) == 6 { break } } if len(seen) == 0 { lines = append(lines, "LAN address unavailable.", "For Docker: rerun ./install on the server.") } if s.Server.Port != "" { lines = append(lines, "Port: "+s.Server.Port) } return lines } func NtfyLines(s *protocol.SystemStatus) []string { if s == nil { return []string{"Checking ntfy…"} } lines := []string{"Status: " + s.Ntfy.Health} if s.Ntfy.URL != "" { lines = append(lines, "Server: "+s.Ntfy.URL) } if s.Topic != "" { lines = append(lines, "Topic: "+s.Topic) } if s.NtfyUser != "" { lines = append(lines, "Login: "+s.NtfyUser, "Use the password set during installation.") } if s.Ntfy.Health == "not configured" { lines = append(lines, "The connected Pipelines server has no ntfy publishing configuration.", "For Docker: check docker compose port pipelines 8080.", "Connect the TUI to that port; check --url / PIPELINES_URL.", "If this is the intended server: run ./install there.") } else if s.Ntfy.Health == "unreachable" || s.Ntfy.Health == "unhealthy" { lines = append(lines, "On the server: docker compose logs ntfy") } return lines } // The human view has exactly two focused sections. --json retains full data. func Lines(s *protocol.SystemStatus) []string { lines := append([]string{"Pipelines server"}, ServerLines(s)...) return append(append(lines, "", "ntfy"), NtfyLines(s)...) }