From b15bfdfef8d359adffcb73b1655cbcfb5bb627fb Mon Sep 17 00:00:00 2001 From: JanAmeis <162981643+WorkingAmeise@users.noreply.github.com> Date: Sat, 26 Oct 2024 02:03:21 +0200 Subject: [PATCH] #533: Add autocompletion of exit in ide shell (#707) --- CHANGELOG.adoc | 1 + .../tools/ide/commandlet/ShellCommandlet.java | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 39434b2b8..094d67183 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -44,6 +44,7 @@ Release with new features and bugfixes: * https://github.com/devonfw/IDEasy/issues/525[#525]: Added online state check before downloading * https://github.com/devonfw/IDEasy/issues/663[#663]: Endless loop when installing Eclipse in force mode * https://github.com/devonfw/IDEasy/issues/657[#657]: Cannot install Java 8 +* https://github.com/devonfw/IDEasy/issues/533[#533]: Added autocompletion of exit in ide shell The full list of changes for this release can be found in https://github.com/devonfw/IDEasy/milestone/13?closed=1[milestone 2024.09.002]. diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java index b2d14a6da..f350408a7 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/ShellCommandlet.java @@ -4,6 +4,7 @@ import java.util.Iterator; import org.fusesource.jansi.AnsiConsole; +import org.jline.reader.Completer; import org.jline.reader.EndOfFileException; import org.jline.reader.LineReader; import org.jline.reader.LineReaderBuilder; @@ -11,6 +12,8 @@ import org.jline.reader.Parser; import org.jline.reader.UserInterruptException; import org.jline.reader.impl.DefaultParser; +import org.jline.reader.impl.completer.AggregateCompleter; +import org.jline.reader.impl.completer.StringsCompleter; import org.jline.terminal.Terminal; import org.jline.terminal.TerminalBuilder; import org.jline.widget.AutosuggestionWidgets; @@ -65,8 +68,9 @@ public void run() { Parser parser = new DefaultParser(); try (Terminal terminal = TerminalBuilder.builder().build()) { - // initialize our own completer here - IdeCompleter completer = new IdeCompleter((AbstractIdeContext) this.context); + // initialize our own completer here and add exit as an autocompletion option + Completer completer = new AggregateCompleter( + new StringsCompleter("exit"), new IdeCompleter((AbstractIdeContext) this.context)); LineReader reader = LineReaderBuilder.builder().terminal(terminal).completer(completer).parser(parser) .variable(LineReader.LIST_MAX, AUTOCOMPLETER_MAX_RESULTS).build(); @@ -86,6 +90,10 @@ public void run() { while (true) { try { line = reader.readLine(prompt, rightPrompt, (MaskingCallback) null, null); + line = line.trim(); + if (line.equals("exit")) { + return; + } reader.getHistory().add(line); int rc = runCommand(line); if (rc == RC_EXIT) {