Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/main/java/org/jboss/aesh/readline/actions/Complete.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.jboss.aesh.readline.actions;

import org.jboss.aesh.console.Config;
import org.jboss.aesh.console.ConsoleBuffer;
import org.jboss.aesh.console.InputProcessor;
import org.jboss.aesh.readline.Action;
import org.jboss.aesh.readline.ActionEvent;
Expand Down Expand Up @@ -49,11 +50,12 @@ public void apply(InputProcessor inputProcessor) {
}
else {
inputProcessor.getCompleter().setAskDisplayCompletion(false);
inputProcessor.getBuffer().getUndoManager().clear();
inputProcessor.getBuffer().out().print(Config.getLineSeparator());
inputProcessor.clearBufferAndDisplayPrompt();
inputProcessor.getBuffer().drawLine();
inputProcessor.getBuffer().moveCursor(inputProcessor.getBuffer().getBuffer().getMultiCursor());
ConsoleBuffer buffer = inputProcessor.getBuffer();
buffer.getUndoManager().clear();
buffer.out().print(Config.getLineSeparator());
buffer.displayPrompt();
buffer.out().print(buffer.getBuffer().getLine());
buffer.moveCursor(buffer.getBuffer().getMultiCursor());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't use {{inputProcessor.getBuffer().drawLine();, as it placed a cursor at the beginning of the line, instead of at the end. In the original code it also seems redundant with previous line inputProcessor.clearBufferAndDisplayPrompt();.

}
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.jboss.aesh.console.Config;
import org.jboss.aesh.console.Console;
import org.jboss.aesh.console.ConsoleOperation;
import org.jboss.aesh.console.Prompt;
import org.jboss.aesh.console.command.Command;
import org.jboss.aesh.console.settings.Settings;
import org.jboss.aesh.console.settings.SettingsBuilder;
Expand Down Expand Up @@ -345,6 +346,63 @@ else if(co.getBuffer().endsWith(" -")) {
console.stop();
}

@Test
public void askDisplayCompletion() throws Exception {
Completion completion = new Completion() {
@Override
public void complete(CompleteOperation co) {
if(co.getBuffer().equals("file")) {
for (int i = 0; i < 105; i++) {
co.addCompletionCandidate("file" + i);
}
}
}
};

PipedOutputStream outputStream = new PipedOutputStream();
PipedInputStream pipedInputStream = new PipedInputStream(outputStream);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

Settings settings = new SettingsBuilder()
.inputStream(pipedInputStream)
.outputStream(new PrintStream(byteArrayOutputStream))
.logging(true)
.create();

Console console = new Console(settings);

console.addCompletion(completion);

console.setConsoleCallback(new CompletionConsoleCallback2(console));
console.setPrompt(new Prompt("# "));
console.start();

try {
outputStream.write("file".getBytes());
outputStream.write(completeChar.getFirstValue());
outputStream.flush();
Thread.sleep(200);

assertEquals("file", console.getBuffer());
assertEquals("Display all 105 possibilities? (y or n)", getLastOutputLine(byteArrayOutputStream));

outputStream.write("n".getBytes());
outputStream.flush();

Thread.sleep(200);

assertEquals("file", console.getBuffer());
} finally {
console.stop();
}
}

String getLastOutputLine(ByteArrayOutputStream os) {
String output = new String(os.toByteArray());
String[] lines = output.split("\n");
return lines[lines.length - 1];
}

class CompletionConsoleCallback extends AeshConsoleCallback {
private transient int count = 0;
final Console console;
Expand Down