How to use the iterm2.capabilities 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 / tab.py View on Github external
async def async_select_pane_in_direction(
            self, direction: NavigationDirection) -> typing.Optional[str]:
        """
        Activates a split pane adjacent to the currently selected pane.
        Requires iTerm2 version 3.3.2.

        :param direction: Specifies the direction to move. For example, LEFT
            will cause the pane to the left of the currently active one.
        :returns: The ID of the newly selected session ID, or None if there was
            no session in that direction.

        :throws: :class:`~iterm2.rpc.RPCException` if something goes wrong.
        """
        if not iterm2.capabilities.supports_select_pane_in_direction(
                self.connection):
            raise iterm2.capabilities.AppVersionTooOld()

        invocation = iterm2.util.invocation_string(
            "iterm2.select_pane_in_direction",
            {"direction": direction.value})
        return await iterm2.rpc.async_invoke_method(
            self.connection, self.tab_id, invocation, -1)
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / session.py View on Github external
Sets the value of properties in this session.

        When you use this function the underlying profile is not modified. The
        session will keep a copy of its profile with these modifications.

        :param write_only_profile: A write-only profile that has the desired
            changes.

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

        .. seealso::
          * Example ":ref:`copycolor_example`"
          * Example ":ref:`settabcolor_example`"
          * Example ":ref:`increase_font_size_example`"
        """
        if iterm2.capabilities.supports_multiple_set_profile_properties(
                self.connection):
            assignments: typing.List[typing.Tuple[str, str]] = []
            for key, json_value in write_only_profile.values.items():
                assignments += [(key, json_value)]
            response = await iterm2.rpc.async_set_profile_properties_json(
                self.connection,
                self.session_id,
                assignments)
            status = response.set_profile_property_response.status
            # pylint: disable=no-member
            if (status != iterm2.api_pb2.SetProfilePropertyResponse.
                    Status.Value("OK")):
                raise iterm2.rpc.RPCException(
                    iterm2.api_pb2.SetProfilePropertyResponse.Status.Name(
                        status))
            return
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / statusbar.py View on Github external
async def async_set_unread_count(
            self, session_id: typing.Optional[str], count: int):
        """
        Sets the unread count that is displayed in the status bar component. If
        0, it is removed.

        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)
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / session.py View on Github external
async def async_run_coprocess(self, command_line: str) -> bool:
        """
        Runs a coprocess, provided non is already running.

        :param command_line: The command line for the new coprocess.

        :returns: True if it was launched or False if one was already running.
        """
        iterm2.capabilities.check_supports_coprocesses(self.connection)
        invocation = iterm2.util.invocation_string(
            "iterm2.run_coprocess",
            {"commandLine": command_line})
        return bool(
            await iterm2.rpc.async_invoke_method(
                self.connection, self.session_id, invocation, -1))
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / tab.py View on Github external
async def async_select_pane_in_direction(
            self, direction: NavigationDirection) -> typing.Optional[str]:
        """
        Activates a split pane adjacent to the currently selected pane.
        Requires iTerm2 version 3.3.2.

        :param direction: Specifies the direction to move. For example, LEFT
            will cause the pane to the left of the currently active one.
        :returns: The ID of the newly selected session ID, or None if there was
            no session in that direction.

        :throws: :class:`~iterm2.rpc.RPCException` if something goes wrong.
        """
        if not iterm2.capabilities.supports_select_pane_in_direction(
                self.connection):
            raise iterm2.capabilities.AppVersionTooOld()

        invocation = iterm2.util.invocation_string(
            "iterm2.select_pane_in_direction",
            {"direction": direction.value})
        return await iterm2.rpc.async_invoke_method(
            self.connection, self.tab_id, invocation, -1)
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / statusbar.py View on Github external
async def async_set_unread_count(
            self, session_id: typing.Optional[str], count: int):
        """
        Sets the unread count that is displayed in the status bar component. If
        0, it is removed.

        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)
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / prompt.py View on Github external
async def async_get(
            self) -> typing.Tuple['PromptMonitor.Mode', typing.Any]:
        """Blocks until a new shell prompt is received.

        Note: Older versions of the runtime that do not support modes other
        than PROMPT always return None.

        :returns: A tuple of (PROMPT,None), (COMMAND_START,Str), or
            (COMMAND_END,Int) where the Str gives the command being run and the
            Int gives the exit status of the command."""
        message = await self.__queue.get()
        if not iterm2.capabilities.supports_prompt_monitor_modes(
                self.connection):
            return (PromptMonitor.Mode.PROMPT, None)
        which = message.WhichOneof('event')
        if which == 'prompt' or which is None:
            return (PromptMonitor.Mode.PROMPT, None)
        if which == 'command_start':
            return (PromptMonitor.Mode.COMMAND_START,
                    message.command_start.command)
        if which == 'command_end':
            return (PromptMonitor.Mode.COMMAND_END, message.command_end.status)
        raise iterm2.rpc.RPCException(
            f'Unexpected oneof in prompt notification: {message}')
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / prompt.py View on Github external
self,
            connection: iterm2.connection.Connection,
            session_id: str,
            modes: typing.Optional[typing.List[Mode]] = None):
        if modes is None:
            modes = [PromptMonitor.Mode.PROMPT]
        self.connection = connection
        self.session_id = session_id
        self.__modes = modes
        self.__token = None
        self.__queue: asyncio.Queue = asyncio.Queue(
            loop=asyncio.get_event_loop())
        if (modes != [PromptMonitor.Mode.PROMPT] and
                not iterm2.capabilities.supports_prompt_monitor_modes(
                    connection)):
            raise iterm2.capabilities.AppVersionTooOld(
                "This version of iTerm2 is too old to handle the " +
                "requested prompt monitor modes (only PROMPT is " +
                "supported in this version). You should upgrade to " +
                "run this script.")
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / profile.py View on Github external
async def async_get_default(
            connection: iterm2.connection.Connection,
            properties: typing.List[str] = [
                "Guid", "Name"]) -> 'PartialProfile':
        """Returns the default profile."""
        iterm2.capabilities.check_supports_get_default_profile(connection)
        result = await iterm2.rpc.async_get_default_profile(connection)
        guid = (result.preferences_response.results[0].
                get_default_profile_result.guid)
        profiles = await PartialProfile.async_query(
            connection, [guid], properties)
        return profiles[0]
    # pylint: enable=dangerous-default-value