Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def matches_lines(rows, columns, matches, current, config, match_format):
highlight_color = func_for_letter(config.color_scheme["operator"].lower())
if not matches:
return []
color = func_for_letter(config.color_scheme["main"])
max_match_width = max(len(m) for m in matches)
words_wide = max(1, (columns - 1) // (max_match_width + 1))
matches = [match_format(m) for m in matches]
if current:
current = match_format(current)
matches = paginate(rows, matches, current, words_wide)
result = [
fmtstr(" ").join(
color(m.ljust(max_match_width))
if m != current
else highlight_color(m.ljust(max_match_width))
for m in matches[i : i + words_wide]
)
for i in range(0, len(matches), words_wide)
]
logger.debug("match: %r" % current)
logger.debug("matches_lines: %r" % result)
return result
def matches_lines(rows, columns, matches, current, config, format):
highlight_color = func_for_letter(config.color_scheme['operator'].lower())
if not matches:
return []
color = func_for_letter(config.color_scheme['main'])
max_match_width = max(len(m) for m in matches)
words_wide = max(1, (columns - 1) // (max_match_width + 1))
matches = [format(m) for m in matches]
if current:
current = format(current)
matches = paginate(rows, matches, current, words_wide)
matches_lines = [fmtstr(' ').join(color(m.ljust(max_match_width))
if m != current
else highlight_color(
m.ljust(max_match_width))
for m in matches[i:i + words_wide])
for i in range(0, len(matches), words_wide)]
logger.debug('match: %r' % current)
logger.debug('matches_lines: %r' % matches_lines)
return matches_lines
def formatted_docstring(docstring, columns, config):
if isinstance(docstring, bytes):
docstring = docstring.decode('utf8')
elif isinstance(docstring, str if py3 else unicode):
pass
else:
# TODO: fail properly here and catch possible exceptions in callers.
return []
color = func_for_letter(config.color_scheme['comment'])
return sum(([color(x) for x in (display_linize(line, columns) if line else
fmtstr(''))]
for line in docstring.split('\n')), [])
def formatted_docstring(docstring, columns, config):
if isinstance(docstring, bytes):
docstring = docstring.decode("utf8")
elif isinstance(docstring, str if py3 else unicode):
pass
else:
# TODO: fail properly here and catch possible exceptions in callers.
return []
color = func_for_letter(config.color_scheme["comment"])
return sum(
(
[
color(x)
for x in (display_linize(line, columns) if line else fmtstr(""))
]
for line in docstring.split("\n")
),
[],
)
def fullscreen_winch_with_input():
print('this should be just off-screen')
w = FullscreenWindow(sys.stdout)
def sigwinch_handler(signum, frame):
print('sigwinch! Changed from %r to %r' % ((rows, columns), (w.height, w.width)))
signal.signal(signal.SIGWINCH, sigwinch_handler)
with w:
with Cbreak(sys.stdin):
for e in input.Input():
rows, columns = w.height, w.width
a = [fmtstr((('.%sx%s.%r.' % (rows, columns, e)) * rows)[:columns]) for row in range(rows)]
w.render_to_terminal(a)
self.saved_indent = self.predicted_indent(line)
if self.config.syntax:
display_line = bpythonparse(
format(self.tokenize(line), self.formatter)
)
# self.tokenize requires that the line not be in self.buffer yet
logger.debug(
"display line being pushed to buffer: %r -> %r",
line,
display_line,
)
self.display_buffer.append(display_line)
else:
self.display_buffer.append(fmtstr(line))
if insert_into_history:
self.insert_into_history(line)
self.buffer.append(line)
code_to_run = "\n".join(self.buffer)
logger.debug("running %r in interpreter", self.buffer)
c, code_will_parse = code_finished_will_parse(
"\n".join(self.buffer), self.interp.compile
)
self.saved_predicted_parse_error = not code_will_parse
if c:
logger.debug("finished - buffer cleared")
self.cursor_offset = 0
self.display_lines.extend(self.display_buffer_lines)
columns = arr.width
last_key_box = paint.paint_last_events(
rows,
columns,
[events.pp_event(x) for x in self.last_events if x],
self.config,
)
arr[
arr.height - last_key_box.height : arr.height,
arr.width - last_key_box.width : arr.width,
] = last_key_box
if self.config.color_scheme["background"] not in ("d", "D"):
for r in range(arr.height):
bg = color_for_letter(self.config.color_scheme["background"])
arr[r] = fmtstr(arr[r], bg=bg)
logger.debug("returning arr of size %r", arr.shape)
logger.debug("cursor pos: %r", (cursor_row, cursor_column))
return arr, (cursor_row, cursor_column)