How to use the iterm2.util 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 / session.py View on Github external
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 / session.py View on Github external
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 output_range(self) -> iterm2.util.CoordRange:
        """
        Gives the :class:`~iterm2.util.CoordRange` of the output of a command
        following a shell prompt.
        """
        return iterm2.util.CoordRange.from_proto(self.__proto.output_range)
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 / statusbar.py View on Github external
Requires iTerm2 version 3.3.2.

        :param session_id: The session identifier, or none to update all
            instances.
        :param count: The number to show, or 0 to remove it.
        :raises: AppVersionTooOld if not supported by this version of iTerm2.
        """
        if not iterm2.capabilities.supports_status_bar_unread_count(
                self.__connection):
            raise iterm2.capabilities.AppVersionTooOld(
                ("Unread count in status bar components is not " +
                 "supported in this version of iTerm2. Please upgrade " +
                 "to use this script."))

        invocation = iterm2.util.invocation_string(
            "iterm2.set_status_bar_component_unread_count",
            {"identifier": self.__identifier,
             "count": count})
        if session_id:
            await iterm2.rpc.async_invoke_method(
                self.__connection, session_id, invocation, -1)
        else:
            assert self.__connection
            await iterm2.async_invoke_function(self.__connection, invocation)