Skip to content

Commit

Permalink
provide ability to set default cursor in TerminalPanel
Browse files Browse the repository at this point in the history
Regression after 9d461c3. Now, `TerminalPanel.setCursorShape` passes `null` for the default cursor, but the full reset (`JediTerminal.reset`) is performed on startup, so a cursor configured in `JBTerminalPanel` constructor was cleared.
  • Loading branch information
segrey committed Sep 10, 2024
1 parent 0f93b21 commit c1cb74d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jediterm.example;

import com.jediterm.pty.PtyProcessTtyConnector;
import com.jediterm.terminal.CursorShape;
import com.jediterm.terminal.TtyConnector;
import com.jediterm.terminal.ui.JediTermWidget;
import com.jediterm.terminal.ui.settings.DefaultSettingsProvider;
Expand All @@ -21,6 +22,7 @@ public class BasicTerminalShellExample {

private static @NotNull JediTermWidget createTerminalWidget() {
JediTermWidget widget = new JediTermWidget(80, 24, new DefaultSettingsProvider());
widget.getTerminalPanel().setDefaultCursorShape(CursorShape.BLINK_UNDERLINE);
widget.setTtyConnector(createTtyConnector());
widget.start();
return widget;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.jediterm.app.JediTerm;
import com.jediterm.app.TtyConnectorWaitFor;
import com.jediterm.core.compatibility.Point;
import com.jediterm.terminal.CursorShape;
import com.jediterm.terminal.Terminal;
import com.jediterm.terminal.TtyConnector;
import com.jediterm.terminal.model.SelectionUtil;
Expand Down Expand Up @@ -176,7 +177,9 @@ private static void onTermination(@NotNull JediTermWidget widget, @NotNull IntCo
}

protected JediTermWidget createTerminalWidget(@NotNull SettingsProvider settingsProvider) {
return new JediTermWidget(settingsProvider);
JediTermWidget widget = new JediTermWidget(settingsProvider);
widget.getTerminalPanel().setDefaultCursorShape(CursorShape.BLINK_VERTICAL_BAR);
return widget;
}

private void sizeFrameForTerm(final JFrame frame) {
Expand Down
2 changes: 1 addition & 1 deletion JediTerm/src/main/kotlin/com/jediterm/app/JediTermMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class JediTerm : AbstractTerminalFrame() {
}

override fun createTerminalWidget(settingsProvider: SettingsProvider): JediTermWidget {
val widget = JediTermWidget(settingsProvider)
val widget = super.createTerminalWidget(settingsProvider)
widget.addHyperlinkFilter(UrlFilter())
return widget
}
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.45
3.46
11 changes: 10 additions & 1 deletion ui/src/com/jediterm/terminal/ui/TerminalPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,7 @@ private class TerminalCursor {
// cursor state
private boolean myCursorIsShown; // blinking state
private final Point myCursorCoordinates = new Point();
private @NotNull CursorShape myDefaultCursorShape = CursorShape.BLINK_BLOCK;
private @Nullable CursorShape myShape;

// terminal modes
Expand Down Expand Up @@ -1236,7 +1237,11 @@ void setShape(@Nullable CursorShape shape) {
}

@NotNull CursorShape getEffectiveShape() {
return Objects.requireNonNullElse(myShape, CursorShape.BLINK_BLOCK);
return Objects.requireNonNullElse(myShape, myDefaultCursorShape);
}

private void setDefaultShape(@NotNull CursorShape defaultShape) {
myDefaultCursorShape = defaultShape;
}
}

Expand Down Expand Up @@ -1548,6 +1553,10 @@ public void setCursorShape(@Nullable CursorShape cursorShape) {
myCursor.setShape(cursorShape);
}

public void setDefaultCursorShape(@NotNull CursorShape defaultCursorShape) {
myCursor.setDefaultShape(defaultCursorShape);
}

public void beep() {
if (mySettingsProvider.audibleBell()) {
Toolkit.getDefaultToolkit().beep();
Expand Down

0 comments on commit c1cb74d

Please sign in to comment.