Skip to content

Commit

Permalink
Improved help highlight...
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Dec 13, 2019
1 parent 064aa77 commit 2d596b8
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions builtins/src/main/java/org/jline/builtins/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -581,17 +581,24 @@ public static AttributedString highlightComment(String comment, StyleResolver re
}

private static AttributedStringBuilder _highlightSyntax(String syntax, StyleResolver resolver) {
AttributedStringBuilder asyntax = new AttributedStringBuilder().append(syntax);
StringBuilder indent = new StringBuilder();
for (char c : syntax.toCharArray()) {
if (c != ' ') {
break;
}
indent.append(c);
}
AttributedStringBuilder asyntax = new AttributedStringBuilder().append(syntax.substring(indent.length()));
// command
asyntax.styleMatches(Pattern.compile("(?:^)(?:\\s*)([a-z]+[a-z-]*){1}\\b"),
asyntax.styleMatches(Pattern.compile("(?:^)([a-z]+[a-z-]*){1}\\b"),
Collections.singletonList(resolver.resolve(".co")));
// argument
asyntax.styleMatches(Pattern.compile("(?:\\[|\\s|=)([A-Za-z]+[A-Za-z_-]*){1}\\b"),
asyntax.styleMatches(Pattern.compile("(?:<|\\[|\\s|=)([A-Za-z]+[A-Za-z_-]*){1}\\b"),
Collections.singletonList(resolver.resolve(".ar")));
// option
asyntax.styleMatches(Pattern.compile("(?:\\s|\\[)(-\\$|-\\?|[-]{1,2}[A-Za-z-]+\\b){1}"),
asyntax.styleMatches(Pattern.compile("(?:^|\\s|\\[)(-\\$|-\\?|[-]{1,2}[A-Za-z-]+\\b){1}"),
Collections.singletonList(resolver.resolve(".op")));
return asyntax;
return new AttributedStringBuilder().append(indent).append(asyntax);
}

private static AttributedStringBuilder _highlightComment(String comment, StyleResolver resolver) {
Expand Down

0 comments on commit 2d596b8

Please sign in to comment.