This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch CAMEL-23514-ascii-diagram-metrics in repository https://gitbox.apache.org/repos/asf/camel.git
commit 645ed05340142aaf5dcad6174486dd848915c36c Author: Claus Ibsen <[email protected]> AuthorDate: Thu May 14 10:18:27 2026 +0200 CAMEL-23514: Fix counter color positions after empty line removal Counter positions from the ASCII renderer use original grid row numbers, but empty lines are filtered out when building diagramLines. Remap the row indices to account for removed lines so counter coloring matches the correct positions in the TUI. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../dsl/jbang/core/commands/tui/CamelMonitor.java | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 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 fe6d9cc64e20..f32c018f21a4 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 @@ -1407,11 +1407,26 @@ public class CamelMonitor extends CamelCommand { RouteDiagramAsciiRenderer asciiRenderer = new RouteDiagramAsciiRenderer( RouteDiagramLayoutEngine.DEFAULT_BOX_WIDTH * RouteDiagramLayoutEngine.SCALE, true, metrics); String ascii = asciiRenderer.renderDiagram(layoutRoutes, currentY); - List<RouteDiagramAsciiRenderer.CounterPos> positions = new ArrayList<>(asciiRenderer.getCounterPositions()); + List<RouteDiagramAsciiRenderer.CounterPos> origPositions = asciiRenderer.getCounterPositions(); + + // Build result lines, remapping counter positions to account for removed empty lines + String[] rawLines = ascii.split("\n", -1); List<String> result = new ArrayList<>(); - for (String line : ascii.split("\n", -1)) { - if (!line.isEmpty()) { - result.add(line); + int[] rowMapping = new int[rawLines.length]; + int newRow = 0; + for (int i = 0; i < rawLines.length; i++) { + if (!rawLines[i].isEmpty()) { + rowMapping[i] = newRow++; + result.add(rawLines[i]); + } else { + rowMapping[i] = -1; + } + } + List<RouteDiagramAsciiRenderer.CounterPos> positions = new ArrayList<>(); + for (RouteDiagramAsciiRenderer.CounterPos cp : origPositions) { + if (cp.row() >= 0 && cp.row() < rowMapping.length && rowMapping[cp.row()] >= 0) { + positions.add(new RouteDiagramAsciiRenderer.CounterPos( + rowMapping[cp.row()], cp.col(), cp.length(), cp.type())); } } applyDiagramResult(routeId, result, null, null, null, positions);
