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 098317196cd2 CAMEL-23838: Fix camel-jbang TUI help (F1/? broken)
098317196cd2 is described below

commit 098317196cd2c9a53d1ca20b9f64c0b08ea696de
Author: Adriano Machado <[email protected]>
AuthorDate: Sun Jun 28 02:46:01 2026 -0400

    CAMEL-23838: Fix camel-jbang TUI help (F1/? broken)
    
    Fix two problems with context-sensitive help in camel tui:
    
    1. F1 threw NoClassDefFoundError because camel-launcher's flat classpath
       had commonmark 0.21.0 core (from openapi-generator) alongside 0.28.0
       extensions (from tamboui-markdown). Pin commonmark to 0.28.0 in
       camel-launcher so the core matches the extensions.
    
    2. The ? key was not bound to open help. Bind ? to toggle help in
       CamelMonitor (guarded against text input focus) and let HelpOverlay
       close on ? as well. Extract opensHelp() for testability and add tests.
    
    Closes #24277
    Co-Authored-By: Claude Opus 4.8 <[email protected]>
---
 .../modules/ROOT/pages/camel-jbang-tui.adoc        |  4 +-
 .../dsl/jbang/core/commands/tui/CamelMonitor.java  | 26 +++++---
 .../dsl/jbang/core/commands/tui/HelpOverlay.java   |  4 +-
 .../jbang/core/commands/tui/CamelMonitorTest.java  | 53 ++++++++++++++++
 .../jbang/core/commands/tui/HelpOverlayTest.java   | 72 ++++++++++++++++++++++
 dsl/camel-jbang/camel-launcher/pom.xml             | 20 ++++++
 6 files changed, 165 insertions(+), 14 deletions(-)

diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang-tui.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-jbang-tui.adoc
index bc77fe6ebddc..bfe2225b3b38 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-tui.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-tui.adoc
@@ -58,7 +58,7 @@ If an example requires infrastructure (like Kafka or a 
database), the TUI automa
 required Docker containers before launching the example. A notification in the 
footer shows the
 progress.
 
-TIP: Press *F1* on any screen for context-sensitive help.
+TIP: Press *F1* or *?* on any screen for context-sensitive help.
 Keyboard shortcuts are always shown in the footer bar.
 
 == Tabs Overview
@@ -313,7 +313,7 @@ The Doctor checks your development environment and reports 
issues:
 
 | *1* - *0* | Jump to tab by number
 | *Tab* / *Shift+Tab* | Next / previous tab
-| *F1* | Context-sensitive help (toggle)
+| *F1* / *?* | Context-sensitive help (toggle)
 | *F2* | Actions menu
 | *F3* | Switch between integrations (when multiple running)
 | *Shift+F5* | Take screenshot
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 adb40965dca7..e9113704af78 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
@@ -610,16 +610,14 @@ public class CamelMonitor extends CamelCommand {
             takeScreenshot();
             return true;
         }
