Skip to content

Commit

Permalink
cleanup StyleState
Browse files Browse the repository at this point in the history
  • Loading branch information
segrey committed Jun 14, 2024
1 parent 8c9bdc0 commit 8366f2b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
26 changes: 8 additions & 18 deletions core/src/com/jediterm/terminal/model/StyleState.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.jediterm.terminal.TextStyle;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public class StyleState {
private volatile TextStyle myCurrentStyle = TextStyle.EMPTY;
private volatile TextStyle myDefaultStyle = TextStyle.EMPTY;
Expand All @@ -19,31 +21,19 @@ public void reset() {
myCurrentStyle = myDefaultStyle;
}

public void set(StyleState styleState) {
setCurrent(styleState.getCurrent());
}

public void setDefaultStyle(TextStyle defaultStyle) {
public void setDefaultStyle(@NotNull TextStyle defaultStyle) {
myDefaultStyle = defaultStyle;
}

public TerminalColor getBackground() {
return getBackground(null);
}

public TerminalColor getBackground(TerminalColor color) {
return color != null ? color : myDefaultStyle.getBackground();
}

public TerminalColor getForeground() {
return getForeground(null);
public @NotNull TerminalColor getDefaultBackground() {
return Objects.requireNonNull(myDefaultStyle.getBackground());
}

public TerminalColor getForeground(TerminalColor color) {
return color != null ? color : myDefaultStyle.getForeground();
public @NotNull TerminalColor getDefaultForeground() {
return Objects.requireNonNull(myDefaultStyle.getForeground());
}

public void setCurrent(TextStyle current) {
public void setCurrent(@NotNull TextStyle current) {
myCurrentStyle = current;
}
}
4 changes: 2 additions & 2 deletions ui/src/com/jediterm/terminal/ui/TerminalPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1256,10 +1256,10 @@ private TextStyle getInversedStyle(@NotNull TextStyle style) {
TextStyle.Builder builder = new TextStyle.Builder(style);
builder.setOption(Option.INVERSE, !style.hasOption(Option.INVERSE));
if (style.getForeground() == null) {
builder.setForeground(myStyleState.getForeground());
builder.setForeground(myStyleState.getDefaultForeground());
}
if (style.getBackground() == null) {
builder.setBackground(myStyleState.getBackground());
builder.setBackground(myStyleState.getDefaultBackground());
}
return builder.build();
}
Expand Down

0 comments on commit 8366f2b

Please sign in to comment.