Skip to content

Commit

Permalink
Less does not display tabs correctly, fixes #104
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Mar 23, 2017
1 parent 50c14de commit 477cb55
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion builtins/src/main/java/org/jline/builtins/Less.java
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ AttributedString getLine(int line) throws IOException {
while (line >= lines.size()) {
String str = reader.readLine();
if (str != null) {
lines.add(AttributedString.fromAnsi(str));
lines.add(AttributedString.fromAnsi(str, tabs));
} else {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ public AttributedString columnSubSequence(int start, int stop) {
public List<AttributedString> columnSplitLength(int columns) {
return columnSplitLength(columns, false, true);
}

public List<AttributedString> columnSplitLength(int columns, boolean includeNewlines, boolean delayLineWrap) {
List<AttributedString> strings = new ArrayList<>();
int cur = 0;
Expand Down
5 changes: 5 additions & 0 deletions terminal/src/main/java/org/jline/utils/AttributedString.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,15 @@ public AttributedString(CharSequence str, int start, int end, AttributedStyle s)
}

public static AttributedString fromAnsi(String ansi) {
return fromAnsi(ansi, 0);
}

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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ public void appendAnsi(String ansi) {
} else if (c == '\t' && tabs > 0) {
insertTab(current);
} else {
ensureCapacity(length + 1);
buffer[length] = c;
style[length] = this.current.getStyle();
length++;
Expand Down

0 comments on commit 477cb55

Please sign in to comment.