-        if (ke.isKey(KeyCode.F1)) {
-            if (helpOverlay.isVisible()) {
-                helpOverlay.close();
-            } else {
-                MonitorTab tab = activeTab();
-                if (tab != null) {
-                    String help = tab.getHelpText();
-                    if (help != null) {
-                        helpOverlay.open(help);
-                    }
+        if (opensHelp(ke, textEditing)) {
+            // Only opens the overlay: while it is visible, dispatch delegates 
to
+            // helpOverlay.handleKeyEvent (which handles F1/?/q/Esc to close) 
before reaching here.
+            MonitorTab tab = activeTab();
+            if (tab != null) {
+                String help = tab.getHelpText();
+                if (help != null) {
+                    helpOverlay.open(help);
                 }
             }
             return true;
@@ -655,6 +653,14 @@ public class CamelMonitor extends CamelCommand {
         return false;
     }
 
+    /**
+     * Whether the key event should open the help overlay. F1 always opens it; 
'?' opens it too, but only when no text
+     * input is focused, so the character is not swallowed while the user is 
typing in a search or probe field.
+     */
+    static boolean opensHelp(KeyEvent ke, boolean textEditing) {
+        return ke.isKey(KeyCode.F1) || (!textEditing && ke.isChar('?'));
+    }
+
     private boolean handleTabKeys(KeyEvent ke) {
         MonitorTab activeTab = activeTab();
 
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HelpOverlay.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HelpOverlay.java
index cdc025205011..d242b30b0ae9 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HelpOverlay.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HelpOverlay.java
@@ -59,7 +59,7 @@ class HelpOverlay {
         if (!visible) {
             return false;
         }
-        if (ke.isCancel() || ke.isChar('q') || ke.isKey(KeyCode.F1)) {
+        if (ke.isCancel() || ke.isChar('q') || ke.isChar('?') || 
ke.isKey(KeyCode.F1)) {
             close();
             return true;
         }
@@ -94,7 +94,7 @@ class HelpOverlay {
                 .borderType(BorderType.ROUNDED)
                 .title(" Help ")
                 .titleBottom(Title.from(Line.from(
-                        Span.styled(" F1", MonitorContext.HINT_KEY_STYLE), 
Span.raw(" close "),
+                        Span.styled(" F1/?", MonitorContext.HINT_KEY_STYLE), 
Span.raw(" close "),
                         Span.styled(" ↑↓", MonitorContext.HINT_KEY_STYLE), 
Span.raw(" scroll "))))
                 .build();
 
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitorTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitorTest.java
new file mode 100644
index 000000000000..9aa48bbc87bc
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/CamelMonitorTest.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.tui;
+
+import dev.tamboui.tui.event.KeyCode;
+import dev.tamboui.tui.event.KeyEvent;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class CamelMonitorTest {
+
+    // '?' is an alternative to F1 for opening the help overlay. Unlike F1, it 
must be suppressed
+    // while a text input is focused, otherwise typing '?' in a search or 
probe field would
+    // pop up help instead of inserting the character.
+
+    @Test
+    void f1OpensHelpEvenWhileTextEditing() {
+        assertTrue(CamelMonitor.opensHelp(KeyEvent.ofKey(KeyCode.F1), true), 
"F1 must open help regardless of text editing");
+        assertTrue(CamelMonitor.opensHelp(KeyEvent.ofKey(KeyCode.F1), false), 
"F1 must open help");
+    }
+
+    @Test
+    void questionMarkOpensHelpWhenNotTextEditing() {
+        assertTrue(CamelMonitor.opensHelp(KeyEvent.ofChar('?'), false), "'?' 
must open help when no input is focused");
+    }
+
+    @Test
+    void questionMarkIsSuppressedWhileTextEditing() {
+        assertFalse(CamelMonitor.opensHelp(KeyEvent.ofChar('?'), true),
+                "'?' must not open help while a text input is focused");
+    }
+
+    @Test
+    void unrelatedKeyDoesNotOpenHelp() {
+        assertFalse(CamelMonitor.opensHelp(KeyEvent.ofChar('x'), false), "an 
unrelated key must not open help");
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/HelpOverlayTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/HelpOverlayTest.java
new file mode 100644
index 000000000000..cc8c5be006d5
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/HelpOverlayTest.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.tui;
+
+import dev.tamboui.tui.event.KeyCode;
+import dev.tamboui.tui.event.KeyEvent;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class HelpOverlayTest {
+
+    // The help overlay is opened with either F1 or '?'. Pressing the same 
keys again must close it,
+    // so the binding is a true toggle. '?' was previously ignored by the 
overlay (CAMEL: TUI help).
+
+    @Test
+    void questionMarkClosesOverlay() {
+        HelpOverlay overlay = new HelpOverlay();
+        overlay.open("# Help");
+        assertTrue(overlay.isVisible());
+
+        boolean handled = overlay.handleKeyEvent(KeyEvent.ofChar('?'));
+
+        assertTrue(handled, "the overlay must consume the key while visible");
+        assertFalse(overlay.isVisible(), "'?' must close the help overlay it 
opened");
+    }
+
+    @Test
+    void f1ClosesOverlay() {
+        HelpOverlay overlay = new HelpOverlay();
+        overlay.open("# Help");
+
+        overlay.handleKeyEvent(KeyEvent.ofKey(KeyCode.F1));
+
+        assertFalse(overlay.isVisible(), "F1 must still close the help 
overlay");
+    }
+
+    @Test
+    void quitKeyClosesOverlay() {
+        HelpOverlay overlay = new HelpOverlay();
+        overlay.open("# Help");
+
+        overlay.handleKeyEvent(KeyEvent.ofChar('q'));
+
+        assertFalse(overlay.isVisible(), "'q' must still close the help 
overlay");
+    }
+
+    @Test
+    void unrelatedKeyKeepsOverlayOpen() {
+        HelpOverlay overlay = new HelpOverlay();
+        overlay.open("# Help");
+
+        overlay.handleKeyEvent(KeyEvent.ofChar('x'));
+
+        assertTrue(overlay.isVisible(), "an unrelated key must not close the 
help overlay");
+    }
+}
diff --git a/dsl/camel-jbang/camel-launcher/pom.xml 
b/dsl/camel-jbang/camel-launcher/pom.xml
index 00be949d3f02..37568d0ca06a 100644
--- a/dsl/camel-jbang/camel-launcher/pom.xml
+++ b/dsl/camel-jbang/camel-launcher/pom.xml
@@ -54,8 +54,28 @@
         <httpcore-version>4.4.16</httpcore-version>
         <commons-codec-version>1.22.0</commons-codec-version>
         <jcl-over-slf4j-version>${slf4j-version}</jcl-over-slf4j-version>
+        <commonmark-version>0.28.0</commonmark-version>
     </properties>
 
+    <dependencyManagement>
+        <dependencies>
+            <!--
+                This launcher bundles both camel-jbang-plugin-generate and 
camel-jbang-plugin-tui on a
+                single flat classpath. The generate plugin drags in commonmark 
0.21.0 (via openapi-generator),
+                while the tui plugin (via tamboui-markdown) needs commonmark 
0.28.0 and its renderer.markdown
+                classes that do not exist in 0.21.0. Without this pin Maven 
mediation keeps the older 0.21.0
+                core next to the 0.28.0 extensions, which makes the TUI 
markdown help throw NoClassDefFoundError.
+                Pin the core to 0.28.0 so it matches the commonmark-ext-* 
modules; openapi-generator only uses
+                the stable Parser/HtmlRenderer APIs, which are unchanged in 
0.28.0.
+            -->
+            <dependency>
+                <groupId>org.commonmark</groupId>
+                <artifactId>commonmark</artifactId>
+                <version>${commonmark-version}</version>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
     <dependencies>
         <dependency>
             <groupId>org.apache.camel</groupId>

Reply via email to