def show_diffs(formatter, # type: CodeFormatter
filenames, # type: List[str]
style, # type: Style
ansi, # type: bool
ansihtml, # type: bool
html, # type: bool
nopager, # type: bool
numlines, # type: int
wrapcolumn=0, # type: int
linenumbers=False, # type: bool
enc='utf-8' # type: str
):
# type: (...) -> None
"""Show the differences between the current and reformatted sources.
"""
if not ansi and not html:
if supports_color():
ansi = True
else:
html = True
pairs = []
for filename in filenames:
sourcedata = get_cached_file(filename)
content = formatter.formatcode(style, sourcedata, filename=filename)
pairs.append((sourcedata, content))
unifilenames = '\n'.join([unifilename(f) for f in filenames]) + '\n'
htmldiffer = HtmlMultiDiff(tabsize=4, wrapcolumn=wrapcolumn)
table = htmldiffer.table_from_pairs(pairs,
enc,
fromdesc='',
todesc='',
context=True,
numlines=numlines)
headerhtml = '<pre>\n' + unifilenames + '</pre>'
customhtml = make_custom_html(htmldiffer, headerhtml, [table], enc=enc)
htmldata = unescape_ill_surrencode(customhtml, enc=enc)
htmldata = translate_non_sgml_chars(htmldata, enc=enc)
headerdata = yellow(unifilenames)
if html or ansihtml:
if ansihtml:
htmldata = html2ansihtml(
surrdecode(htmldata, enc=enc),
header=headerdata,
enc=enc,
linenumbers=linenumbers)
fd, tempname = tempfile.mkstemp(suffix='.html', prefix='whatstyle_')
os.write(fd, htmldata)
os.close(fd)
url = urljoin('file:', pathname2url(tempname))
webbrowser.open(url)
elif ansi:
with pagercontext(not nopager) as fp:
outline(headerdata, fp=fp)
htmldiff2ansi(customhtml, enc, linenumbers=linenumbers, fp=fp)
评论列表
文章目录