Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: show ansi colors in log viewer
Kyle Mendella6be63d70d55
diff --git a/backend/internal/utils/notifications/email_util.go b/backend/internal/utils/notifications/email_util.goindex 480430753..9d548f4b6 100644--- a/backend/internal/utils/notifications/email_util.go+++ b/backend/internal/utils/notifications/email_util.go@@ -169,25 +169,6 @@ func SanitizeForEmail(s string) string {return string(safe)}-// BuildSimpleMessage constructs a simple email message with headers-func BuildSimpleMessage(fromAddress string, toAddresses []string, subject string, body string) string {- var buf bytes.Buffer-- // Add headers- buf.WriteString(fmt.Sprintf("From: %s\r\n", fromAddress))- buf.WriteString(fmt.Sprintf("To: %s\r\n", strings.Join(toAddresses, ", ")))- buf.WriteString(fmt.Sprintf("Subject: %s\r\n", subject))- buf.WriteString(fmt.Sprintf("Date: %s\r\n", time.Now().Format(time.RFC1123Z)))- buf.WriteString("MIME-Version: 1.0\r\n")- buf.WriteString("Content-Type: text/plain; charset=UTF-8\r\n")- buf.WriteString("\r\n")-- // Add body- buf.WriteString(body)-- return buf.String()-}-// BuildMultipartMessage constructs a MIME multipart email message with both HTML and text partsfunc BuildMultipartMessage(fromAddress string, toAddresses []string, subject string, htmlBody string, textBody string) string {var buf bytes.Bufferdiff --git a/backend/internal/utils/ws/ansi.go b/backend/internal/utils/ws/ansi.godeleted file mode 100644index bc714c855..000000000--- a/backend/internal/utils/ws/ansi.go+++ /dev/null@@ -1,13 +0,0 @@-package ws--import "regexp"--var ansiRegexp = regexp.MustCompile(`\x1B\[[0-?]*[ -/]*[@-~]|\x1B\][^\x07\x1B]*(\x07|\x1B\\)|\x1B[@-_]`)--// StripANSI removes ANSI color / control escape sequences.-func StripANSI(s string) string {- if s == "" {- return s- }- return ansiRegexp.ReplaceAllString(s, "")-}diff --git a/backend/internal/utils/ws/parse.go b/backend/internal/utils/ws/parse.goindex 7bdaf9c1c..1ba373062 100644--- a/backend/internal/utils/ws/parse.go+++ b/backend/internal/utils/ws/parse.go@@ -14,7 +14,7 @@ var (// NormalizeContainerLine parses a raw container log line into level + cleaned message.// It extracts Docker's timestamp if present (when timestamps=true in Docker API).func NormalizeContainerLine(raw string) (level string, msg string, timestamp string) {- line := StripANSI(strings.TrimRight(raw, "\r\n"))+ line := strings.TrimRight(raw, "\r\n")level = "stdout"switch {diff --git a/frontend/package.json b/frontend/package.jsonindex ab60421bb..b0257110b 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -28,6 +28,7 @@"@uiw/codemirror-themes": "^4.25.2","@xterm/addon-fit": "^0.10.0","@xterm/xterm": "^5.5.0",+ "ansi-to-html": "^0.7.2","axios": "^1.13.1","codemirror": "^6.0.2","date-fns": "^4.1.0",diff --git a/frontend/src/lib/components/logs/log-viewer.svelte b/frontend/src/lib/components/logs/log-viewer.svelteindex 4472a1a80..65529ff60 100644--- a/frontend/src/lib/components/logs/log-viewer.svelte+++ b/frontend/src/lib/components/logs/log-viewer.svelte@@ -4,6 +4,7 @@import { m } from '$lib/paraglide/messages';import { ReconnectingWebSocket } from '$lib/utils/ws';import { cn } from '$lib/utils';+ import { ansiToHtml } from '$lib/utils/ansi';import { onDestroy } from 'svelte';interface LogEntry {@@ -408,7 +409,7 @@</span></div><div class="text-sm break-words whitespace-pre-wrap text-gray-300">- {log.message}+ {@html ansiToHtml(log.message)}</div></div>@@ -428,7 +429,7 @@{log.level.toUpperCase()}</span><span class="flex-1 break-words whitespace-pre-wrap text-gray-300">- {log.message}+ {@html ansiToHtml(log.message)}</span></div>{/each}diff --git a/frontend/src/lib/utils/ansi.ts b/frontend/src/lib/utils/ansi.tsnew file mode 100644index 000000000..ce0cf8647--- /dev/null+++ b/frontend/src/lib/utils/ansi.ts@@ -0,0 +1,32 @@+import Convert from 'ansi-to-html';++const converter = new Convert({+ fg: '#e4e4e7',+ bg: '#000000',+ newline: false,+ escapeXML: true,+ stream: false,+ colors: {+ 0: '#18181b',+ 1: '#ef4444',+ 2: '#22c55e',+ 3: '#eab308',+ 4: '#3b82f6',+ 5: '#a855f7',+ 6: '#06b6d4',+ 7: '#f4f4f5',+ 8: '#71717a',+ 9: '#f87171',+ 10: '#4ade80',+ 11: '#facc15',+ 12: '#60a5fa',+ 13: '#c084fc',+ 14: '#22d3ee',+ 15: '#fafafa'+ }+});++export function ansiToHtml(text: string): string {+ if (!text) return '';+ return converter.toHtml(text);+}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 31a5a54e5..7264ae249 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -91,6 +91,9 @@ importers:'@xterm/xterm':specifier: ^5.5.0version: 5.5.0+ ansi-to-html:+ specifier: ^0.7.2+ version: 0.7.2axios:specifier: ^1.13.1version: 1.13.1@@ -2156,6 +2159,11 @@ packages:resolution: {integrity: sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg==}engines: {node: '>=12'}+ resolution: {integrity: sha512-v6MqmEpNlxF+POuyhKkidusCHWWkaLcGRURzivcU3I9tv7k4JVhFcnukrM5Rlk2rUywdZuzYAZ+kbZqWCnfN3g==}+ engines: {node: '>=8.0.0'}+ hasBin: true+resolution: {integrity: sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==}@@ -2555,6 +2563,9 @@ packages:resolution: {integrity: sha512-d4lC8xfavMeBjzGr2vECC3fsGXziXZQyJxD868h2M/mBI3PwAuODxAkLkq5HYuvrPYcUtiLzsTo8U3PgX3Ocww==}engines: {node: '>=10.13.0'}+ resolution: {integrity: sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==}+resolution: {integrity: sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==}engines: {node: '>=0.12'}@@ -6363,6 +6374,10 @@ snapshots:+ dependencies:+ entities: 2.2.0+@@ -6759,6 +6774,8 @@ snapshots:graceful-fs: 4.2.11tapable: 2.3.0+ [email protected]: {}+