src/main/java/org/vaadin/console/client/ui/TextConsole.java
changeset 7 a778386e297f
parent 6 8a7e51bd3ddb
child 8 1f4c68061547
     1.1 --- a/src/main/java/org/vaadin/console/client/ui/TextConsole.java	Wed May 18 15:04:22 2011 +0400
     1.2 +++ b/src/main/java/org/vaadin/console/client/ui/TextConsole.java	Wed May 18 22:18:43 2011 +0400
     1.3 @@ -529,6 +529,41 @@
     1.4  
     1.5          reducePrompt(linesAdded);
     1.6      }
     1.7 +
     1.8 +	public void print(String string, String className) {
     1.9 +		if (isPromptActive()) {
    1.10 +			setPromtActive(false);
    1.11 +			if (!bufferIsEmpty() && !bufferEndsWithNewLine()) {
    1.12 +				newLine();
    1.13 +				reducePrompt(-1);
    1.14 +			}
    1.15 +			string = getCurrentPromptContent() + string;
    1.16 +		}
    1.17 +		final boolean doWrap = config.isWrap();
    1.18 +		// _log("print original: '" + string + "' (" + doWrap + ")");
    1.19 +		String str = string.replaceAll("\t", tabs);
    1.20 +		int linesAdded = 0;
    1.21 +
    1.22 +		Element classedChild = Document.get().createElement("span");
    1.23 +		classedChild.addClassName(className);
    1.24 +		buffer.appendChild(classedChild);
    1.25 +		// Split by the newlines anyway
    1.26 +		int s = 0, e = str.indexOf('\n');
    1.27 +		while (e >= s) {
    1.28 +			final String line = str.substring(s, e);
    1.29 +			linesAdded += appendLine(classedChild, line, doWrap ? cols : -1);
    1.30 +			classedChild.appendChild(createBr());
    1.31 +			s = e + 1;
    1.32 +			e = str.indexOf('\n', s);
    1.33 +		}
    1.34 +
    1.35 +		// Print the remaining string
    1.36 +		if (s < str.length()) {
    1.37 +			linesAdded += appendLine(classedChild, str.substring(s), doWrap ? cols : -1);
    1.38 +		}
    1.39 +
    1.40 +		reducePrompt(linesAdded);
    1.41 +	}
    1.42      
    1.43  	public void append(String string) {
    1.44  		if (isPromptActive()) {
    1.45 @@ -566,6 +601,36 @@
    1.46  		reducePrompt(linesAdded);
    1.47  	}
    1.48  
    1.49 +	public void append(String string, String className) {
    1.50 +		if (isPromptActive()) {
    1.51 +			setPromtActive(false);
    1.52 +		}
    1.53 +		final boolean doWrap = config.isWrap();
    1.54 +//		 _log("print original: '" + string + "' (" + doWrap + ")");
    1.55 +		String str = string.replaceAll("\t", tabs);
    1.56 +		int linesAdded = 0;
    1.57 +		
    1.58 +		Element classedChild = Document.get().createElement("span");
    1.59 +		classedChild.addClassName(className);
    1.60 +		buffer.appendChild(classedChild);
    1.61 +		// Split by the newlines anyway
    1.62 +		int s = 0, e = str.indexOf('\n');
    1.63 +		while (e >= s) {
    1.64 +			final String line = str.substring(s, e);
    1.65 +			linesAdded += appendLine(classedChild, line, doWrap ? cols : -1);
    1.66 +			classedChild.appendChild(createBr());
    1.67 +			s = e + 1;
    1.68 +			e = str.indexOf('\n', s);
    1.69 +		}
    1.70 +		
    1.71 +		// Print the remaining string
    1.72 +		if (s < str.length()) {
    1.73 +			linesAdded += appendLine(classedChild, str.substring(s), doWrap ? cols : -1);
    1.74 +		}
    1.75 +		
    1.76 +		reducePrompt(linesAdded);
    1.77 +	}
    1.78 +
    1.79      private String getCurrentPromptContent() {
    1.80          return prompt.getInnerText() + getInput();
    1.81      }
    1.82 @@ -648,6 +713,10 @@
    1.83          print(string + "\n");
    1.84      }
    1.85  
    1.86 +	public void println(final String string, final String className) {
    1.87 +		print(string + "\n", className);
    1.88 +	}
    1.89 +
    1.90      @Override
    1.91      public void setHeight(final String height) {
    1.92          final int oldh = term.getClientHeight();