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)
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)
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 paint_statusbar(rows, columns, msg, config):
func = func_for_letter(config.color_scheme["main"])
return fsarray([func(msg.ljust(columns))[:columns]])
def formatted_argspec(funcprops, arg_pos, columns, config):
# Pretty directly taken from bpython.cli
func = funcprops.func
args = funcprops.argspec.args
kwargs = funcprops.argspec.defaults
_args = funcprops.argspec.varargs
_kwargs = funcprops.argspec.varkwargs
is_bound_method = funcprops.is_bound_method
if py3:
kwonly = funcprops.argspec.kwonly
kwonly_defaults = funcprops.argspec.kwonly_defaults or dict()
arg_color = func_for_letter(config.color_scheme['name'])
func_color = func_for_letter(config.color_scheme['name'].swapcase())
punctuation_color = func_for_letter(config.color_scheme['punctuation'])
token_color = func_for_letter(config.color_scheme['token'])
bolds = {token_color: lambda x: bold(token_color(x)),
arg_color: lambda x: bold(arg_color(x))}
s = func_color(func) + arg_color(': (')
if is_bound_method and isinstance(arg_pos, int):
# TODO what values could this have?
arg_pos += 1
for i, arg in enumerate(args):
kw = None
if kwargs and i >= len(args) - len(kwargs):
kw = str(kwargs[i - (len(args) - len(kwargs))])
def formatted_argspec(funcprops, arg_pos, columns, config):
# Pretty directly taken from bpython.cli
func = funcprops.func
args = funcprops.argspec.args
kwargs = funcprops.argspec.defaults
_args = funcprops.argspec.varargs
_kwargs = funcprops.argspec.varkwargs
is_bound_method = funcprops.is_bound_method
if py3:
kwonly = funcprops.argspec.kwonly
kwonly_defaults = funcprops.argspec.kwonly_defaults or dict()
arg_color = func_for_letter(config.color_scheme["name"])
func_color = func_for_letter(config.color_scheme["name"].swapcase())
punctuation_color = func_for_letter(config.color_scheme["punctuation"])
token_color = func_for_letter(config.color_scheme["token"])
bolds = {
token_color: lambda x: bold(token_color(x)),
arg_color: lambda x: bold(arg_color(x)),
}
s = func_color(func) + arg_color(": (")
if is_bound_method and isinstance(arg_pos, int):
# TODO what values could this have?
arg_pos += 1
for i, arg in enumerate(args):
kw = None
if kwargs and i >= len(args) - len(kwargs):
def formatted_argspec(funcprops, arg_pos, columns, config):
# Pretty directly taken from bpython.cli
func = funcprops.func
args = funcprops.argspec.args
kwargs = funcprops.argspec.defaults
_args = funcprops.argspec.varargs
_kwargs = funcprops.argspec.varkwargs
is_bound_method = funcprops.is_bound_method
if py3:
kwonly = funcprops.argspec.kwonly
kwonly_defaults = funcprops.argspec.kwonly_defaults or dict()
arg_color = func_for_letter(config.color_scheme["name"])
func_color = func_for_letter(config.color_scheme["name"].swapcase())
punctuation_color = func_for_letter(config.color_scheme["punctuation"])
token_color = func_for_letter(config.color_scheme["token"])
bolds = {
token_color: lambda x: bold(token_color(x)),
arg_color: lambda x: bold(arg_color(x)),
}
s = func_color(func) + arg_color(": (")
if is_bound_method and isinstance(arg_pos, int):
# TODO what values could this have?
arg_pos += 1
for i, arg in enumerate(args):
kw = None
if kwargs and i >= len(args) - len(kwargs):
kw = str(kwargs[i - (len(args) - len(kwargs))])
color = token_color if arg_pos in (i, arg) else arg_color
from_doc = (formatted_docstring(docstring, width, config)
if docstring else [])
from_matches = (matches_lines(max(1, rows - len(from_argspec) - 2),
width, matches, match, config, format)
if matches else [])
lines = from_argspec + from_matches + from_doc
def add_border(line):
"""Add colored borders left and right to a line."""
new_line = border_color(config.left_border + ' ')
new_line += line.ljust(width)[:width]
new_line += border_color(' ' + config.right_border)
return new_line
border_color = func_for_letter(config.color_scheme['main'])
top_line = border_color(config.left_top_corner +
config.top_border * (width + 2) +
config.right_top_corner)
bottom_line = border_color(config.left_bottom_corner +
config.bottom_border * (width + 2) +
config.right_bottom_corner)
output_lines = list(itertools.chain((top_line, ), map(add_border, lines),
(bottom_line, )))
r = fsarray(output_lines[:min(rows - 1,
len(output_lines) - 1)] + output_lines[-1:])
return r
def display_line_with_prompt(self):
"""colored line with prompt"""
prompt = func_for_letter(self.config.color_scheme["prompt"])
more = func_for_letter(self.config.color_scheme["prompt_more"])
if self.incr_search_mode == "reverse_incremental_search":
return (
prompt(
"(reverse-i-search)`{}': ".format(self.incr_search_target)
)
+ self.current_line_formatted
)
elif self.incr_search_mode == "incremental_search":
return (
prompt("(i-search)`%s': ".format(self.incr_search_target))
+ self.current_line_formatted
)
return (
prompt(self.ps1) if self.done else more(self.ps2)
) + self.current_line_formatted