Example #1
0
 @Override
 public void setAnsiSupported(final boolean value) {
   if (value != isAnsiSupported()) {
     try {
       if (value) {
         configureOSTerminal();
       } else {
         TerminalFactory.configure(TerminalFactory.Type.NONE);
         TerminalFactory.reset();
       }
       initReaderAndStreams();
     } catch (IOException e) {
       throw new RuntimeException("Failed to reset Terminal instance for ANSI configuration", e);
     }
   }
 }
Example #2
0
 private void configureOSTerminal() throws IOException {
   if (OSUtils.isLinux() || OSUtils.isOSX()) {
     TerminalFactory.configure(TerminalFactory.Type.UNIX);
     TerminalFactory.reset();
   } else if (OSUtils.isWindows()) {
     TerminalFactory.configure(TerminalFactory.Type.WINDOWS);
     TerminalFactory.reset();
   } else {
     TerminalFactory.configure(TerminalFactory.Type.NONE);
     TerminalFactory.reset();
   }
   initReaderAndStreams();
 }
Example #3
0
  private void initReaderAndStreams() throws IOException {
    boolean noInitMode = isNoInitMode();
    if ((_redirectedStream == null) && noInitMode) {
      return;
    }

    if ((inputPipe == null) && (_redirectedStream == null)) {
      inputPipe = new ConsoleInputSession(System.in);
    }
    if (outputStream == null) {
      outputStream = System.out;
    }

    Terminal terminal;
    if (Boolean.getBoolean("forge.compatibility.IDE")) {
      terminal = new IdeTerminal();
    } else if (OSUtils.isWindows()) {
      final OutputStream ansiOut = AnsiConsole.wrapOutputStream(System.out);

      TerminalFactory.configure(TerminalFactory.Type.WINDOWS);
      terminal = TerminalFactory.get();

      final OutputStreamWriter writer =
          new OutputStreamWriter(
              ansiOut,
              System.getProperty(
                  "jline.WindowsTerminal.output.encoding", System.getProperty("file.encoding")));

      outputStream =
          new OutputStream() {
            @Override
            public void write(final int b) throws IOException {
              writer.write(b);
              writer.flush();
            }
          };
    } else {
      terminal = TerminalFactory.get();
    }

    this.screenBuffer = new JLineScreenBuffer(terminal, outputStream);
    this.reader =
        new ConsoleReader(
            _redirectedStream == null ? inputPipe.getExternalInputStream() : _redirectedStream,
            this,
            null,
            terminal);
    this.reader.setHistoryEnabled(true);
    this.reader.setBellEnabled(false);

    for (TriggeredAction action : triggeredActions) {
      this.reader.addTriggeredAction(action.getTrigger(), action.getListener());
    }

    if (noInitMode) {
      if (_historyOverride != null) {

        _setHistory(_historyOverride);
      }

      if (_deferredCompleters != null) {
        for (Completer completer : _deferredCompleters) {
          _initCompleters(completer);
        }
      }
    }
  }