Ejemplo n.º 1
0
 void resume() {
   try {
     in.getTerminal().init();
   } catch (Exception ex) {
     throw new IllegalStateException(ex);
   }
 }
Ejemplo n.º 2
0
 void suspend() {
   try {
     in.getTerminal().restore();
   } catch (Exception ex) {
     throw new IllegalStateException(ex);
   }
 }
Ejemplo n.º 3
0
 boolean terminalEditorRunning() {
   Terminal terminal = in.getTerminal();
   if (terminal instanceof JJSUnixTerminal) {
     return ((JJSUnixTerminal) terminal).isRaw();
   }
   return false;
 }
Ejemplo n.º 4
0
 private void bind(String shortcut, Object action) {
   KeyMap km = in.getKeys();
   for (int i = 0; i < shortcut.length(); i++) {
     final Object value = km.getBound(Character.toString(shortcut.charAt(i)));
     if (value instanceof KeyMap) {
       km = (KeyMap) value;
     } else {
       km.bind(shortcut.substring(i), action);
     }
   }
 }
Ejemplo n.º 5
0
  Console(
      final InputStream cmdin,
      final PrintStream cmdout,
      final File historyFile,
      final NashornCompleter completer,
      final Function<String, String> docHelper)
      throws IOException {
    this.historyFile = historyFile;

    TerminalFactory.registerFlavor(
        Flavor.WINDOWS, isCygwin() ? JJSUnixTerminal::new : JJSWindowsTerminal::new);
    TerminalFactory.registerFlavor(Flavor.UNIX, JJSUnixTerminal::new);
    in = new ConsoleReader(cmdin, cmdout);
    in.setExpandEvents(false);
    in.setHandleUserInterrupt(true);
    in.setBellEnabled(true);
    in.setCopyPasteDetection(true);
    final Iterable<String> existingHistory =
        historyFile.exists() ? Files.readAllLines(historyFile.toPath()) : null;
    in.setHistory(
        new EditingHistory(in, existingHistory) {
          @Override
          protected boolean isComplete(CharSequence input) {
            return completer.isComplete(input.toString());
          }
        });
    in.addCompleter(completer);
    Runtime.getRuntime().addShutdownHook(new Thread((Runnable) this::saveHistory));
    bind(DOCUMENTATION_SHORTCUT, (ActionListener) evt -> showDocumentation(docHelper));
  }
Ejemplo n.º 6
0
 private void showDocumentation(final Function<String, String> docHelper) {
   final String buffer = in.getCursorBuffer().buffer.toString();
   final int cursor = in.getCursorBuffer().cursor;
   final String doc = docHelper.apply(buffer.substring(0, cursor));
   try {
     if (doc != null) {
       in.println();
       in.println(doc);
       in.redrawLine();
       in.flush();
     } else {
       in.beep();
     }
   } catch (IOException ex) {
     throw new IllegalStateException(ex);
   }
 }
Ejemplo n.º 7
0
 EditingHistory getHistory() {
   return (EditingHistory) in.getHistory();
 }
Ejemplo n.º 8
0
 String readLine(final String prompt) throws IOException {
   return in.readLine(prompt);
 }