mirror of
https://github.com/Nanaloveyuki/py-logiliteal.git
synced 2025-09-03 18:16:22 +00:00
✨ 增加ANSI粗体等样式
This commit is contained in:
@ -20,6 +20,7 @@ __all__ = [
|
||||
"fmt_placeholder",
|
||||
"fmt_message",
|
||||
"fmt_level_name",
|
||||
"set_style",
|
||||
"set_color",
|
||||
"set_bg_color",
|
||||
"Logger" # 日志记录器非实例化
|
||||
|
@ -8,7 +8,7 @@ Utility functions
|
||||
from .configs import get_config, set_config, reset_config
|
||||
from .time import get_asctime, get_date, get_time, get_weekday
|
||||
from .fmt import fmt_console, fmt_placeholder, fmt_message, fmt_level_name
|
||||
from .styles import set_color, set_bg_color
|
||||
from .styles import set_color, set_bg_color, set_style
|
||||
|
||||
__all__ = [
|
||||
"get_config",
|
||||
@ -24,4 +24,5 @@ __all__ = [
|
||||
"fmt_level_name",
|
||||
"set_color",
|
||||
"set_bg_color",
|
||||
]
|
||||
"set_style"
|
||||
]
|
||||
|
@ -47,3 +47,22 @@ def set_bg_color(text: str, color: str) -> str:
|
||||
# 将前景色ANSI代码转换为背景色代码 (38→48)
|
||||
ansi = ansi.replace("38;", "48;")
|
||||
return f"{ansi}{text}\033[0m"
|
||||
|
||||
def set_style(text: str, bold: bool = False, underline: bool = False, reverse: bool = False) -> str:
|
||||
"""
|
||||
设置文本样式
|
||||
Set text style
|
||||
:param text: 文本内容 Text content
|
||||
:param bold: 是否加粗 Is bold
|
||||
:param underline: 是否下划线 Is underline
|
||||
:param reverse: 是否反相 Is reverse
|
||||
:return: 格式化后的文本 Formatted text
|
||||
"""
|
||||
ansi = ""
|
||||
if bold:
|
||||
ansi += "\033[1m"
|
||||
if underline:
|
||||
ansi += "\033[4m"
|
||||
if reverse:
|
||||
ansi += "\033[7m"
|
||||
return f"{ansi}{text}\033[0m"
|
||||
|
Reference in New Issue
Block a user