Skip to content

Commit

Permalink
Restore AttributedStringBuilder compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jun 18, 2017
1 parent 4eb828f commit 9ca6187
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion style/src/main/java/org/jline/style/StyleExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private String style(String key) {
String spec = key.substring(0, idx);
String value = key.substring(idx + 1);
AttributedStyle style = resolver.resolve(spec);
return new AttributedStringBuilder().style(style).appendAnsi(value).toAnsi();
return new AttributedStringBuilder().style(style).ansiAppend(value).toAnsi();
}
return null;
}
Expand Down
14 changes: 7 additions & 7 deletions terminal/src/main/java/org/jline/utils/AttributedString.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,19 @@ public static AttributedString fromAnsi(String ansi, int tabs) {
if (ansi == null) {
return null;
}
AttributedStringBuilder sb = new AttributedStringBuilder(ansi.length());
sb.tabs(tabs);
sb.appendAnsi(ansi);
return sb.toAttributedString();
return new AttributedStringBuilder(ansi.length())
.tabs(tabs)
.ansiAppend(ansi)
.toAttributedString();
}

public static String stripAnsi(String ansi) {
if (ansi == null) {
return null;
}
AttributedStringBuilder sb = new AttributedStringBuilder(ansi.length());
sb.appendAnsi(ansi);
return sb.toString();
return new AttributedStringBuilder(ansi.length())
.ansiAppend(ansi)
.toString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ public AttributedStyle style() {
return current;
}

public AttributedStringBuilder append(AttributedString str) {
return append((AttributedCharSequence) str, 0, str.length());
}

public AttributedStringBuilder append(AttributedString str, int start, int end) {
return append((AttributedCharSequence) str, start, end);
}

public AttributedStringBuilder append(AttributedCharSequence str) {
return append(str, 0, str.length());
}
Expand Down Expand Up @@ -166,7 +174,11 @@ protected void ensureCapacity(int nl) {
}
}

public AttributedStringBuilder appendAnsi(String ansi) {
public void appendAnsi(String ansi) {
ansiAppend(ansi);
}

public AttributedStringBuilder ansiAppend(String ansi) {
int ansiStart = 0;
int ansiState = 0;
ensureCapacity(length + ansi.length());
Expand Down

0 comments on commit 9ca6187

Please sign in to comment.