Skip to content

Commit

Permalink
ConsoleEngine: implemented invoke() method
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Jan 16, 2020
1 parent 5863651 commit c279d61
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
16 changes: 16 additions & 0 deletions builtins/src/main/java/org/jline/builtins/ConsoleEngineImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,21 @@ public Object execute(String command, String[] args) throws Exception {
return out;
}

@Override
public Object invoke(String command, Object... args) throws Exception {
Object out = null;
if (command.equals("prnt")) {
invokePrnt(args);
} else {
String[] _args = new String[args.length];
for (int i = 0; i < args.length; i++) {
_args[i] = args[i].toString();
}
out = execute(command, _args);
}
return out;
}

@SuppressWarnings("unchecked")
private Map<String,Object> defaultPrntOptions() {
Map<String, Object> out = new HashMap<>();
Expand Down Expand Up @@ -403,6 +418,7 @@ public void println(Map<String, Object> options, Object object) {
as.println(terminal);
}
}
terminal.flush();
}

private void highlight(int width, String style, String object) {
Expand Down
3 changes: 2 additions & 1 deletion builtins/src/test/script/init.jline
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ array=[0,1]

array.each {
println it
:show
resp=:show
:prnt $resp
}

println $1
Expand Down
6 changes: 5 additions & 1 deletion groovy/src/test/script/hello.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import org.jline.builtins.SystemRegistry

class HelloWorld {
static void hello(def who) {
println "hello $who!"
println "hello $who!"
def map = [user:'pippo',age:10]
SystemRegistry.get().invoke('prnt', '-s', 'JSON', map)
}
}

Expand Down

0 comments on commit c279d61

Please sign in to comment.