< prev index next >

src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/Console.java

Print this page

        

@@ -34,26 +34,30 @@
 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(InputStream cmdin, PrintStream cmdout, Preferences prefs) throws IOException {
+    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(String prompt) throws IOException {
+    String readLine(final String prompt) throws IOException {
         return in.readLine(prompt);
     }
 
 
     @Override

@@ -63,20 +67,20 @@
 
     public static class PersistentHistory extends MemoryHistory {
 
         private final Preferences prefs;
 
-        protected PersistentHistory(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 {
-                List<String> keys = new ArrayList<>(Arrays.asList(prefs.keys()));
+                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 >