At initial stage, cursor is at the end of stream output. This method makes cursor crawl upwards until it hits
current section. Then it erases content it crawled through. Optionally, it erases part of current section too.
161842
private function popStreamContentUntilCurrentSection(int $numberOfLinesToClearFromCurrentSection = 0): string
    {
        $numberOfLinesToClear = $numberOfLinesToClearFromCurrentSection;
        $erasedContent = [];

        foreach ($this->sections as $section) {
            if ($section === $this) {
                break;
            }

            $numberOfLinesToClear += $section->lines;
            $erasedContent[] = $section->getContent();
        }

        if ($numberOfLinesToClear > 0) {
            // move cursor up n lines
            parent::doWrite(sprintf("\x1b[%dA", $numberOfLinesToClear), false);
            // erase to end of screen
            parent::doWrite("\x1b[0J", false);
        }

        return implode('', array_reverse($erasedContent));
    }
246614
public static void dumpCurrentRow(Cursor cursor, PrintStream stream) {
        String[] cols = cursor.getColumnNames();
        stream.println("" + cursor.getPosition() + " {");
        int length = cols.length;
        for (int i = 0; i< length; i++) {
            String value;
            try {
                value = cursor.getString(i);
            } catch (SQLiteException e) {
                // assume that if the getString threw this exception then the column is not
                // representable by a string, e.g. it is a BLOB.
                value = "<unprintable>";
            }
            stream.println("   " + cols[i] + '=' + value);
        }
        stream.println("}");
    }
1258767
void redrawRestOfLine() {
        //The number of lines to reach the end of the frame.
        int maxLinesToRepaint = terminal.getHeight() - getFooterSize() - frameLine;
        LinkedList<String> toRepaintLines = new LinkedList<String>();
        String currentLine = getContent(getLine());
        toRepaintLines.addAll(toDisplayLines(currentLine));
        //Remove already shown lines
        int remainingLines = (getColumn() - 1) / terminal.getWidth();
        for (int r = 0; r < remainingLines; r++) {
            toRepaintLines.removeFirst();
        }

        saveCursorPosition();
        for (int l = 0; l < Math.min(maxLinesToRepaint, toRepaintLines.size()); l++) {
            console.out().print(ansi().cursor(frameLine + getHeaderSize() + l, 1));
            console.out().print(ansi().eraseLine(Erase.FORWARD));
            displayText(toRepaintLines.get(l));
        }
        restoreCursorPosition();
    }
580
boolean remove(RowCursor cursor)
  {
    int rowHead = _rowHead;
    int blobTail = _blobTail;
    
    rowHead -= cursor.removeLength();

    if (rowHead < blobTail) {
      return false;
    }
    
    byte []buffer = _buffer;
    
    // buffer[rowHead] = REMOVE;
    
    cursor.getRemove(buffer, rowHead);
    // cursor.getKey(buffer, rowHead + ColumnState.LENGTH);
    
    rowHead(rowHead);
    
    validateBlock(cursor.row());    
    
    return true;
  }
311510
void progress(int cur, int max) {
    StringBuilder out = new StringBuilder();

    if (lastProgress != null) {
      char[] back = new char[lastProgress.length()];
      Arrays.fill(back, '\b');
      out.append(back);
    }

    String progress =
        cur + "/" + (max == -1 ? "?" : "" + max) + " "
            + (max == -1 ? "(??%)"
            : "(" + cur * 100 / (max == 0 ? 1 : max) + "%)");

    if (cur >= max && max != -1) {
      progress += " " + loc("done") + SEPARATOR;
      lastProgress = null;
    } else {
      lastProgress = progress;
    }

    out.append(progress);

    getOutputStream().print(out.toString());
    getOutputStream().flush();
  }
1076769
def flush(self):
        
        if self._writable:
            with self._seek_lock:
                buffer = self._get_buffer()

                # Flush that part of the file
                end = self._seek
                start = end - len(buffer)

                # Clear buffer
                self._write_buffer = bytearray()

            # Flush content
            with handle_os_exceptions():
                self._flush(buffer, start, end)
651618
int findAndFill(RowCursor cursor)
  {
    int ptr = find(cursor);

    if (ptr >= 0) {
      cursor.setRow(_buffer, ptr);
      cursor.setLeafBlock(this, ptr);
    }
    
    return ptr;
  }
