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}')

asciicast

发展现状

本模块处于开发的早期阶段。 更多的功能有望很快推出。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为什么列表<String>不能作为列表<Object>接受?   java从Android应用程序启动两项活动   java传递给ThreadPoolExecutor/ScheduledThreadPoolExecutor的建议corePoolSize是多少?   java ANDROID禁用手机提醒   Spring引导中的java TaskRejectedException   JavaJSF2。h:选择布尔复选框。意外行为   java如何从InputStream创建RandomAccessFile?   ReEX在“中间”中用“java”替换单词的撇号   java短、整数、长性能   java是SOAP web服务优于REST的实时实际情况吗?   java多模块maven项目:未能对项目执行目标,无法解析项目的依赖项,无法找到工件   当使用GroovyEventPlugin时,JavaGroovy不会将闭包转换为BiPredicate   java在应用程序启动时运行JFXDialog   在Java中,如何将用户输入的整数发送到链表?   哪一个Eclipse下载用于开发Java ME   PostgreSQL/Clojure的java驱动程序问题   java如何创建SSL连接客户机类来连接到现有服务器?   java如何使用JUnit5测试抽象接口?   升级JIRA时我需要下载哪个jar?   我们可以运行反编译java(jar到java)吗