Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
XX..
"""
sx, sy = self.constrain_coords(*start)
ex, ey = self.constrain_coords(*end)
# within a single row
if sy == ey:
for x in xrange(sx, ex + 1):
self.term[sy][x] = self.empty_char()
return
# spans multiple rows
y = sy
while y <= ey:
if y == sy:
for x in xrange(sx, self.width):
self.term[y][x] = self.empty_char()
elif y == ey:
for x in xrange(ex + 1):
self.term[y][x] = self.empty_char()
else:
self.blank_line(y)
y += 1
Erase a region of the terminal. The 'start' tuple (x, y) defines the
starting position of the erase, while end (x, y) the last position.
For example if the terminal size is 4x3, start=(1, 1) and end=(1, 2)
would erase the following region:
....
.XXX
XX..
"""
sx, sy = self.constrain_coords(*start)
ex, ey = self.constrain_coords(*end)
# within a single row
if sy == ey:
for x in xrange(sx, ex + 1):
self.term[sy][x] = self.empty_char()
return
# spans multiple rows
y = sy
while y <= ey:
if y == sy:
for x in xrange(sx, self.width):
self.term[y][x] = self.empty_char()
elif y == ey:
for x in xrange(ex + 1):
self.term[y][x] = self.empty_char()
else:
self.blank_line(y)
y += 1
def _setup_colour_pairs(self):
"""
Initialize all 63 color pairs based on the term:
bg * 8 + 7 - fg
So to get a color, we just need to use that term and get the right color
pair number.
"""
if not self.has_color:
return
for fg in xrange(8):
for bg in xrange(8):
# leave out white on black
if fg == curses.COLOR_WHITE and \
bg == curses.COLOR_BLACK:
continue
curses.init_pair(bg * 8 + 7 - fg, fg, bg)
focus = self._validate_contents_modified(indices, new_items)
if focus is not None:
return focus
focus = self._focus
if step == 1:
if start + num_new_items <= focus < stop:
focus = stop
# adjust for added/removed items
if stop <= focus:
focus += num_new_items - (stop - start)
else:
if not num_new_items:
# extended slice being removed
if focus in xrange(start, stop, step):
focus += 1
# adjust for removed items
focus -= len(list(xrange(start, min(focus, stop), step)))
return min(focus, len(self) + num_new_items - num_removed -1)
ex, ey = self.constrain_coords(*end)
# within a single row
if sy == ey:
for x in xrange(sx, ex + 1):
self.term[sy][x] = self.empty_char()
return
# spans multiple rows
y = sy
while y <= ey:
if y == sy:
for x in xrange(sx, self.width):
self.term[y][x] = self.empty_char()
elif y == ey:
for x in xrange(ex + 1):
self.term[y][x] = self.empty_char()
else:
self.blank_line(y)
y += 1
def clear(self, cursor=None):
"""
Clears the whole terminal screen and resets the cursor position
to (0, 0) or to the coordinates given by 'cursor'.
"""
self.term = [self.empty_line() for x in xrange(self.height)]
if cursor is None:
self.set_term_cursor(0, 0)
else:
self.set_term_cursor(*cursor)
def reverse_video(self, undo=False):
"""
Reverse video/scanmode (DECSCNM) by swapping fg and bg colors.
"""
for y in xrange(self.height):
for x in xrange(self.width):
char = self.term[y][x]
attrs = self.reverse_attrspec(char[0], undo=undo)
self.term[y][x] = (attrs,) + char[1:]
def __iter__(self):
"""
Return an iterable of positions for this container from first
to last.
"""
return iter(xrange(len(self.contents)))