davsclaus commented on code in PR #24328:
URL: https://github.com/apache/camel/pull/24328#discussion_r3496961930


##########
dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/ShellPanel.java:
##########
@@ -269,17 +283,46 @@ void render(Frame frame, Rect area) {
             lines = renderLiveView(screen, innerWidth, innerHeight);
         }
 
+        // Split the inner area: content (fill) + scrollbar (1 col) when 
history exists
+        int totalLines = histSize + innerHeight;
+        boolean showScrollbar = totalLines > innerHeight;
+        Rect contentArea;
+        if (showScrollbar) {
+            List<Rect> hChunks = Layout.horizontal()
+                    .constraints(Constraint.fill(), Constraint.length(1))
+                    .split(inner);
+            contentArea = hChunks.get(0);
+
+            // Map scrollOffset (lines-from-bottom) to top-down position for 
ScrollbarState
+            int viewStart = Math.max(0, totalLines - scrollOffset - 
innerHeight);
+            scrollbarState
+                    .contentLength(totalLines)
+                    .viewportContentLength(innerHeight)
+                    .position(viewStart);
+            frame.renderStatefulWidget(Scrollbar.builder().build(), 
hChunks.get(1), scrollbarState);
+        } else {
+            contentArea = inner;
+        }
+
         frame.renderWidget(
                 Paragraph.builder()
                         .text(Text.from(lines))
                         .overflow(Overflow.CLIP)
                         .build(),
-                inner);
+                contentArea);
+
+        // Set the real terminal cursor position so it blinks at the shell 
prompt.
+        // Only show the cursor in live view (not scrolled back) and when the 
shell is focused.
+        if (scrollOffset == 0 && cursor[1] >= 0 && cursor[1] < innerHeight
+                && cursor[0] >= 0 && cursor[0] < innerWidth) {
+            frame.setCursorPosition(contentArea.x() + cursor[0], 
contentArea.y() + cursor[1]);
+        }
     }
 
     void renderFooter(List<Span> spans) {
         MonitorContext.hint(spans, "F6", "close");
-        MonitorContext.hint(spans, "Shift+F6", SPLIT_PERCENTS[splitIndex] + 
"%");
+        int nextIndex = (splitIndex + 1) % SPLIT_PERCENTS.length;
+        MonitorContext.hint(spans, "Shift+F6", SPLIT_PERCENTS[nextIndex] + 
"%");

Review Comment:
   The footer hint should show the current shell panel size, not what it will 
become after pressing the key. This change is wrong — please revert to using 
`splitIndex` instead of `nextIndex`.
   
   ```suggestion
           MonitorContext.hint(spans, "Shift+F6", SPLIT_PERCENTS[splitIndex] + 
"%");
   ```



##########
dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/ShellPanel.java:
##########
@@ -616,14 +653,37 @@ static byte[] encodeKeyEvent(KeyEvent ke) {
         };
     }
 
+    // TODO: ScreenTerminal.history is private with no public accessor in 
JLine 4.2.1.
+    //       File a JLine issue to add getHistory()/getHistorySize() public 
methods,
+    //       then replace this reflection with direct calls.
+    //       See: https://github.com/jline/jline3/issues/1266
+    private static final Field HISTORY_FIELD;
+    private static final AtomicBoolean HISTORY_WARN_LOGGED = new 
AtomicBoolean(false);
+
+    static {
+        Field f = null;
+        try {
+            f = ScreenTerminal.class.getDeclaredField("history");
+            f.setAccessible(true);
+        } catch (NoSuchFieldException e) {
+            System.err.println("[ShellPanel] ScreenTerminal.history field not 
found — "
+                               + "scrollback will be unavailable. JLine API 
may have changed.");
+        }
+        HISTORY_FIELD = f;

Review Comment:
   Minor: `LOG` (the `System.Logger` introduced earlier in this file) is a 
static field initialized before this static block runs, so it's available here. 
Using `LOG.log(Level.WARNING, ...)` would be more consistent with the rest of 
the file.
   
   Same applies to the `System.err.println` in `getHistory()` below.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to