MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / print_aligned_string_list

Function print_aligned_string_list

SwissArmyTransformer/sat/helpers.py:56–82  ·  view source on GitHub ↗
(str_list, column_spacing=2)

Source from the content-addressed store, hash-verified

54 print()
55
56def print_aligned_string_list(str_list, column_spacing=2):
57 # 获取字符串列表中的最长字符串长度
58 max_length = max(len(s) for s in str_list)
59
60 # 计算终端宽度以便我们知道多少列可以显示
61 try:
62 import shutil
63 terminal_width = shutil.get_terminal_size().columns
64 except Exception:
65 terminal_width = 80
66 print("-" * (terminal_width-5))
67
68 # 计算每行可容纳的列数
69 columns_per_row = (terminal_width + column_spacing) // (max_length + column_spacing)
70
71 # 计算需要多少行来显示所有字符串
72 rows_required = (len(str_list) + columns_per_row - 1) // columns_per_row
73
74 # 按行打印字符串,确保对齐
75 for row in range(rows_required):
76 line = ""
77 for col in range(columns_per_row):
78 index = row + col * rows_required
79 if index < len(str_list):
80 line += str_list[index].ljust(max_length + column_spacing)
81 print(line.strip())
82 print("-" * (terminal_width-5))
83
84def list_avail_models():
85 from .model import official

Callers 2

list_avail_modelsFunction · 0.85
list_avail_pretrainedFunction · 0.85

Calls 1

printFunction · 0.50

Tested by

no test coverage detected