Skip to content

Commit

Permalink
Small improvements...
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Jan 30, 2020
1 parent 29077a2 commit 1bcf06f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ private Map<String,Object> defaultPrntOptions() {
@Override
public void println(Object object) {
Map<String,Object> options = defaultPrntOptions();
options.put("exception", "message");
options.putIfAbsent("exception", "message");
println(options, object);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,14 @@ public Object invoke(String command, Object... args) throws Exception {
if (id > -1) {
out = commandRegistries[id].invoke(command, args);
} else if (isLocalCommand(command)) {
out = invoke(command, args);
String[] _args = new String[args.length];
for (int i = 0; i < args.length; i++) {
if (!(args[i] instanceof String)) {
throw new IllegalArgumentException();
}
_args[i] = args[i].toString();
}
out = localExecute(command, _args);
} else if (consoleId != null) {
out = consoleEngine().invoke(command, args);
}
Expand Down
6 changes: 3 additions & 3 deletions demo/src/main/scripts/optionCompleterTest.jline
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import org.jline.builtins.SystemRegistry

def complete(commandLine) {
candidates = []
completer.complete(reader, parser.parse(commandLine, commandLine.length(), Parser.ParseContext.ACCEPT_LINE), candidates)
completer.complete(null, parser.parse(commandLine, commandLine.length(), Parser.ParseContext.ACCEPT_LINE), candidates)
candidates.each { println it.value()}
null
}

reader=null // reader is not really needed here!
parser=SystemRegistry.get().parser
parser = SystemRegistry.get().parser

options=['--opt1','--opt2']
optionValues=['--option':['val1','val2'],'--option2':['val3','val4']]
Expand Down
1 change: 0 additions & 1 deletion groovy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
13 changes: 8 additions & 5 deletions groovy/src/main/java/org/jline/script/GroovyEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,15 @@ private List<AttributedString> highlightMap(Map<String, Object> map, int width)
for (Map.Entry<String, Object> entry : map.entrySet()) {
AttributedStringBuilder asb = new AttributedStringBuilder().tabs(Arrays.asList(0, max + 1));
asb.append(entry.getKey(), AttributedStyle.DEFAULT.foreground(AttributedStyle.BLUE + AttributedStyle.BRIGHT));
asb.append("\t");
asb.append(Utils.toString(entry.getValue()), AttributedStyle.DEFAULT.foreground(AttributedStyle.YELLOW));
if (asb.columnLength() > width) {
asb.setLength(width);
for (String v : Utils.toString(entry.getValue()).split("\n")) {
asb.append("\t");
asb.append(v, AttributedStyle.DEFAULT.foreground(AttributedStyle.YELLOW));
if (asb.columnLength() > width) {
asb.setLength(width);
}
out.add(asb.toAttributedString());
asb = new AttributedStringBuilder().tabs(Arrays.asList(0, max + 1));
}
out.add(asb.toAttributedString());
}
return out;
}
Expand Down

0 comments on commit 1bcf06f

Please sign in to comment.