Skip to content

Commit

Permalink
SystemHighlighter highlight command aliases as commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Nov 30, 2020
1 parent 0e5d510 commit b1a17cb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 10 additions & 2 deletions console/src/main/java/org/jline/console/SystemRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,21 @@ public interface SystemRegistry extends CommandRegistry, ConsoleOptionGetter {
* @return true if the specified line has a command registered
*/
boolean isCommandOrScript(ParsedLine line);

/**
* Returns whether a line contains command/script that is known to this registry.
* Returns whether command is known to this registry.
* @param command the command to test
* @return true if the specified line has a command registered
* @return true if the specified command is known
*/
boolean isCommandOrScript(String command);

/**
* Returns whether alias is known command alias.
* @param alias the alias to test
* @return true if the alias is known command alias
*/
boolean isCommandAlias(String alias);

/**
* Orderly close SystemRegistry.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ private boolean doDefaultHighlight(LineReader reader) {

private AttributedString systemHighlight(Parser parser, String buffer) {
AttributedString out;
String command = parser.getCommand(buffer.trim().split("\\s+")[0]);
if (buffer.trim().isEmpty()) {
out = new AttributedStringBuilder().append(buffer).toAttributedString();
} else if (systemRegistry.isCommandOrScript(parser.getCommand(buffer.trim().split("\\s+")[0]))) {
} else if (systemRegistry.isCommandOrScript(command) || systemRegistry.isCommandAlias(command)) {
if (commandHighlighter != null || argsHighlighter != null) {
int idx = -1;
boolean cmdFound = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,8 @@ public boolean isByteOutputStream() {

}

private boolean isCommandAlias(String command) {
@Override
public boolean isCommandAlias(String command) {
if (consoleEngine() == null) {
return false;
}
Expand Down

0 comments on commit b1a17cb

Please sign in to comment.