This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch tui-mcp-CAMEL-23606 in repository https://gitbox.apache.org/repos/asf/camel.git
commit cdf8ae0c83a504bd043463cf02b823d53669ac9a Author: Claus Ibsen <[email protected]> AuthorDate: Sun May 24 22:34:02 2026 +0200 CAMEL-23606: camel-tui - MCP caption auto-dismiss with non-blocking duration Co-Authored-By: Claude Opus 4.6 <[email protected]> --- .../dsl/jbang/core/commands/tui/CamelMonitor.java | 4 ++++ .../jbang/core/commands/tui/CaptionOverlay.java | 28 +++++++++++++++++++++- .../dsl/jbang/core/commands/tui/TuiMcpServer.java | 13 +++++++++- 3 files 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 552f55752413..4e5e8597ee3f 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 @@ -3080,6 +3080,10 @@ public class CamelMonitor extends CamelCommand { captionOverlay.showCaption(text); } + void showCaption(String text, int durationSeconds) { + captionOverlay.showCaption(text, durationSeconds); + } + String navigateToTab(String tabName) { for (int i = 0; i < TAB_NAMES.length; i++) { if (TAB_NAMES[i].equalsIgnoreCase(tabName)) { diff --git a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CaptionOverlay.java b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CaptionOverlay.java index 24050181509a..eb315794e93b 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CaptionOverlay.java +++ b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CaptionOverlay.java @@ -56,6 +56,7 @@ class CaptionOverlay { private String captionText; private long captionStartTime; private long captionFullyTypedTime; + private long captionAutoDismissTime; boolean isInputVisible() { return showInput; @@ -91,6 +92,18 @@ class CaptionOverlay { captionText = text; captionStartTime = System.currentTimeMillis(); captionFullyTypedTime = 0; + captionAutoDismissTime = 0; + } + + void showCaption(String text, int durationSeconds) { + captionText = text; + captionStartTime = System.currentTimeMillis(); + captionFullyTypedTime = 0; + if (durationSeconds > 0) { + captionAutoDismissTime = System.currentTimeMillis() + (durationSeconds * 1000L); + } else { + captionAutoDismissTime = 0; + } } void close() { @@ -150,6 +163,9 @@ class CaptionOverlay { return true; } if (captionText != null) { + if (captionAutoDismissTime > 0) { + return false; + } captionText = null; captionFullyTypedTime = 0; return true; @@ -166,6 +182,14 @@ class CaptionOverlay { if (captionText == null || inlineMode) { return; } + + if (captionAutoDismissTime > 0 && now > captionAutoDismissTime) { + captionText = null; + captionFullyTypedTime = 0; + captionAutoDismissTime = 0; + return; + } + int totalChars = captionText.length(); long elapsed = now - captionStartTime; int charsToShow = (int) (elapsed / CHAR_DELAY_MS); @@ -173,7 +197,9 @@ class CaptionOverlay { if (charsToShow >= totalChars && captionFullyTypedTime == 0) { captionFullyTypedTime = now; } - if (captionFullyTypedTime > 0 && now - captionFullyTypedTime > HOLD_DURATION_MS + FADE_DURATION_MS) { + if (captionAutoDismissTime == 0 + && captionFullyTypedTime > 0 + && now - captionFullyTypedTime > HOLD_DURATION_MS + FADE_DURATION_MS) { captionText = null; captionFullyTypedTime = 0; } diff --git a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TuiMcpServer.java b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TuiMcpServer.java index 0e6e92080529..914b22311f4e 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TuiMcpServer.java +++ b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TuiMcpServer.java @@ -219,7 +219,10 @@ class TuiMcpServer { "Shows a caption message on the TUI screen with a typewriter animation. " + "Use this to display messages to the user. " + "Supports \\n for newlines.", - Map.of("text", propDef("string", "The caption text to display")), + Map.of("text", propDef("string", "The caption text to display"), + "duration", propDef("integer", + "Auto-dismiss after this many seconds. Caption won't block key events. " + + "If omitted, caption stays until dismissed by a key press.")), List.of("text"))); toolList.add(toolDef( "tui_navigate", @@ -357,6 +360,14 @@ class TuiMcpServer { if (text == null || text.isBlank()) { return "Error: text is required"; } + Object durationArg = args.get("duration"); + if (durationArg instanceof Number n) { + int duration = n.intValue(); + if (duration > 0) { + monitor.showCaption(text, duration); + return "Caption displayed (auto-dismiss in " + duration + "s): " + text; + } + } monitor.showCaption(text); return "Caption displayed: " + text; }
