How to use the iterm2.util.CoordRange function in iterm2

To help you get started, we’ve selected a few iterm2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / selection.py View on Github external
# The ranges may be out of order so put them in an array and then sort
        # it.
        all_ranges = []

        # pylint: disable=invalid-name
        def f(values):
            i, x = values
            return i - x
        # pylint: enable=invalid-name

        # Iterate contiguous ranges
        # pylint: disable=unused-variable
        for k, range_group in itertools.groupby(enumerate(sorted(indexes)), f):
            # range exists in both indexes and the_range
            values_in_range = list(map(itemgetter(1), range_group))
            coord_range = iterm2.util.CoordRange(
                iterm2.util.Point(
                    min(values_in_range) % width,
                    min(values_in_range) // width),
                iterm2.util.Point(
                    max(values_in_range) % width,
                    max(values_in_range) // width))
            all_ranges.append(coord_range)

        def range_key(a_range):
            return a_range.start.y * width + a_range.start.x

        sorted_ranges = sorted(all_ranges, key=range_key)
        for idx, the_range in enumerate(sorted_ranges):
            end_index = (
                the_range.start.x +
                the_range.start.y * width +
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / session.py View on Github external
unavailable then a subset is returned.

        :throws: :class:`~iterm2.rpc.RPCException` if something goes wrong.

        .. code-block:: python
          :caption: Example that prints the first ten lines of `session`.


          async with iterm2.Transaction(connection) as txn:
            li = await session.async_get_line_info()
            lines = await session.async_get_contents(li.overflow, 10)
          print(list(map(lambda line: line.string, lines)))

        """
        coord_range = iterm2.util.WindowedCoordRange(
            iterm2.util.CoordRange(
                iterm2.util.Point(0, first_line),
                iterm2.util.Point(0, first_line + number_of_lines)))

        response = await iterm2.rpc.async_get_screen_contents(
            self.connection,
            self.session_id,
            coord_range)
        # pylint: disable=no-member
        if (response.get_buffer_response.status ==
                iterm2.api_pb2.GetBufferResponse.Status.Value("OK")):
            contents = iterm2.screen.ScreenContents(
                response.get_buffer_response)
            result = []
            for i in range(contents.number_of_lines):
                result.append(contents.line(i))
            return result
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / prompt.py View on Github external
def prompt_range(self) -> iterm2.util.CoordRange:
        """Gives the :class:`~iterm2.util.CoordRange` of a shell prompt."""
        return iterm2.util.CoordRange.from_proto(self.__proto.prompt_range)
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / screen.py View on Github external
def windowed_coord_range(self) -> iterm2.util.WindowedCoordRange:
        """The line number of the first line in this object."""
        return iterm2.util.WindowedCoordRange(
            iterm2.util.CoordRange(
                iterm2.util.Point(
                    self.__proto.windowed_coord_range.coord_range.start.x,
                    self.__proto.windowed_coord_range.coord_range.start.y),
                iterm2.util.Point(
                    self.__proto.windowed_coord_range.coord_range.end.x,
                    self.__proto.windowed_coord_range.coord_range.end.y)),
            iterm2.util.Range(
                self.__proto.windowed_coord_range.columns.location,
                self.__proto.windowed_coord_range.columns.length))
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / selection.py View on Github external
def enumerate_ranges(self, callback):
        """Invoke callback for each selected range."""
        if self.__windowed_coord_range.hasWindow:
            right = self.__windowed_coord_range.right
            start_x = self.__windowed_coord_range.start.x
            y = self.__windowed_coord_range.coordRange.start.y
            while y < self.__windowed_coord_range.coordRange.end.y:
                callback(iterm2.util.CoordRange(
                    iterm2.util.Point(start_x, y),
                    iterm2.util.Point(right, y)))
                start_x = self.__windowed_coord_range.left

                y += 1

            callback(iterm2.util.CoordRange(
                iterm2.util.Point(
                    start_x,
                    self.__windowed_coord_range.coordRange.end.y),
                iterm2.util.Point(
                    self.__windowed_coord_range.end.x,
                    self.__windowed_coord_range.coordRange.end.y)))
        else:
            callback(self.__windowed_coord_range.coordRange, self)
    # pylint: enable=invalid-name
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / session.py View on Github external
self.connection, self.session_id)
        status = response.selection_response.status
        # pylint: disable=no-member
        if status != iterm2.api_pb2.SelectionResponse.Status.Value("OK"):
            raise iterm2.rpc.RPCException(
                iterm2.api_pb2.SelectionResponse.Status.Name(status))
        subs = []
        for sub_proto in (response.selection_response.get_selection_response.
                          selection.sub_selections):
            start = iterm2.util.Point(
                sub_proto.windowed_coord_range.coord_range.start.x,
                sub_proto.windowed_coord_range.coord_range.start.y)
            end = iterm2.util.Point(
                sub_proto.windowed_coord_range.coord_range.end.x,
                sub_proto.windowed_coord_range.coord_range.end.y)
            coord_range = iterm2.util.CoordRange(start, end)
            column_range = iterm2.util.Range(
                sub_proto.windowed_coord_range.columns.location,
                sub_proto.windowed_coord_range.columns.length)
            windowed_coord_range = iterm2.util.WindowedCoordRange(
                coord_range, column_range)

            sub = iterm2.SubSelection(
                windowed_coord_range,
                iterm2.selection.SelectionMode.from_proto_value(
                    sub_proto.selection_mode),
                sub_proto.connected)
            subs.append(sub)
        return iterm2.Selection(subs)
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / prompt.py View on Github external
def command_range(self) -> iterm2.util.CoordRange:
        """
        Gives the :class:`~iterm2.util.CoordRange` of the command following the
        shell prompt.
        """
        return iterm2.util.CoordRange.from_proto(self.__proto.command_range)