29779
function Cursor() {
  // If true, cursor should be rendered to the right of the char at offset p-1
  // rather than at the left edge of the char at offset p. This can happen when
  // user presses the "end" key or clicks past the end of a line.
  this.rightEnd = false;

  // Used for tracking previous left position in pixels, needed to implement
  // up/down arrows.
  this.prevLeft = null;

  // Used for rendering. Row is also needed to implement up/down arrows.
  this.row = 0;   // row (line number)
  this.left = 0;  // left position, in pixels

  this.blinkTimer_ = 0;

  this.el_ = createDiv({
    position: 'absolute',
    width: '2px',
    backgroundColor: '#000',
    zIndex: '2'
  });

  window.setInterval((function() {
    if (this.blinkTimer_ === -1) return;
    this.blinkTimer_ = (this.blinkTimer_ + 1) % 10;
    // Visible 60% of the time, hidden 40% of the time.
    this.el_.style.visibility = (this.blinkTimer_ < 6) ? 'visible' : 'hidden';
  }).bind(this), 100);
}
182046
function(start, end, direction) {
      var current = (start = startOfLine(start)), before = start && startOfLine(start.previousSibling);
      if (!isBR(end)) end = endOfLine(end, this.container);
      this.addDirtyNode(start);

      do {
        var next = endOfLine(current, this.container);
        if (current) this.highlight(before, next, true);
        this.indentLineAfter(current, direction);
        before = current;
        current = next;
      } while (current != end);
      select.setCursorPos(this.container, {node: start, offset: 0}, {node: end, offset: 0});
    }
1325314
private void endMainBlock() {
        BlockTabRec btr = blockTab[0];
        btr.tPosContentsEnd = templateText.length();
        btr.tPosEnd = templateText.length();
        btr.definitionIsOpen = false;
        currentNestingLevel--;
    }
1043904
def end_of_line(event):
    "  "
    buff = event.current_buffer
    buff.cursor_position += buff.document.get_end_of_line_position()
345941
private boolean commentLinesBefore( String content, int line )
  {
    int offset = _root.getElement( line ).getStartOffset();
    // Start of comment not found, nothing to do
    int startDelimiter = lastIndexOf( content, getStartDelimiter(), offset - 2 );
    if( startDelimiter < 0 )
    {
      return false;
    }
    // Matching start/end of comment found, nothing to do
    int endDelimiter = indexOf( content, getEndDelimiter(), startDelimiter );
    if( endDelimiter < offset & endDelimiter != -1 )
    {
      return false;
    }
    // End of comment not found, highlight the lines
    setCharacterAttributes( startDelimiter, offset - startDelimiter + 1, _comment, false );
    return true;
  }
894308
public boolean endOfData(TextProvider textProvider)        
    {
    	clearLastToken(textProvider);
    	clearLeadingSpaces(textProvider);
    	mark(textProvider);
    	if (m_debug)
    		debug("testing",textProvider);
    	try
    	{
    		char c = getNextChar(textProvider);
    		if (c == 0) {
    			unmark(textProvider);
    			return true;
    		}
    	}
    	catch (Exception e)
    	{
			unmark(textProvider);
        	debug(textProvider);
    		return true;
    	}
    	reset(textProvider);
    	return false;
    }
474846
public synchronized void moveToBottom()
  {
    if (tc.isEntryEnabled())
      SibTr.entry(tc, "moveToBottom");

    checkEntryParent();
    
    //record the parent list
    LinkedList list = parentList;
    synchronized(list)
    {
      //remove the cursor from it current position
      forceRemove();
      //reset the parent list
      parentList = list;
      //mark it as at the bottom
      atBottom = true;
      
      //insert it in front of the old first bottom cursor
      next = list.firstBottomCursor;
      if(next != null) next.previous = this;
      //mark this on as the first bottom cursor
      list.firstBottomCursor = this;      
    }    
    
    if (tc.isEntryEnabled())
      SibTr.exit(tc, "moveToBottom");
  }
1207941
def erase_down (self): # <ESC>[0J -or- <ESC>[J
        ''''''

        self.erase_end_of_line ()
        self.fill_region (self.cur_r + 1, 1, self.rows, self.cols)
1246378
public void finish() {
        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE))  //306998.15
            logger.entering(CLASS_NAME,"finish","["+this+"]");

        if (!isCommitted()) {
            commit();
        }

        // flush the OutputStream and Writer
        try {
            flushBuffer(false);
            _rawOut.close();
        }
        catch (IOException e) {
            // Don't want to report errors on early browser closes
            if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)) {  //306998.15
                logger.logp(Level.FINE, CLASS_NAME,"finish", "Servlet.Exception:.Error.while.finishing.response", e);
            }
        }
        finally {
            _rawOut.reset();
            // PK29451 - remove call to clearHeaders(). Implementation of clearHeaders() was empty,
            // which this method relies on, but has been implemented in PK29451 to make reset() work.
            // _response.clearHeaders();
            
            cleanupFromFinish();
            // LIBERTY _bufferedOut.reset();
            _bufferedWriter.reset();
            // LIBERTY this._responseBuffer = null;
        }

        resetState();

        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE))  //306998.15
            logger.exiting(CLASS_NAME,"finish");
    }
816905
@SuppressWarnings("unused")
    public void clearCompletionText() {
        //Respect currentCompletionText in case hint is visible or if other checks are added.
        if (currentCompletionText().length() == 0){
            return;
        }

        Range currentRange = getCurrentCandidateTokenRange();
        internalEditInProgress = true;
        getText().delete(currentRange.start, currentRange.end);
        internalEditInProgress = false;
    }