Mercurial > hg > release > thermostat-2.0
changeset 2293:e8aa651b0627
Append spaces to tab completion candidates and disable JLine space appending
This eases shell tab completion usability by removing extraneous spaces which
may be printed in certain situations (ex. when tab-completing a file path),
while still allowing for fast and easy tab-completions in other contexts
(ex. vmId, agentId, dbUrl, etc.)
Reviewed-by: jerboaa
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-April/018626.html
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-May/018761.html
author | Andrew Azores <aazores@redhat.com> |
---|---|
date | Wed, 11 May 2016 13:56:26 -0400 |
parents | 12e2aa7b6c42 |
children | 181cffa3afd2 |
files | common/core/src/main/java/com/redhat/thermostat/common/cli/CompletionFinderTabCompleter.java common/core/src/test/java/com/redhat/thermostat/common/cli/CompletionFinderTabCompleterTest.java launcher/src/main/java/com/redhat/thermostat/launcher/internal/JLineStringsCompleter.java launcher/src/main/java/com/redhat/thermostat/launcher/internal/LogLevelCompleterService.java launcher/src/main/java/com/redhat/thermostat/launcher/internal/ShellCommand.java launcher/src/main/java/com/redhat/thermostat/launcher/internal/TreeCompleter.java launcher/src/test/java/com/redhat/thermostat/launcher/internal/LogLevelCompleterServiceTest.java |
diffstat | 7 files changed, 20 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/common/core/src/main/java/com/redhat/thermostat/common/cli/CompletionFinderTabCompleter.java Wed May 11 12:02:41 2016 -0400 +++ b/common/core/src/main/java/com/redhat/thermostat/common/cli/CompletionFinderTabCompleter.java Wed May 11 13:56:26 2016 -0400 @@ -84,7 +84,7 @@ private List<String> getCompletions(List<CompletionInfo> completions) { List<String> result = new ArrayList<>(); for (CompletionInfo completion : completions) { - result.add(completion.getActualCompletion()); + result.add(completion.getActualCompletion() + " "); } return result; }
--- a/common/core/src/test/java/com/redhat/thermostat/common/cli/CompletionFinderTabCompleterTest.java Wed May 11 12:02:41 2016 -0400 +++ b/common/core/src/test/java/com/redhat/thermostat/common/cli/CompletionFinderTabCompleterTest.java Wed May 11 13:56:26 2016 -0400 @@ -86,7 +86,7 @@ verify(finder).findCompletions(); - assertThat(candidates, is(equalTo(Collections.singletonList((CharSequence) completionInfo.getActualCompletion())))); + assertThat(candidates, is(equalTo(Collections.singletonList((CharSequence) (completionInfo.getActualCompletion() + " "))))); } @Test
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/JLineStringsCompleter.java Wed May 11 12:02:41 2016 -0400 +++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/JLineStringsCompleter.java Wed May 11 13:56:26 2016 -0400 @@ -38,12 +38,13 @@ import jline.console.completer.StringsCompleter; +import java.util.Arrays; import java.util.Collection; public class JLineStringsCompleter extends JLineCompleterWrapper { public JLineStringsCompleter(String... strings) { - super(new StringsCompleter(strings)); + this(Arrays.asList(strings)); } public JLineStringsCompleter(Collection<String> strings) {
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/LogLevelCompleterService.java Wed May 11 12:02:41 2016 -0400 +++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/LogLevelCompleterService.java Wed May 11 13:56:26 2016 -0400 @@ -55,7 +55,7 @@ static { for (LoggingUtils.LogLevel level : LoggingUtils.LogLevel.values()) { - LOG_LEVELS.add(level.getLevel().getName()); + LOG_LEVELS.add(level.getLevel().getName() + " "); } }
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/ShellCommand.java Wed May 11 12:02:41 2016 -0400 +++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/ShellCommand.java Wed May 11 13:56:26 2016 -0400 @@ -47,6 +47,7 @@ import jline.TerminalFactory; import jline.console.ConsoleReader; import jline.console.UserInterruptException; +import jline.console.completer.CandidateListCompletionHandler; import jline.console.history.FileHistory; import jline.console.history.History; import jline.console.history.PersistentHistory; @@ -168,6 +169,9 @@ if (history != null) { reader.setHistory(history); } + CandidateListCompletionHandler completionHandler = new CandidateListCompletionHandler(); + completionHandler.setPrintSpaceAfterFullCompletion(false); + reader.setCompletionHandler(completionHandler); try { while (handleConsoleInput(reader, ctx.getConsole(), shellPrompt.getPrompt())) { /* no-op; the loop conditional performs the action */ } } finally {
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/TreeCompleter.java Wed May 11 12:02:41 2016 -0400 +++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/TreeCompleter.java Wed May 11 13:56:26 2016 -0400 @@ -334,7 +334,7 @@ * @return the node containing the string completer */ public static Node createStringNode(String tag, String... strings) { - return new Node(tag, new JLineStringsCompleter(strings)); + return createStringNode(tag, Arrays.asList(strings)); } public static Node createStringNode(String tag) { @@ -347,6 +347,14 @@ * @return the node containing the string completer */ public static Node createStringNode(String tag, List<String> strings) { - return new Node(tag, new JLineStringsCompleter(strings)); + List<String> spaced = new ArrayList<>(); + for (String s : strings) { + if (s.endsWith(" ")) { + spaced.add(s); + } else { + spaced.add(s + " "); + } + } + return new Node(tag, new JLineStringsCompleter(spaced)); } }
--- a/launcher/src/test/java/com/redhat/thermostat/launcher/internal/LogLevelCompleterServiceTest.java Wed May 11 12:02:41 2016 -0400 +++ b/launcher/src/test/java/com/redhat/thermostat/launcher/internal/LogLevelCompleterServiceTest.java Wed May 11 13:56:26 2016 -0400 @@ -68,7 +68,7 @@ LoggingUtils.LogLevel[] levels = LoggingUtils.LogLevel.values(); List<String> expected = new ArrayList<>(); for (LoggingUtils.LogLevel level : levels) { - expected.add(level.getLevel().getName()); + expected.add(level.getLevel().getName() + " "); } Collections.sort(expected, String.CASE_INSENSITIVE_ORDER);