# HG changeset patch # User indvdum # Date 1305588421 -14400 # Node ID 3eab4f9f42a92a5b0de503d0a0dd3963761481d9 # Parent 7226af94d2626e24a78e0fba6d33eccaa73ae67b + client method append(String) diff -r 7226af94d262 -r 3eab4f9f42a9 src/main/java/org/vaadin/console/Console.java --- a/src/main/java/org/vaadin/console/Console.java Mon May 16 14:34:42 2011 +0400 +++ b/src/main/java/org/vaadin/console/Console.java Tue May 17 03:27:01 2011 +0400 @@ -549,6 +549,10 @@ public void println(final String string) { client.call("println", string); } + + public void append(final String string) { + client.call("append", string); + } public void newLine() { client.call("newLine"); diff -r 7226af94d262 -r 3eab4f9f42a9 src/main/java/org/vaadin/console/client/ui/TextConsole.java --- a/src/main/java/org/vaadin/console/client/ui/TextConsole.java Mon May 16 14:34:42 2011 +0400 +++ b/src/main/java/org/vaadin/console/client/ui/TextConsole.java Tue May 17 03:27:01 2011 +0400 @@ -445,6 +445,7 @@ protected void setPs(final String string) { cleanPs = Util.escapeHTML(string); cleanPs = cleanPs.replaceAll(" ", " "); + ps.setInnerHTML(cleanPs); } public void prompt(final String inputText) { @@ -509,6 +510,42 @@ reducePrompt(linesAdded); } + + public void append(String string) { + if (isPromptActive()) { + setPromtActive(false); + } + final boolean doWrap = config.isWrap(); + // _log("print original: '" + string + "' (" + doWrap + ")"); + String str = string.replaceAll("\t", tabs); + + // Continue to the last text node if available + final Node last = getLastTextNode(); + int linesAdded = 0; + if (last != null) { + // _log("print append to old node: '" + last.getNodeValue() + "'"); + str = last.getNodeValue() + str; + buffer.removeChild(last); + linesAdded--; + } + + // Split by the newlines anyway + int s = 0, e = str.indexOf('\n'); + while (e >= s) { + final String line = str.substring(s, e); + linesAdded += appendLine(buffer, line, doWrap ? cols : -1); + buffer.appendChild(createBr()); + s = e + 1; + e = str.indexOf('\n', s); + } + + // Print the remaining string + if (s < str.length()) { + linesAdded += appendLine(buffer, str.substring(s), doWrap ? cols : -1); + } + + reducePrompt(linesAdded); + } private String getCurrentPromptContent() { return prompt.getInnerText() + getInput(); diff -r 7226af94d262 -r 3eab4f9f42a9 src/main/java/org/vaadin/console/client/ui/VTextConsole.java --- a/src/main/java/org/vaadin/console/client/ui/VTextConsole.java Mon May 16 14:34:42 2011 +0400 +++ b/src/main/java/org/vaadin/console/client/ui/VTextConsole.java Tue May 17 03:27:01 2011 +0400 @@ -80,6 +80,11 @@ println((String) data[0]); } }); + comm.register("append", new Method() { + public void invoke(final String methodName, final Object[] data) { + append((String) data[0]); + } + }); comm.register("prompt", new Method() { public void invoke(final String methodName, final Object[] data) { prompt((String) (data.length > 0 ? data[0] : null));