Ejemplo n.º 1
0
  public void consolePrompt(String prompt, boolean showInput) {
    if (prompt != null) prompt = VirtualConsole.consolify(prompt);

    prompt_.getElement().setInnerText(prompt);
    // input_.clear() ;
    ensureInputVisible();

    // Deal gracefully with multi-line prompts
    int promptLines = StringUtil.notNull(prompt).split("\\n").length;
    input_.asWidget().getElement().getStyle().setPaddingTop((promptLines - 1) * 15, Unit.PX);

    input_.setPasswordMode(!showInput);
  }
Ejemplo n.º 2
0
  private boolean output(String text, String className, boolean addToTop) {
    if (text.indexOf('\f') >= 0) clearOutput();

    Node node;
    boolean isOutput = StringUtil.isNullOrEmpty(className) || className.equals(styles_.output());

    if (isOutput && !addToTop && trailingOutput_ != null) {
      // Short-circuit the case where we're appending output to the
      // bottom, and there's already some output there. We need to
      // treat this differently in case the new output uses control
      // characters to pound over parts of the previous output.

      int oldLineCount = DomUtils.countLines(trailingOutput_, true);
      trailingOutputConsole_.submit(text);
      trailingOutput_.setNodeValue(ensureNewLine(trailingOutputConsole_.toString()));
      int newLineCount = DomUtils.countLines(trailingOutput_, true);
      lines_ += newLineCount - oldLineCount;
    } else {
      Element outEl = output_.getElement();

      text = VirtualConsole.consolify(text);
      if (isOutput) {
        VirtualConsole console = new VirtualConsole();
        console.submit(text);
        String consoleSnapshot = console.toString();

        // We use ensureNewLine to make sure that even if output
        // doesn't end with \n, a prompt will appear on its own line.
        // However, if we call ensureNewLine indiscriminantly (i.e.
        // on an output that's going to be followed by another output)
        // we can end up inserting newlines where they don't belong.
        //
        // It's safe to add a newline when we're appending output to
        // the end of the console, because if the next append is also
        // output, we'll use the contents of VirtualConsole and the
        // newline we add here will be plowed over.
        //
        // If we're prepending output to the top of the console, then
        // it's safe to add a newline if the next chunk (which is already
        // there) is something besides output.
        if (!addToTop
            || (!outEl.hasChildNodes() || outEl.getFirstChild().getNodeType() != Node.TEXT_NODE)) {
          consoleSnapshot = ensureNewLine(consoleSnapshot);
        }

        node = Document.get().createTextNode(consoleSnapshot);
        if (!addToTop) {
          trailingOutput_ = (Text) node;
          trailingOutputConsole_ = console;
        }
      } else {
        SpanElement span = Document.get().createSpanElement();
        span.setClassName(className);
        span.setInnerText(text);
        node = span;
        if (!addToTop) {
          trailingOutput_ = null;
          trailingOutputConsole_ = null;
        }
      }

      if (addToTop) outEl.insertFirst(node);
      else outEl.appendChild(node);

      lines_ += DomUtils.countLines(node, true);
    }
    return !trimExcess();
  }