Skip to content

Commit

Permalink
Enhance DefaultHighlighter to support command styling
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Dec 10, 2024
1 parent bc15b16 commit bbae299
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public AttributedString highlight(LineReader reader, String buffer) {
int underlineEnd = -1;
int negativeStart = -1;
int negativeEnd = -1;
boolean first = true;
String search = reader.getSearchTerm();
if (search != null && search.length() > 0) {
underlineStart = buffer.indexOf(search);
Expand Down Expand Up @@ -65,6 +66,7 @@ public AttributedString highlight(LineReader reader, String buffer) {
}

AttributedStringBuilder sb = new AttributedStringBuilder();
commandStyle(reader, sb, true);
for (int i = 0; i < buffer.length(); i++) {
if (i == underlineStart) {
sb.style(AttributedStyle::underline);
Expand All @@ -77,6 +79,10 @@ public AttributedString highlight(LineReader reader, String buffer) {
}

char c = buffer.charAt(i);
if (first && Character.isSpaceChar(c)) {
first = false;
commandStyle(reader, sb, false);
}
if (c == '\t' || c == '\n') {
sb.append(c);
} else if (c < 32) {
Expand Down Expand Up @@ -105,4 +111,6 @@ public AttributedString highlight(LineReader reader, String buffer) {
}
return sb.toAttributedString();
}

protected void commandStyle(LineReader reader, AttributedStringBuilder sb, boolean enable) {}
}

0 comments on commit bbae299

Please sign in to comment.