pretty.py 文件源码

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

项目:backend.ai-client-py 作者: lablup 项目源码 文件源码
def print_pretty(msg, *, status=PrintStatus.NONE, file=None):
    if file is None:
        file = sys.stderr
    if status == PrintStatus.NONE:
        indicator = '\x1b[96m\u2219' if file.isatty() else '\u2219'
    elif status == PrintStatus.WAITING:
        assert '\n' not in msg, 'Waiting message must be a single line.'
        indicator = '\x1b[93m\u22EF' if file.isatty() else '\u22EF'
    elif status == PrintStatus.DONE:
        indicator = '\x1b[92m\u2714' if file.isatty() else '\u2714'
    elif status == PrintStatus.FAILED:
        indicator = '\x1b[91m\u2718' if file.isatty() else '\u2718'
    else:
        raise ValueError
    if file.isatty():
        print('\x1b[2K', end='', file=file)
    text = textwrap.indent(msg, '  ')
    text = indicator + text[1:]
    if file.isatty():
        text += '\x1b[0m'
    print('{0}\r'.format(text), end='', file=file)
    file.flush()
    if status != PrintStatus.WAITING:
        print('', file=file)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号