Skip to content

Commit

Permalink
Improve toString() terminal rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Oct 23, 2023
1 parent 60c9297 commit 91e29d0
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,9 @@ public String systemStreamName(SystemStream stream) {
public int systemStreamWidth(SystemStream stream) {
return FfmNativePty.systemStreamWidth(stream);
}

@Override
public String toString() {
return "TerminalProvider[" + name() + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,9 @@ public String systemStreamName(SystemStream stream) {
public int systemStreamWidth(SystemStream stream) {
return JansiNativePty.systemStreamWidth(stream);
}

@Override
public String toString() {
return "TerminalProvider[" + name() + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,9 @@ public int systemStreamWidth(SystemStream stream) {
return -1;
}
}

@Override
public String toString() {
return "TerminalProvider[" + name() + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,9 @@ public String systemStreamName(SystemStream stream) {
public int systemStreamWidth(SystemStream stream) {
return JniNativePty.systemStreamWidth(stream);
}

@Override
public String toString() {
return "TerminalProvider[" + name() + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@ public String systemStreamName(SystemStream stream) {
public int systemStreamWidth(SystemStream stream) {
return 0;
}

@Override
public String toString() {
return "TerminalProvider[" + name() + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,9 @@ public ProcessBuilder.Redirect newRedirectPipe(FileDescriptor fd) {
return JLineLibrary.newRedirectPipe(fd);
}
}

@Override
public String toString() {
return "TerminalProvider[" + name() + "]";
}
}
5 changes: 5 additions & 0 deletions terminal/src/main/java/org/jline/utils/ColorPalette.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,9 @@ private static int[] doLoad(Terminal terminal) throws IOException {
;
return Arrays.copyOfRange(palette, 0, max + 1);
}

@Override
public String toString() {
return "ColorPalette[" + "length=" + getLength() + ", " + "distance='" + getDist() + "\']";
}
}
22 changes: 21 additions & 1 deletion terminal/src/main/java/org/jline/utils/Colors.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ static Distance getDistance(String dist) {
if (dist == null) {
dist = System.getProperty(PROP_COLOR_DISTANCE, "cie76");
}
return doGetDistance(dist);
return new NamedDistance(dist, doGetDistance(dist));
}

private static Distance doGetDistance(String dist) {
Expand Down Expand Up @@ -291,6 +291,26 @@ private static double scalar(double[] c1, double[] c2) {
return sqr(c1[0] - c2[0]) + sqr(c1[1] - c2[1]) + sqr(c1[2] - c2[2]);
}

private static class NamedDistance implements Distance {
private final String name;
private final Distance delegate;

public NamedDistance(String name, Distance delegate) {
this.name = name;
this.delegate = delegate;
}

@Override
public double compute(int c1, int c2) {
return delegate.compute(c1, c2);
}

@Override
public String toString() {
return name;
}
}

private static final int L = 0;
private static final int A = 1;
private static final int B = 2;
Expand Down
6 changes: 6 additions & 0 deletions terminal/src/main/java/org/jline/utils/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,10 @@ public void restore() {
public int size() {
return oldLines.size() + border;
}

@Override
public String toString() {
return "Status[" + "supported="
+ supported + ']';
}
}

0 comments on commit 91e29d0

Please sign in to comment.