终端引导-python控制台输出中用于unicode文本格式化的python css文件
termstrap的Python项目详细描述
术语表
用于在python控制台输出中设置unicode文本格式的css文件(类似引导程序)
用法
使用pip安装它:pip install termstrap
在代码中导入:import css
或from css import Bootstrap, printc
。
创建一个对象:text = Bootstrap()
用作:text.colorize(<string>, <color>)
或text.stylize(<string>, < b / i / u >)
或text.start_block(<color>, <formatter>)
可访问的功能/方法
简单的:
colorize()
:接受文本、字体颜色(可选)和bgcolor(可选)。stylize()
:接受文本、样式名(粗体、斜体、下划线和闪烁)。只传递缩写(例如,“B”表示粗体)。可以同时传递多个样式。
info:闪烁是实验性的,如果它不起作用,它不会破坏任何东西!因此没有速记!
LIL高级:
get_color()
:获取字体颜色的名称并返回其颜色代码get_bgcolor()
:获取背景颜色的名称并返回其颜色代码new_color()
:获取颜色名称和颜色代码。可用于添加新的自定义字体颜色项new_bgcolor()
:获取颜色名称和颜色代码。可用于添加新的自定义背景色项
warning:如果您知道自己在做什么,请仅使用new_color()
或new_bgcolor()
!
可访问变量
类实例可以访问所有颜色。覆盖它们将/可能会破坏功能。
- 颜色变量:引导名称-主要、危险、警告等。
- 背景颜色变量:bg_primary、bg_danger、bg_warning等。
- 样式变量:粗体、斜体、下划线、选定、闪烁
更多实用功能
这些不是引导类的成员。不需要创建实例。只需导入和使用。
- printc:类似于标准print()。除外:没有flush和file参数。有颜色参数,取颜色的名称。样式参数,获取所有样式的列表或元组。bgcolor param,取bgcolor的名称!
- 隐藏光标:在控制台中隐藏光标
- show_cursor:恢复光标可见性。
示例
fromcssimportBootstrap,printc# make sure you have downloaded the css.py file in the same folder/directorytext=Bootstrap()# Using colorize to colorprint(text.colorize("THIS IS RED","red"))# You can also use Bootstrap classes, eg. dangerprint(text.colorize("THIS IS blue","primary"))# blue will also work.# Using stylize to format text- bold(b), italics(i), underline(u), selected(s), blinkprint(text.stylize("A BOLD move","bold"))# b also works in place of boldprint(text.stylize("Slightly slanted","i"))print(text.stylize("More the merrier",'b','u','s','i'))# You can also combine colors and formats:print(text.stylize(text.colorize("This is bold in red"),'b'))# Change color for multiple lines if needed!text.start_block('red',bold=True)# Any text in this clock will be printed in RED, and BOLD by defaulttext.end_block()# Using the printcprintc("RED text in *BOLD*",color='red',style=('b'))printc("[1,2,3,4]",color='warning',style=('b','u'),sep='***')# yellow text, styled bold and underlined, seperated by - ***printc("a","b","cdf",color="primary",end='')# print multiple strings and specify end param as none, ie. no newline at end!
important:信息与引导信息的颜色不同,它是紫色的!
已知问题
- 风格眨眼在大多数情况下不起作用。
- Windows CMD仅支持Windows 10(v1511以后)中的颜色!
灵感
Thisstackoverflow是这个项目的灵感来源。