code: def ensure_vbounds(self, use_margins=None):
          
          if (use_margins or mo.DECOM in self.mode) and self.margins is not None:
              top, bottom = self.margins
          else:
              top, bottom = 0, self.lines - 1
  
          self.cursor.y = min(max(top, self.cursor.y), bottom)
docs: Ensure the cursor is within vertical screen bounds.
  
          :param bool use_margins: when ``True`` or when
                                   :data:`~pyte.modes.DECOM` is set,
                                   cursor is bounded by top and and bottom
                                   margins, instead of ``[0; lines - 1]``.