public void clearLast ( int N ) { if ( N < 1 ) { throw new IllegalArgumentException ( "Unable to clear " + N + " lines" ) ; } if ( N > count ( ) ) { throw new IllegalArgumentException ( "Count: " + N + ", Size: " + count ( ) ) ; } if ( N == count ( ) ) { clear ( ) ; return ; } terminal . format ( "\r%s" , CURSOR_ERASE ) ; buffer . remove ( buffer . size ( ) - 1 ) ; for ( int i = 1 ; i < N ; ++ i ) { terminal . format ( "%s%s" , UP , CURSOR_ERASE ) ; buffer . remove ( buffer . size ( ) - 1 ) ; } terminal . format ( "%s\r%s" , UP , cursorRight ( printableWidth ( lastLine ( ) ) ) ) ; }
Clear the last N lines and move the cursor to the end of the last remaining line .