< prev index next >
src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/Console.java
Print this page
*** 34,59 ****
import java.util.Iterator;
import java.util.List;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import jdk.internal.jline.console.ConsoleReader;
import jdk.internal.jline.console.history.History.Entry;
import jdk.internal.jline.console.history.MemoryHistory;
class Console implements AutoCloseable {
private final ConsoleReader in;
private final PersistentHistory history;
! Console(InputStream cmdin, PrintStream cmdout, Preferences prefs) throws IOException {
in = new ConsoleReader(cmdin, cmdout);
in.setExpandEvents(false);
in.setHandleUserInterrupt(true);
in.setHistory(history = new PersistentHistory(prefs));
Runtime.getRuntime().addShutdownHook(new Thread(()->close()));
}
! String readLine(String prompt) throws IOException {
return in.readLine(prompt);
}
@Override
--- 34,63 ----
import java.util.Iterator;
import java.util.List;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import jdk.internal.jline.console.ConsoleReader;
+ import jdk.internal.jline.console.completer.Completer;
import jdk.internal.jline.console.history.History.Entry;
import jdk.internal.jline.console.history.MemoryHistory;
class Console implements AutoCloseable {
private final ConsoleReader in;
private final PersistentHistory history;
! Console(final InputStream cmdin, final PrintStream cmdout, final Preferences prefs,
! final Completer completer) throws IOException {
in = new ConsoleReader(cmdin, cmdout);
in.setExpandEvents(false);
in.setHandleUserInterrupt(true);
+ in.setBellEnabled(true);
in.setHistory(history = new PersistentHistory(prefs));
+ in.addCompleter(completer);
Runtime.getRuntime().addShutdownHook(new Thread(()->close()));
}
! String readLine(final String prompt) throws IOException {
return in.readLine(prompt);
}
@Override
*** 63,82 ****
public static class PersistentHistory extends MemoryHistory {
private final Preferences prefs;
! protected PersistentHistory(Preferences prefs) {
this.prefs = prefs;
load();
}
private static final String HISTORY_LINE_PREFIX = "HISTORY_LINE_";
public final void load() {
try {
! List<String> keys = new ArrayList<>(Arrays.asList(prefs.keys()));
Collections.sort(keys);
for (String key : keys) {
if (!key.startsWith(HISTORY_LINE_PREFIX))
continue;
CharSequence line = prefs.get(key, "");
--- 67,86 ----
public static class PersistentHistory extends MemoryHistory {
private final Preferences prefs;
! protected PersistentHistory(final Preferences prefs) {
this.prefs = prefs;
load();
}
private static final String HISTORY_LINE_PREFIX = "HISTORY_LINE_";
public final void load() {
try {
! final List<String> keys = new ArrayList<>(Arrays.asList(prefs.keys()));
Collections.sort(keys);
for (String key : keys) {
if (!key.startsWith(HISTORY_LINE_PREFIX))
continue;
CharSequence line = prefs.get(key, "");
< prev index next >