def ensure_bounds(self, use_margins=None):
        margins = self.margins
        if margins and use_margins or mo.DECOM in self.mode:
            top, bottom = margins
        else:
            top, bottom = 0, self.lines - 1

        cursor_position = self.pt_cursor_position
        line_offset = self.line_offset

        cursor_position.x = min(max(0, cursor_position.x), self.columns - 1)
        cursor_position.y = min(max(top + line_offset, cursor_position.y),
                                bottom + line_offset + 1)
Ensure that current cursor position is within screen bounds.
dataset/ETHPy150Open jonathanslenders/pymux/pymux/screen.py/BetterScreen.ensure_bounds