Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# 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 +
the_range.length(width))
eol = (end_index not in connectors) and idx + 1 < len(
sorted_ranges)
the_range.end.x += 1
# 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 +
the_range.length(width))
# 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 +
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
"""
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))
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)
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)
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)
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(
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