Skip to content

Commit

Permalink
feat: 账号概览增加支持某一行的某一列设置单独的颜色
Browse files Browse the repository at this point in the history
  • Loading branch information
fzls committed Feb 3, 2025
1 parent 7cbc7b9 commit 2687021
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 6 additions & 3 deletions main_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,9 @@ def show_following_regular_activity_expected_info():
)


account_status_line_color = color("fg_bold_green")


@try_except()
# show_accounts_status 展示个人概览
def sas(cfg: Config, ctx: str, user_buy_info: BuyInfo):
Expand Down Expand Up @@ -916,7 +919,7 @@ def sas(cfg: Config, ctx: str, user_buy_info: BuyInfo):

logger.info(tableify(heads, colSizes))
for row in rows:
logger.info(color("fg_bold_green") + tableify(row, colSizes, need_truncate=True))
logger.info(account_status_line_color + tableify(row, colSizes, need_truncate=True))

# # 展示本周闪光杯爆装
# DjcHelper(cfg.account_configs[0], cfg.common).dnf_shanguang_show_equipments()
Expand Down Expand Up @@ -954,9 +957,9 @@ def get_account_status(idx: int, account_config: AccountConfig, common_config: C

if token_expired:
if account_config.dnf_helper_info.token != "":
levelInfo = "token已过期"
levelInfo = ("token已过期", color("bold_cyan"), account_status_line_color)
else:
levelInfo = "token未配置"
levelInfo = ("token未配置", color("bold_yellow"), account_status_line_color)

user_info_db = (
DnfHelperChronicleUserActivityTopInfoDB().with_context(djcHelper.get_dnf_helper_chronicle_db_key()).load()
Expand Down
13 changes: 11 additions & 2 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,14 @@ def truncate(msg, expect_width) -> str:
return "".join(truncated)


def padLeftRight(msg, target_size, pad_char=" ", mode="middle", need_truncate=False):
msg = str(msg)
def padLeftRight(target_msg, target_size, pad_char=" ", mode="middle", need_truncate=False):
msg = str(target_msg)
# re: 如果本列想要指定单独的颜色,可以在传入消息的时候不直接传字符串,而是传入一个三元素的列表或tuple,分别是消息内容、消息颜色,本行的颜色,这样可以实现本内容使用单独颜色,并在后面恢复原来的颜色
msg_color = None
line_color = None
if type(target_msg) is list or type(target_msg) is tuple:
msg, msg_color, line_color = target_msg

if need_truncate:
msg = truncate(msg, target_size)
msg_len = printed_width(msg)
Expand All @@ -587,6 +593,9 @@ def padLeftRight(msg, target_size, pad_char=" ", mode="middle", need_truncate=Fa
pad_left_len = total // 2
pad_right_len = total - pad_left_len

if msg_color is not None and line_color is not None:
msg = msg_color + msg + asciiReset + line_color

if mode == "middle":
return pad_char * pad_left_len + msg + pad_char * pad_right_len
elif mode == "left":
Expand Down

0 comments on commit 2687021

Please sign in to comment.