From 9955ec3e8a1c3ff094fc21f3f4b952a8c5bc9c71 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sun, 20 Aug 2023 23:11:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=AE=9E=E9=99=85=E4=B8=8A=E4=BC=9A=E5=AF=BC=E8=87=B4=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E9=97=AE=E9=A2=98=E7=9A=84=E9=83=A8=E5=88=86=20?= =?UTF-8?q?=E6=94=B9=E8=BF=9B=E4=BA=86=E4=B8=80=E7=82=B9=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib_not_dr/types/options.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib_not_dr/types/options.py b/lib_not_dr/types/options.py index 6d4c69e..82110f3 100644 --- a/lib_not_dr/types/options.py +++ b/lib_not_dr/types/options.py @@ -215,7 +215,10 @@ class Options: value_len = min(value_len, console_width // 3) value_type_len = min(value_type_len, console_width // 3) # 先指定每一个列的输出最窄宽度, 然后去尝试增加宽度 - while option_len + value_len + value_type_len + 16 < console_width: + while option_len + value_len + value_type_len + 16 < console_width\ + and (option_len < value[1] + or value_len < value[2] + or value_type_len < value[3]): # 每一个部分的逻辑都是 # 如果现在的输出长度小于原始长度 # 并且长度 + 1 之后的总长度依然在允许范围内 @@ -226,14 +229,15 @@ class Options: value_len += 1 if value_type_len < value[3] and option_len + value_len + value_type_len + 1 + 15 < console_width: value_type_len += 1 - - for k in range(len(value[0])): - if len(str(value[0][k][0])) > option_len: - value[0][k][0] = str(value[0][k][0])[:value_len - 3] + '..' - if len(str(value[0][k][1])) > value_len: - value[0][k][1] = str(value[0][k][1])[:value_len - 3] + '..' - if len(str(value[0][k][2])) > value_type_len: - value[0][k][2] = str(value[0][k][2])[:value_len - 3] + '..' + # 实际上 对于列表(可变对象) for 出来的这个值是一个引用 + # 所以可以直接修改 string + for string in value[0]: + if len(str(string[0])) > option_len: + string[0] = f'{str(string[0])[:value_len - 3]}...' + if len(str(string[1])) > value_len: + string[1] = f'{str(string[1])[:value_len - 3]}...' + if len(str(string[2])) > value_type_len: + string[2] = f'{str(string[2])[:value_len - 3]}...' cache.write( f"| Option{' ' * (option_len - 3)}| Value{' ' * (value_len - 2)}| Value Type{' ' * (value_type_len - 7)}|\n")