+ client method append(String)
authorindvdum
Tue, 17 May 2011 03:27:01 +0400
changeset 33eab4f9f42a9
parent 2 7226af94d262
child 4 27bd1032a5c6
+ client method append(String)
src/main/java/org/vaadin/console/Console.java
src/main/java/org/vaadin/console/client/ui/TextConsole.java
src/main/java/org/vaadin/console/client/ui/VTextConsole.java
     1.1 --- a/src/main/java/org/vaadin/console/Console.java	Mon May 16 14:34:42 2011 +0400
     1.2 +++ b/src/main/java/org/vaadin/console/Console.java	Tue May 17 03:27:01 2011 +0400
     1.3 @@ -549,6 +549,10 @@
     1.4      public void println(final String string) {
     1.5          client.call("println", string);
     1.6      }
     1.7 +    
     1.8 +    public void append(final String string) {
     1.9 +    	client.call("append", string);
    1.10 +    }
    1.11  
    1.12      public void newLine() {
    1.13          client.call("newLine");
     2.1 --- a/src/main/java/org/vaadin/console/client/ui/TextConsole.java	Mon May 16 14:34:42 2011 +0400
     2.2 +++ b/src/main/java/org/vaadin/console/client/ui/TextConsole.java	Tue May 17 03:27:01 2011 +0400
     2.3 @@ -445,6 +445,7 @@
     2.4      protected void setPs(final String string) {
     2.5          cleanPs = Util.escapeHTML(string);
     2.6          cleanPs = cleanPs.replaceAll(" ", " ");
     2.7 +        ps.setInnerHTML(cleanPs);
     2.8      }
     2.9  
    2.10      public void prompt(final String inputText) {
    2.11 @@ -509,6 +510,42 @@
    2.12  
    2.13          reducePrompt(linesAdded);
    2.14      }
    2.15 +    
    2.16 +	public void append(String string) {
    2.17 +		if (isPromptActive()) {
    2.18 +			setPromtActive(false);
    2.19 +		}
    2.20 +		final boolean doWrap = config.isWrap();
    2.21 +		// _log("print original: '" + string + "' (" + doWrap + ")");
    2.22 +		String str = string.replaceAll("\t", tabs);
    2.23 +
    2.24 +		// Continue to the last text node if available
    2.25 +		final Node last = getLastTextNode();
    2.26 +		int linesAdded = 0;
    2.27 +		if (last != null) {
    2.28 +			// _log("print append to old node: '" + last.getNodeValue() + "'");
    2.29 +			str = last.getNodeValue() + str;
    2.30 +			buffer.removeChild(last);
    2.31 +			linesAdded--;
    2.32 +		}
    2.33 +
    2.34 +		// Split by the newlines anyway
    2.35 +		int s = 0, e = str.indexOf('\n');
    2.36 +		while (e >= s) {
    2.37 +			final String line = str.substring(s, e);
    2.38 +			linesAdded += appendLine(buffer, line, doWrap ? cols : -1);
    2.39 +			buffer.appendChild(createBr());
    2.40 +			s = e + 1;
    2.41 +			e = str.indexOf('\n', s);
    2.42 +		}
    2.43 +
    2.44 +		// Print the remaining string
    2.45 +		if (s < str.length()) {
    2.46 +			linesAdded += appendLine(buffer, str.substring(s), doWrap ? cols : -1);
    2.47 +		}
    2.48 +
    2.49 +		reducePrompt(linesAdded);
    2.50 +	}
    2.51  
    2.52      private String getCurrentPromptContent() {
    2.53          return prompt.getInnerText() + getInput();
     3.1 --- a/src/main/java/org/vaadin/console/client/ui/VTextConsole.java	Mon May 16 14:34:42 2011 +0400
     3.2 +++ b/src/main/java/org/vaadin/console/client/ui/VTextConsole.java	Tue May 17 03:27:01 2011 +0400
     3.3 @@ -80,6 +80,11 @@
     3.4                  println((String) data[0]);
     3.5              }
     3.6          });
     3.7 +        comm.register("append", new Method() {
     3.8 +        	public void invoke(final String methodName, final Object[] data) {
     3.9 +        		append((String) data[0]);
    3.10 +        	}
    3.11 +        });
    3.12          comm.register("prompt", new Method() {
    3.13              public void invoke(final String methodName, final Object[] data) {
    3.14                  prompt((String) (data.length > 0 ? data[0] : null));