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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 2e5314f56ebe camel-tui: Syntax highlighting in edit mode
2e5314f56ebe is described below

commit 2e5314f56ebe1658d7cfb392a7b2ec5d19f9de6b
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Aug 14 08:58:40 2026 +0200

    camel-tui: Syntax highlighting in edit mode
    
    Apply syntax highlighting as a post-render buffer overlay after
    TextArea renders plain text. Patches foreground colors cell-by-cell
    using SyntaxHighlighter output, preserving cursor reversed style
    and composing with zebra/scope/gutter overlays. Supports YAML,
    Java, XML, and Properties with the Monokai palette.
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../dsl/jbang/core/commands/tui/SourceViewer.java  | 53 ++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceViewer.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceViewer.java
index 4e38a8a5a81e..91b21564f0e1 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceViewer.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/SourceViewer.java
@@ -2416,6 +2416,8 @@ class SourceViewer {
                 .build();
         textArea.renderWithCursor(editorArea, frame.buffer(), editState, 
frame);
 
+        applySyntaxHighlightOverlay(frame, editorArea);
+
         // cursor line highlight
         int cursorRelRow = editState.cursorRow() - editState.scrollRow();
         if (cursorRelRow >= 0 && cursorRelRow < editorArea.height()) {
@@ -2506,6 +2508,57 @@ class SourceViewer {
         }
     }
 
+    private void applySyntaxHighlightOverlay(Frame frame, Rect editorArea) {
+        if (language == SyntaxHighlighter.Language.PLAIN) {
+            return;
+        }
+        int gutterWidth = plainMode
+                ? 0
+                : Math.max(2, String.valueOf(editState.lineCount()).length()) 
+ 2;
+        int contentStartX = editorArea.left() + gutterWidth;
+        int scrollCol = editState.scrollCol();
+        int rightEdge = editorArea.right();
+
+        for (int row = 0; row < editorArea.height(); row++) {
+            int lineIdx = editState.scrollRow() + row;
+            if (lineIdx >= editState.lineCount()) {
+                break;
+            }
+            String lineText = editState.getLine(lineIdx);
+            if (lineText.isEmpty()) {
+                continue;
+            }
+            Line highlighted = SyntaxHighlighter.highlightLine(lineText, 
language);
+            int screenY = editorArea.top() + row;
+            int textCol = 0;
+            for (Span span : highlighted.spans()) {
+                Style spanStyle = span.style();
+                boolean hasStyle = spanStyle != null && 
!Style.EMPTY.equals(spanStyle);
+                String content = span.content();
+                for (int c = 0; c < content.length(); c++) {
+                    int col = textCol + c;
+                    if (col < scrollCol) {
+                        continue;
+                    }
+                    int screenX = contentStartX + (col - scrollCol);
+                    if (screenX >= rightEdge) {
+                        break;
+                    }
+                    if (hasStyle) {
+                        dev.tamboui.buffer.Cell cell = 
frame.buffer().get(screenX, screenY);
+                        if (cell != null && !cell.isContinuation()) {
+                            frame.buffer().set(screenX, screenY, 
cell.patchStyle(spanStyle));
+                        }
+                    }
+                }
+                textCol += content.length();
+                if (contentStartX + (textCol - scrollCol) >= rightEdge) {
+                    break;
+                }
+            }
+        }
+    }
+
     private void renderDiffContent(Frame frame, Rect inner) {
         List<String> orig = YamlBlockEditor.toLines(originalEditText);
         List<EditDiff.DiffEntry> entries = EditDiff.unifiedDiff(orig, 
editLines(), 3);

Reply via email to