src/main/java/org/vaadin/console/client/ui/TextConsole.java
changeset 9 dbc3bbf10535
parent 8 1f4c68061547
equal deleted inserted replaced
8:1f4c68061547 9:dbc3bbf10535
   444                                           return w1-w2;
   444                                           return w1-w2;
   445                                           }-*/;
   445                                           }-*/;
   446 
   446 
   447     public void newLine() {
   447     public void newLine() {
   448         // _log("newline");
   448         // _log("newline");
       
   449     	beforeChangeTerminal();
   449         buffer.appendChild(createBr());
   450         buffer.appendChild(createBr());
   450         checkBufferLimit();
   451         checkBufferLimit();
   451         reducePrompt(1);
   452         reducePrompt(1);
   452     }
   453     }
   453 
   454 
   454 	public void newLineIfNotEndsWithNewLine() {
   455 	public void newLineIfNotEndsWithNewLine() {
   455 		if (!bufferIsEmpty() && !bufferEndsWithNewLine()) {
   456 		if (!bufferIsEmpty() && !bufferEndsWithNewLine()) {
   456 			// _log("newline");
   457 			// _log("newline");
       
   458 			beforeChangeTerminal();
   457 			buffer.appendChild(createBr());
   459 			buffer.appendChild(createBr());
   458 			checkBufferLimit();
   460 			checkBufferLimit();
   459 			reducePrompt(1);
   461 			reducePrompt(1);
   460 		}
   462 		}
   461 	}
   463 	}
   477 		if (isFocused())
   479 		if (isFocused())
   478 			setPromtActive(true);
   480 			setPromtActive(true);
   479 		scrollToEnd();
   481 		scrollToEnd();
   480 		ps.setInnerHTML(cleanPs);
   482 		ps.setInnerHTML(cleanPs);
   481 	}
   483 	}
   482 
   484 	
   483     public void scrollToEnd() {
   485 	private boolean isCheckedScrollState = false;
   484         term.setScrollTop(BIG_NUMBER);
   486 
   485     }
   487 	public void scrollToEnd() {
       
   488 		if (config.isSmartScrollToEnd()) {
       
   489 			if (config.isScrolledToEnd())
       
   490 				term.setScrollTop(BIG_NUMBER);
       
   491 		} else
       
   492 			term.setScrollTop(BIG_NUMBER);
       
   493 		isCheckedScrollState = false;
       
   494 	}
       
   495 	
       
   496 	private void beforeChangeTerminal(){
       
   497 		if(!isCheckedScrollState){
       
   498 			config.setScrolledToEnd(term.getScrollTop() >= term.getScrollHeight() - term.getClientHeight());
       
   499 			isCheckedScrollState = true;
       
   500 		}
       
   501 	}
   486 
   502 
   487     public void prompt() {
   503     public void prompt() {
   488         prompt(null);
   504         prompt(null);
   489     }
   505     }
   490 
   506 
   491     public void print(String string) {
   507     public void print(String string) {
       
   508     	beforeChangeTerminal();
   492         if (isPromptActive()) {
   509         if (isPromptActive()) {
   493             setPromtActive(false);
   510             setPromtActive(false);
   494             if (!bufferIsEmpty() && !bufferEndsWithNewLine()) {
   511             if (!bufferIsEmpty() && !bufferEndsWithNewLine()) {
   495                 newLine();
   512                 newLine();
   496                 reducePrompt(-1);
   513                 reducePrompt(-1);
   529 
   546 
   530         reducePrompt(linesAdded);
   547         reducePrompt(linesAdded);
   531     }
   548     }
   532 
   549 
   533 	public void print(String string, String className) {
   550 	public void print(String string, String className) {
       
   551 		beforeChangeTerminal();
   534 		if (isPromptActive()) {
   552 		if (isPromptActive()) {
   535 			setPromtActive(false);
   553 			setPromtActive(false);
   536 			if (!bufferIsEmpty() && !bufferEndsWithNewLine()) {
   554 			if (!bufferIsEmpty() && !bufferEndsWithNewLine()) {
   537 				newLine();
   555 				newLine();
   538 				reducePrompt(-1);
   556 				reducePrompt(-1);
   564 
   582 
   565 		reducePrompt(linesAdded);
   583 		reducePrompt(linesAdded);
   566 	}
   584 	}
   567     
   585     
   568 	public void append(String string) {
   586 	public void append(String string) {
       
   587 		beforeChangeTerminal();
   569 		final boolean doWrap = config.isWrap();
   588 		final boolean doWrap = config.isWrap();
   570 		// _log("print original: '" + string + "' (" + doWrap + ")");
   589 		// _log("print original: '" + string + "' (" + doWrap + ")");
   571 		String str = string.replaceAll("\t", tabs);
   590 		String str = string.replaceAll("\t", tabs);
   572 
   591 
   573 		// Continue to the last text node if available
   592 		// Continue to the last text node if available
   597 
   616 
   598 		reducePrompt(linesAdded);
   617 		reducePrompt(linesAdded);
   599 	}
   618 	}
   600 
   619 
   601 	public void append(String string, String className) {
   620 	public void append(String string, String className) {
       
   621 		beforeChangeTerminal();
   602 		final boolean doWrap = config.isWrap();
   622 		final boolean doWrap = config.isWrap();
   603 //		 _log("print original: '" + string + "' (" + doWrap + ")");
   623 //		 _log("print original: '" + string + "' (" + doWrap + ")");
   604 		String str = string.replaceAll("\t", tabs);
   624 		String str = string.replaceAll("\t", tabs);
   605 		int linesAdded = 0;
   625 		int linesAdded = 0;
   606 		
   626 		
   815     public int getCols() {
   835     public int getCols() {
   816         return cols;
   836         return cols;
   817     }
   837     }
   818 
   838 
   819     public void reset() {
   839     public void reset() {
       
   840     	beforeChangeTerminal();
   820         setPromtActive(false);
   841         setPromtActive(false);
   821         clearBuffer();
   842         clearBuffer();
   822         setPromptHeight(getRows());
   843         setPromptHeight(getRows());
   823         print(config.getGreeting());
   844         print(config.getGreeting());
   824         prompt();
   845         prompt();