How to use the iterm2.api_pb2 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
async def _async_get_content_in_range(
            self, connection, session_id, coord_range):
        """Returns the string in the given range."""
        result = await iterm2.rpc.async_get_screen_contents(
            connection,
            session_id,
            coord_range)
        # pylint: disable=no-member
        if (result.get_buffer_response.status == iterm2.
                api_pb2.GetBufferResponse.Status.Value("OK")):
            screen_contents = iterm2.screen.ScreenContents(
                result.get_buffer_response)
            built_string = ""
            i = 0
            while i < screen_contents.number_of_lines:
                line = screen_contents.line(i)
                i += 1
                built_string += line.string
                if line.hard_eol:
                    built_string += "\n"
            return built_string
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / session.py View on Github external
"""
        Restarts a session.

        :param only_if_exited: When `True`, this will raise an exception if the
            session is still running. When `False`, a running session will be
            killed and restarted.

        :throws: :class:`~iterm2.rpc.RPCException` if something goes wrong.
        """
        result = await iterm2.rpc.async_restart_session(
            self.connection, self.__session_id, only_if_exited)
        status = result.restart_session_response.status
        # pylint: disable=no-member
        if status != iterm2.api_pb2.RestartSessionResponse.Status.Value("OK"):
            raise iterm2.rpc.RPCException(
                iterm2.api_pb2.RestartSessionResponse.Status.Name(status))
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / tool.py View on Github external
duplicate registration attempt.
    :param url: The URL to show in the webview.

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

    .. seealso:: Example ":ref:`targeted_input_example`"
    """
    result = await iterm2.rpc.async_register_web_view_tool(
        connection,
        display_name,
        identifier,
        reveal_if_already_registered,
        url)
    status = result.register_tool_response.status
    # pylint: disable=no-member
    if status == iterm2.api_pb2.RegisterToolResponse.Status.Value("OK"):
        return None
    raise iterm2.rpc.RPCException(result.register_tool_response)
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / rpc.py View on Github external
async def async_restore_arrangement(connection, name, window_id=None):
    """
    Restore a window arrangement.
    """
    request = _alloc_request()
    request.saved_arrangement_request.name = name
    request.saved_arrangement_request.action = (
        iterm2.api_pb2.SavedArrangementRequest.Action.Value("RESTORE"))
    if window_id is not None:
        request.saved_arrangement_request.window_id = window_id
    return await _async_call(connection, request)
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / notifications.py View on Github external
if notification.HasField('keystroke_notification'):
        key = (notification.keystroke_notification.session,
               iterm2.api_pb2.NOTIFY_ON_KEYSTROKE)
        notification = notification.keystroke_notification
    elif notification.HasField('screen_update_notification'):
        key = (notification.screen_update_notification.session,
               iterm2.api_pb2.NOTIFY_ON_SCREEN_UPDATE)
        notification = notification.screen_update_notification
    elif notification.HasField('prompt_notification'):
        key = (notification.prompt_notification.session,
               iterm2.api_pb2.NOTIFY_ON_PROMPT)
        notification = notification.prompt_notification
    elif notification.HasField('location_change_notification'):
        key = (notification.location_change_notification.session,
               iterm2.api_pb2.NOTIFY_ON_LOCATION_CHANGE)
        notification = notification.location_change_notification
    elif notification.HasField('custom_escape_sequence_notification'):
        key = (notification.custom_escape_sequence_notification.session,
               iterm2.api_pb2.NOTIFY_ON_CUSTOM_ESCAPE_SEQUENCE)
        notification = notification.custom_escape_sequence_notification
    elif notification.HasField('new_session_notification'):
        key = (None, iterm2.api_pb2.NOTIFY_ON_NEW_SESSION)
        notification = notification.new_session_notification
    elif notification.HasField('terminate_session_notification'):
        key = (None, iterm2.api_pb2.NOTIFY_ON_TERMINATE_SESSION)
        notification = notification.terminate_session_notification
    elif notification.HasField('layout_changed_notification'):
        key = (None, iterm2.api_pb2.NOTIFY_ON_LAYOUT_CHANGE)
        notification = notification.layout_changed_notification
    elif notification.HasField('focus_changed_notification'):
        key = (None, iterm2.api_pb2.NOTIFY_ON_FOCUS_CHANGE)
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / session.py View on Github external
async def async_get_selection(self) -> iterm2.selection.Selection:
        """
        :returns: The selected regions of this session. The selection will be
            empty if there is no selected text.

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

        .. seealso:: Example ":ref:`georges_title_example`"
        """
        response = await iterm2.rpc.async_get_selection(
            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(
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / session.py View on Github external
def to_session_summary_protobuf(self):
        """Returns the protobuf representation."""
        # pylint: disable=no-member
        summary = iterm2.api_pb2.SessionSummary()
        summary.unique_identifier = self.session_id
        summary.grid_size.width = self.preferred_size.width
        summary.grid_size.height = self.preferred_size.height
        return summary
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / focus.py View on Github external
async with iterm2.FocusMonitor(connection) as monitor:
                while True:
                    update = await monitor.async_get_next_update()
                    if update.selected_tab_changed:
                        print("The active tab is now {}".
                            format(update.selected_tab_changed.tab_id))
        """
        if self.__queue:
            temp = self.__queue[0]
            del self.__queue[0]
            return self.handle_proto(temp)

        future: asyncio.Future = asyncio.Future()
        self.__future = future
        await self.__future
        proto: iterm2.api_pb2.FocusChangedNotification = future.result()
        self.__future = None
        return self.handle_proto(proto)
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / selection.py View on Github external
async def async_get_string(
            self,
            connection: iterm2.connection.Connection,
            session_id: str) -> str:
        """Gets the text belonging to this subselection.

        :param connection: The connection to iTerm2.
        :param session_id: The ID of the session for which to look up the
            selected text.
        """
        result = await iterm2.rpc.async_get_screen_contents(
            connection,
            session_id,
            self.__windowed_coord_range)
        # pylint: disable=no-member
        if (result.get_buffer_response.status == iterm2.
                api_pb2.GetBufferResponse.Status.Value("OK")):
            screen_contents = iterm2.screen.ScreenContents(
                result.get_buffer_response)
            built_string = ""
            i = 0
            while i < screen_contents.number_of_lines:
                line = screen_contents.line(i)
                i += 1
                built_string += line.string
                if line.hard_eol:
                    built_string += "\n"
            return built_string
        raise iterm2.rpc.RPCException(
            iterm2.api_pb2.GetBufferResponse.Status.Name(
                result.get_buffer_response.status))
github gnachman / iTerm2 / api / library / python / iterm2 / iterm2 / hierarchy.py View on Github external
"""Creates a new window.

    Arguments:
      profile: The name of the profile to use for the new window.
      command: A command to run in lieu of the shell in the new session.

    Throws CreateWindowException if something went wrong.
    """
    result = await iterm2.rpc.create_tab(self.connection, profile=profile, window=None, command=command)
    ctr = result.create_tab_response
    if ctr.status == iterm2.api_pb2.CreateTabResponse.Status.Value("OK"):
      session = await self.get_session_by_id(ctr.session_id)
      window, tab = self.get_tab_and_window_for_session(session)
      return window
    else:
      raise CreateWindowException(iterm2.api_pb2.CreateTabResponse.Status.Name(result.create_tab_response.status))