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))
:throws: :class:`~iterm2.rpc.RPCException` if something goes wrong.
.. code-block:: python
:caption: Example that prints the first ten lines of `session`.
async with iterm2.Transaction(connection) as txn:
li = await session.async_get_line_info()
lines = await session.async_get_contents(li.overflow, 10)
print(list(map(lambda line: line.string, lines)))
"""
coord_range = iterm2.util.WindowedCoordRange(
iterm2.util.CoordRange(
iterm2.util.Point(0, first_line),
iterm2.util.Point(0, first_line + number_of_lines)))
response = await iterm2.rpc.async_get_screen_contents(
self.connection,
self.session_id,
coord_range)
# pylint: disable=no-member
if (response.get_buffer_response.status ==
iterm2.api_pb2.GetBufferResponse.Status.Value("OK")):
contents = iterm2.screen.ScreenContents(
response.get_buffer_response)
result = []
for i in range(contents.number_of_lines):
result.append(contents.line(i))
return result
raise iterm2.rpc.RPCException(
iterm2.api_pb2.GetBufferResponse.Status.Name(
def cursor_coord(self) -> iterm2.util.Point:
"""Returns the location of the cursor.
:returns: A :class:`~iterm2.Point`"""
return iterm2.util.Point(self.__proto.cursor.x, self.__proto.cursor.y)
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
def windowed_coord_range(self) -> iterm2.util.WindowedCoordRange:
"""The line number of the first line in this object."""
return iterm2.util.WindowedCoordRange(
iterm2.util.CoordRange(
iterm2.util.Point(
self.__proto.windowed_coord_range.coord_range.start.x,
self.__proto.windowed_coord_range.coord_range.start.y),
iterm2.util.Point(
self.__proto.windowed_coord_range.coord_range.end.x,
self.__proto.windowed_coord_range.coord_range.end.y)),
iterm2.util.Range(
self.__proto.windowed_coord_range.columns.location,
self.__proto.windowed_coord_range.columns.length))
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
:throws: :class:`~iterm2.rpc.RPCException` if something goes wrong.
.. code-block:: python
:caption: Example that prints the first ten lines of `session`.
async with iterm2.Transaction(connection) as txn:
li = await session.async_get_line_info()
lines = await session.async_get_contents(li.overflow, 10)
print(list(map(lambda line: line.string, lines)))
"""
coord_range = iterm2.util.WindowedCoordRange(
iterm2.util.CoordRange(
iterm2.util.Point(0, first_line),
iterm2.util.Point(0, first_line + number_of_lines)))
response = await iterm2.rpc.async_get_screen_contents(
self.connection,
self.session_id,
coord_range)
# pylint: disable=no-member
if (response.get_buffer_response.status ==
iterm2.api_pb2.GetBufferResponse.Status.Value("OK")):
contents = iterm2.screen.ScreenContents(
response.get_buffer_response)
result = []
for i in range(contents.number_of_lines):
result.append(contents.line(i))
return result
raise iterm2.rpc.RPCException(
: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(
coord_range, column_range)
sub = iterm2.SubSelection(
windowed_coord_range,
iterm2.selection.SelectionMode.from_proto_value(
sub_proto.selection_mode),