def set_cursor(self, offset, whence=0):
        """
        Set cursor within the modifiable range.
        :param offset:
        :param whence:
        """
        # Lock the main_screen for modification
        with self.main_screen.acquire_lock():
            self._ensure_main_screen_consistency()

            modifiable_xs, modifiable_xe = self.main_screen.modifiable_range

            if whence == 1:  # current position
                new_cursor_x = self.main_screen.cursor_xs + offset
            elif whence == 2:  # from the end
                new_cursor_x = modifiable_xe + offset
            else:  # default from start
                new_cursor_x = modifiable_xs + offset

            if new_cursor_x < modifiable_xs:
                new_cursor_x = modifiable_xs
            elif new_cursor_x > modifiable_xe:
                new_cursor_x = modifiable_xe

            # Ensure the cursor position is within the modifiable range
            self.main_screen.cursor_x = new_cursor_x

        self.stash.renderer.render(no_wait=True)

        Set cursor within the modifiable range.
        :param offset:
        :param whence:
        
system/shstreams.py