Skip to content

Commit

Permalink
restore default cursor on soft/hard resets
Browse files Browse the repository at this point in the history
  • Loading branch information
segrey committed May 27, 2024
1 parent 964dcbb commit 9d461c3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 34 deletions.
20 changes: 13 additions & 7 deletions core/src/com/jediterm/terminal/CursorShape.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package com.jediterm.terminal;

/** Current cursor shape as described by https://vt100.net/docs/vt510-rm/DECSCUSR.html. */
/**
* Cursor shape as described by <a href="https://vt100.net/docs/vt510-rm/DECSCUSR.html">DECSCUSR</a>.
*/
public enum CursorShape {
BLINK_BLOCK,
STEADY_BLOCK,
BLINK_UNDERLINE,
STEADY_UNDERLINE,
BLINK_VERTICAL_BAR,
STEADY_VERTICAL_BAR
BLINK_BLOCK,
STEADY_BLOCK,
BLINK_UNDERLINE,
STEADY_UNDERLINE,
BLINK_VERTICAL_BAR,
STEADY_VERTICAL_BAR;

public boolean isBlinking() {
return this == BLINK_BLOCK || this == BLINK_UNDERLINE || this == BLINK_VERTICAL_BAR;
}
}
5 changes: 4 additions & 1 deletion core/src/com/jediterm/terminal/TerminalDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
public interface TerminalDisplay {
void setCursor(int x, int y);

void setCursorShape(@NotNull CursorShape cursorShape);
/**
* Sets cursor shape, null means default.
*/
void setCursorShape(@Nullable CursorShape cursorShape);

void beep();

Expand Down
4 changes: 2 additions & 2 deletions core/src/com/jediterm/terminal/model/JediTerminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ public void cursorBackward(final int dX) {
}

@Override
public void cursorShape(@NotNull CursorShape shape) {
public void cursorShape(@Nullable CursorShape shape) {
myDisplay.setCursorShape(shape);
}

Expand Down Expand Up @@ -844,7 +844,7 @@ public void reset(boolean clearScrollBackBuffer) {
initMouseModes();

cursorPosition(1, 1);
cursorShape(CursorShape.BLINK_BLOCK);
cursorShape(null);
}

private void initMouseModes() {
Expand Down
2 changes: 1 addition & 1 deletion core/tests/src/com/jediterm/util/BackBufferDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void setCursor(int x, int y) {
}

@Override
public void setCursorShape(@NotNull CursorShape cursorShape) {
public void setCursorShape(@Nullable CursorShape cursorShape) {
}

@Override
Expand Down
34 changes: 11 additions & 23 deletions ui/src/com/jediterm/terminal/ui/TerminalPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.text.CharacterIterator;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -1099,11 +1100,10 @@ private class TerminalCursor {
// cursor state
private boolean myCursorIsShown; // blinking state
private final Point myCursorCoordinates = new Point();
private CursorShape myShape = CursorShape.BLINK_BLOCK;
private @Nullable CursorShape myShape;

// terminal modes
private boolean myShouldDrawCursor = true;
private boolean myBlinking = true;

private long myLastCursorChange;
private boolean myCursorHasChanged;
Expand Down Expand Up @@ -1133,12 +1133,8 @@ public void setShouldDrawCursor(boolean shouldDrawCursor) {
myShouldDrawCursor = shouldDrawCursor;
}

public void setBlinking(boolean blinking) {
myBlinking = blinking;
}

public boolean isBlinking() {
return myBlinking && (getBlinkingPeriod() > 0);
return getEffectiveShape().isBlinking() && (getBlinkingPeriod() > 0);
}

public void cursorChanged() {
Expand Down Expand Up @@ -1208,7 +1204,7 @@ void drawCursor(String c, Graphics2D gfx, TextStyle style) {
TextStyle inversedStyle = getInversedStyle(style);
java.awt.Color inverseBg = getEffectiveBackground(inversedStyle);

switch (myShape) {
switch (getEffectiveShape()) {
case BLINK_BLOCK:
case STEADY_BLOCK:
if (state == TerminalCursorState.SHOWING) {
Expand All @@ -1235,8 +1231,12 @@ void drawCursor(String c, Graphics2D gfx, TextStyle style) {
}
}

void setShape(CursorShape shape) {
this.myShape = shape;
void setShape(@Nullable CursorShape shape) {
myShape = shape;
}

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

Expand Down Expand Up @@ -1544,20 +1544,8 @@ public void setCursor(final int x, final int y) {
}

@Override
public void setCursorShape(@NotNull CursorShape cursorShape) {
public void setCursorShape(@Nullable CursorShape cursorShape) {
myCursor.setShape(cursorShape);
switch (cursorShape) {
case STEADY_BLOCK:
case STEADY_UNDERLINE:
case STEADY_VERTICAL_BAR:
myCursor.setBlinking(false);
break;
case BLINK_BLOCK:
case BLINK_UNDERLINE:
case BLINK_VERTICAL_BAR:
myCursor.setBlinking(true);
break;
}
}

public void beep() {
Expand Down

0 comments on commit 9d461c3

Please sign in to comment.