'Ensure that current cursor position is within 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]``.'

def ensure_bounds(self, use_margins=None):

    if (use_margins or (mo.DECOM in self.mode)):
        (top, bottom) = self.margins
    else:
        (top, bottom) = (0, (self.lines - 1))
    self.cursor.x = min(max(0, self.cursor.x), (self.columns - 1))
    self.cursor.y = min(max(top, self.cursor.y), bottom)
