This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch worktree-more-tui-2
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 3d66db215ca3bc4acbdf92023ec03a6ddb05bda6
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue May 19 15:46:41 2026 +0200

    camel-jbang - Unescape JSON values in TUI inspect tab to avoid rendering 
garbage characters
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
---
 .../dsl/jbang/core/commands/tui/CamelMonitor.java  | 45 +++++++++++++++++++++-
 1 file changed, 43 insertions(+), 2 deletions(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitor.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitor.java
index 7bd985e0b4aa..3d85f0d82e6b 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitor.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitor.java
@@ -4303,11 +4303,18 @@ public class CamelMonitor extends CamelCommand {
             } else {
                 typeLabel = String.format("%-21s", "");
             }
+            String val = entry.getValue() != null ? 
entry.getValue().toString() : "null";
+            try {
+                val = Jsoner.unescape(val);
+            } catch (Exception e) {
+                // ignore
+            }
+            val = stripControlChars(val);
             lines.add(Line.from(
                     Span.styled("   " + typeLabel, Style.EMPTY.dim()),
                     Span.styled(entry.getKey(), Style.EMPTY.fg(Color.CYAN)),
                     Span.raw(" = "),
-                    Span.raw(entry.getValue() != null ? 
entry.getValue().toString() : "null")));
+                    Span.raw(val)));
         }
         lines.add(Line.from(Span.raw("")));
     }
@@ -4321,9 +4328,14 @@ public class CamelMonitor extends CamelCommand {
             } else {
                 lines.add(Line.from(Span.styled(" Body:", 
Style.EMPTY.fg(Color.GREEN).bold())));
             }
+            try {
+                body = Jsoner.unescape(body);
+            } catch (Exception e) {
+                // ignore
+            }
             String[] bodyParts = body.split("\n");
             for (String bl : bodyParts) {
-                lines.add(Line.from(Span.raw("   " + bl)));
+                lines.add(Line.from(Span.raw("   " + stripControlChars(bl))));
             }
         } else {
             lines.add(Line.from(Span.styled(" Body is null", 
Style.EMPTY.fg(Color.GREEN).bold())));
@@ -4331,6 +4343,35 @@ public class CamelMonitor extends CamelCommand {
         lines.add(Line.from(Span.raw("")));
     }
 
+    private static String stripControlChars(String s) {
+        if (s == null) {
+            return s;
+        }
+        boolean needsStrip = false;
+        for (int i = 0; i < s.length(); i++) {
+            char ch = s.charAt(i);
+            if (ch < 0x20 || (ch >= 0x7F && ch <= 0x9F)) {
+                needsStrip = true;
+                break;
+            }
+        }
+        if (!needsStrip) {
+            return s;
+        }
+        StringBuilder sb = new StringBuilder(s.length());
+        for (int i = 0; i < s.length(); i++) {
+            char ch = s.charAt(i);
+            if (ch == '\t') {
+                sb.append("    ");
+            } else if (ch < 0x20 || (ch >= 0x7F && ch <= 0x9F)) {
+                // skip C0 and C1 control chars
+            } else {
+                sb.append(ch);
+            }
+        }
+        return sb.toString();
+    }
+
     private static void addExceptionLines(List<Line> lines, String exception) {
         if (exception == null) {
             return;

Reply via email to