Skip to content

Commit eb1199e

Browse files
committed
Groovy REPL demo erroneously can complete groovy statements in shell command, fixes #663
1 parent 6b51104 commit eb1199e

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

console/src/main/java/org/jline/console/impl/SystemHighlighter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ protected AttributedString systemHighlight(LineReader reader, String buffer) {
7070
out = new AttributedStringBuilder().append(buffer).toAttributedString();
7171
} else if (fileHighlight.contains(command)) {
7272
out = doFileHighlight(reader, buffer);
73-
} else if (systemRegistry.isCommandOrScript(command) || systemRegistry.isCommandAlias(command)
74-
|| command.startsWith("!")) {
73+
} else if (systemRegistry.isCommandOrScript(command) || systemRegistry.isCommandAlias(command)) {
7574
out = doCommandHighlight(buffer);
7675
} else if (langHighlighter != null) {
7776
out = langHighlighter.highlight(buffer);

demo/src/main/java/org/jline/demo/Repl.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,17 @@ public void run() {
224224
}
225225
}
226226

227+
private static class ReplSystemRegistry extends SystemRegistryImpl {
228+
public ReplSystemRegistry(Parser parser, Terminal terminal, Supplier<Path> workDir, ConfigurationPath configPath) {
229+
super(parser, terminal, workDir, configPath);
230+
}
231+
232+
@Override
233+
public boolean isCommandOrScript(String command) {
234+
return command.startsWith("!") || super.isCommandOrScript(command);
235+
}
236+
}
237+
227238
public static void main(String[] args) {
228239
try {
229240
Supplier<Path> workDir = () -> Paths.get(System.getProperty("user.dir"));
@@ -264,7 +275,7 @@ public static void main(String[] args) {
264275
, workDir, configPath);
265276
Builtins builtins = new Builtins(workDir, configPath, (String fun)-> new ConsoleEngine.WidgetCreator(consoleEngine, fun));
266277
MyCommands myCommands = new MyCommands(workDir);
267-
SystemRegistryImpl systemRegistry = new SystemRegistryImpl(parser, terminal, workDir, configPath);
278+
ReplSystemRegistry systemRegistry = new ReplSystemRegistry(parser, terminal, workDir, configPath);
268279
systemRegistry.register("groovy", new GroovyCommand(scriptEngine, printer));
269280
systemRegistry.setCommandRegistries(consoleEngine, builtins, myCommands);
270281
systemRegistry.addCompleter(scriptEngine.getScriptCompleter());

0 commit comments

Comments
 (0)