util.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:cuvner 作者: meejah 项目源码 文件源码
def print_banner(fname, percent, fill=None, pager=None):
    """
    Prints out a coloured banner showing coverage percent

    :param fill: the width of the banner; if None, uses 80 or the
        terminal width, whichever is less.
    """

    echo = pager.echo if pager else click.echo
    if fill is None:
        fill = min(click.get_terminal_size()[0], 80)

    echo(colors.color('-' * fill, bg=226, fg=236), color=True)
    maxsize = fill - len('coverage: ') - 3
    truncfname = fname[-maxsize:]
    if len(truncfname) != len(fname):
        truncfname = u'...{}'.format(truncfname)
    echo(colors.color(u'coverage: {}'.format(truncfname).ljust(fill), bg=226, fg=236), color=True)
    grsize = int(fill * percent)
    if grsize >= 5:
        prcnt_formatted = u'%3d%%' % int(percent * 100.0)
        gr = colors.color(prcnt_formatted + (u' ' * (grsize - 4)), fg=255, bg=22)
    else:
        gr = colors.color(u' ' * grsize, bg=22)
    red = colors.color(u' ' * int(math.ceil(fill * (1.0 - percent))), bg=52)
    echo(gr + red, color=True)
    echo(colors.color(u'-' * fill, bg=226, fg=236), color=True)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号