This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch fix/camel-tui-tamboui-improvements in repository https://gitbox.apache.org/repos/asf/camel.git
commit 322da2bb5f53277e9471538e6772316ae906fa55 Author: Claus Ibsen <[email protected]> AuthorDate: Fri May 15 17:27:56 2026 +0200 CAMEL-23514: Consolidate duplicated sort helpers, formatSinceLast, and colorStyleForLevel - Extract generic sortLabel()/sortStyle() called by all three sort-column pairs - Collapse formatSinceLast(IntegrationInfo) and formatSinceLastRoute(RouteInfo) into shared formatSinceLast(String, String, String) primitive - Use existing colorStyleForLevel() in log table row loop instead of inline switch Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --- .../dsl/jbang/core/commands/tui/CamelMonitor.java | 66 +++++++++------------- 1 file changed, 26 insertions(+), 40 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 e6422621246b..0df113011781 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 @@ -1086,13 +1086,11 @@ public class CamelMonitor extends CamelCommand { } private String overviewSortLabel(String label, String column) { - return overviewSort.equals(column) ? label + "▼" : label; + return sortLabel(label, column, overviewSort); } private Style overviewSortStyle(String column) { - return overviewSort.equals(column) - ? Style.EMPTY.fg(Color.YELLOW).bold() - : Style.EMPTY.bold(); + return sortStyle(column, overviewSort); } private int sortRoute(RouteInfo a, RouteInfo b) { @@ -1114,21 +1112,27 @@ public class CamelMonitor extends CamelCommand { } private String traceSortLabel(String label, String column) { - return traceSort.equals(column) ? label + "▼" : label; + return sortLabel(label, column, traceSort); } private Style traceSortStyle(String column) { - return traceSort.equals(column) - ? Style.EMPTY.fg(Color.YELLOW).bold() - : Style.EMPTY.bold(); + return sortStyle(column, traceSort); } private String routeSortLabel(String label, String column) { - return routeSort.equals(column) ? label + "\u25BC" : label; + return sortLabel(label, column, routeSort); } private Style routeSortStyle(String column) { - return routeSort.equals(column) + return sortStyle(column, routeSort); + } + + private static String sortLabel(String label, String column, String currentSort) { + return currentSort.equals(column) ? label + "▼" : label; + } + + private static Style sortStyle(String column, String currentSort) { + return currentSort.equals(column) ? Style.EMPTY.fg(Color.YELLOW).bold() : Style.EMPTY.bold(); } @@ -1911,13 +1915,7 @@ public class CamelMonitor extends CamelCommand { // Log table List<Row> rows = new ArrayList<>(); for (LogEntry entry : filteredLogEntries) { - Style levelStyle = switch (entry.level) { - case "ERROR", "FATAL" -> Style.EMPTY.fg(Color.RED); - case "WARN" -> Style.EMPTY.fg(Color.YELLOW); - case "DEBUG", "TRACE" -> Style.EMPTY.dim(); - default -> Style.EMPTY; - }; - + Style levelStyle = colorStyleForLevel(entry.level); rows.add(Row.from( Cell.from(Span.styled(entry.time, Style.EMPTY.dim())), Cell.from(Span.styled(entry.level, levelStyle)), @@ -2848,23 +2846,7 @@ public class CamelMonitor extends CamelCommand { } private static String formatSinceLastRoute(RouteInfo route) { - StringBuilder sb = new StringBuilder(); - if (route.sinceLastStarted != null) { - sb.append(route.sinceLastStarted); - } - if (route.sinceLastCompleted != null) { - if (!sb.isEmpty()) { - sb.append('/'); - } - sb.append(route.sinceLastCompleted); - } - if (route.sinceLastFailed != null) { - if (!sb.isEmpty()) { - sb.append('/'); - } - sb.append(route.sinceLastFailed); - } - return sb.toString(); + return formatSinceLast(route.sinceLastStarted, route.sinceLastCompleted, route.sinceLastFailed); } private static Cell rightCell(String text, int width) { @@ -3664,21 +3646,25 @@ public class CamelMonitor extends CamelCommand { } private static String formatSinceLast(IntegrationInfo info) { + return formatSinceLast(info.sinceLastStarted, info.sinceLastCompleted, info.sinceLastFailed); + } + + private static String formatSinceLast(String started, String completed, String failed) { StringBuilder sb = new StringBuilder(); - if (info.sinceLastStarted != null) { - sb.append(info.sinceLastStarted); + if (started != null) { + sb.append(started); } - if (info.sinceLastCompleted != null) { + if (completed != null) { if (!sb.isEmpty()) { sb.append('/'); } - sb.append(info.sinceLastCompleted); + sb.append(completed); } - if (info.sinceLastFailed != null) { + if (failed != null) { if (!sb.isEmpty()) { sb.append('/'); } - sb.append(info.sinceLastFailed); + sb.append(failed); } return sb.toString(); }
