public void escapeText(@NotNull String text, @NotNull Key outputType, @NotNull ColoredTextAcceptor textAcceptor) {
    AnsiStreamingLexer effectiveLexer;
    AnsiTerminalEmulator effectiveEmulator;
    if (ProcessOutputType.isStdout(outputType)) {
      effectiveLexer = myStdoutLexer;
      effectiveEmulator = myStdoutEmulator;
    }
    else if (ProcessOutputType.isStderr(outputType)) {
      effectiveLexer = myStderrLexer;
      effectiveEmulator = myStderrEmulator;
    }
    else {
      processTextWithoutAnsi(text, outputType, textAcceptor);
      return;
    }

    List<Pair<String, Key>> chunks = null;

    //noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (effectiveLexer) {
      effectiveLexer.append(text);
      effectiveLexer.advance();

      AnsiElementType elementType;
      while ((elementType = effectiveLexer.getElementType()) != null) {
        String elementText = effectiveLexer.getElementTextSmart();
        assert elementText != null;
        if (elementType == AnsiStreamingLexer.SGR) {
          effectiveEmulator.processSgr(elementText);
        }
        else if (elementType == AnsiStreamingLexer.TEXT) {
          chunks = processTextChunk(chunks, elementText, outputType, textAcceptor);
        }
        else {
          assert elementType == AnsiStreamingLexer.CONTROL;
          // Commands other than SGR are unhandled currently. Extend here when it's needed.
        }
        effectiveLexer.advance();
      }
    }

    if (chunks != null && textAcceptor instanceof ColoredChunksAcceptor) {
      ((ColoredChunksAcceptor)textAcceptor).coloredChunksAvailable(chunks);
    }
  }
public void escapeText(@NotNull String text, @NotNull Key outputType, @NotNull ColoredTextAcceptor textAcceptor)