Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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))
async def async_set_title(self, title: str):
"""Changes the tab's title.
This is equivalent to editing the tab's title with the menu item Edit
Tab Title. The title is an interpolated string.
:param title: The new title. Set it to an empty string to use the
default value (the current session's title).
:throws: :class:`~iterm2.rpc.RPCException` if something goes wrong.
"""
invocation = iterm2.util.invocation_string(
"iterm2.set_title",
{"title": title})
await iterm2.rpc.async_invoke_method(
self.connection, self.tab_id, invocation, -1)
async def async_set_name(self, name: str):
"""Changes the session's name.
This is equivalent to editing the session's name manually in the Edit
Session window.
:param name: The new name to use.
:throws: :class:`~iterm2.rpc.RPCException` if something goes wrong.
"""
invocation = iterm2.util.invocation_string(
"iterm2.set_name",
{"name": name})
await iterm2.rpc.async_invoke_method(
self.connection, self.session_id, invocation, -1)
async def async_stop_coprocess(self) -> bool:
"""
Stops the currently running coprocess, if any.
:returns: True if a coprocess was stopped or False if non was running.
"""
iterm2.capabilities.check_supports_coprocesses(self.connection)
invocation = iterm2.util.invocation_string(
"iterm2.stop_coprocess",
{})
return bool(
await iterm2.rpc.async_invoke_method(
self.connection, self.session_id, invocation, -1))
async def async_set_title(self, title: str):
"""Changes the window's title.
This is equivalent to editing the window's title with the menu item
Edit Window Title. The title is an interpolated string. Note that when
using tmux integration, tab titles correspond to tmux window titles.
iTerm2's window titles have no equivalent in tmux.
:param title: The new title. Set it to an empty string to use the
default value (the current tab's title).
:throws: :class:`~iterm2.rpc.RPCException` if something goes wrong.
"""
invocation = iterm2.util.invocation_string(
"iterm2.set_title",
{"title": title})
await iterm2.rpc.async_invoke_method(
self.connection, self.window_id, invocation, -1)
"""
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)
async def async_run_tmux_command(
self, command: str, timeout: float = -1) -> str:
"""Invoke a tmux command and return its result. Raises an exception if
this session is not a tmux integration session.
:param command: The tmux command to run.
:param timeout: The amount of time to wait for a response, or -1 to use
the default.
:returns: The output from tmux.
:throws: :class:`~iterm2.rpc.RPCException` if something goes wrong.
"""
invocation = iterm2.util.invocation_string(
"iterm2.run_tmux_command",
{"command": command})
return await iterm2.rpc.async_invoke_method(
self.connection, self.session_id, invocation, timeout)
async def async_get_coprocess(self) -> typing.Optional[str]:
"""
Returns the command line of the currently running coprocess, if any.
:returns: Whether there is a coprocess currently running.
"""
iterm2.capabilities.check_supports_coprocesses(self.connection)
invocation = iterm2.util.invocation_string(
"iterm2.get_coprocess",
{})
return await iterm2.rpc.async_invoke_method(
self.connection, self.session_id, invocation, -1)