ANSI转义代码格式化程序
afmt的Python项目详细描述
afmt
此模块提供了在CLI环境中格式化文本的简单方法。
它设计用于f-strings中,但是使用
format
方法也受支持。在
该模块负责从管道输出中剥离ANSI转义序列 只有在输出设备支持的情况下才放入序列。在
设置
$ pip install afmt
用法和示例
fromafmtimportFormatterf=Formatter()# You can use inline stylingprint(f'{f:bold}bold text{f:e}')# You can define specs outside of an f-stringwarning='bold bg(yellow) fg(black) italic'error='bold bg(red) fg(white) underline'print(f'{f:{warning}}Warning: you shouldn\'t do it{f:e}')print(f'{f:{error}}Error: you can\'t do it{f:e}')# You can define custom styles in the formatter instancef.add_style('important','b fg(red)')print(f'{f:important}important text{f:e}')# Or you can pass a dict of styles in the initializer f=Formatter(styles={'important':'bold fg(255,0,0)','unimporant':'faint'})print(f'{f:important}important text{f:e}')print(f'{f:unimportant}not so important text{f:e}')# Move cursor to 4th row and 6th column and print text in reverse video mode print(f'{f:reverse goto(4,6)}hello, world{f:e}')# Make text bold and underlined and unset bold in the middleprint(f'{f:bold italic}hello,{f:!bold} world{f:e}')
发展现状
本模块处于开发的早期阶段。 更多的功能有望很快推出。在
- 项目
标签: