public String processCommandEntry() { // parse out the command text String promptText = prompt_.getElement().getInnerText(); String commandText = input_.getCode(); input_.setText(""); // Force render to avoid subtle command movement in the console, caused // by the prompt disappearing before the input line does input_.forceImmediateRender(); prompt_.setHTML(""); SpanElement pendingPrompt = Document.get().createSpanElement(); pendingPrompt.setInnerText(promptText); pendingPrompt.setClassName(styles_.prompt() + " " + KEYWORD_CLASS_NAME); if (!suppressPendingInput_ && !input_.isPasswordMode()) { SpanElement pendingInput = Document.get().createSpanElement(); pendingInput.setInnerText(StringUtil.notNull(commandText).split("\n")[0] + "\n"); pendingInput.setClassName(styles_.command() + " " + KEYWORD_CLASS_NAME); pendingInput_.getElement().appendChild(pendingPrompt); pendingInput_.getElement().appendChild(pendingInput); pendingInput_.setVisible(true); } ensureInputVisible(); return commandText; }
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(); }