Исправлено: обрезка длинных имён + разделители между парами

- _pad_col теперь обрезает имена длиннее колонки (с многоточием)
- Разделительная линия (────┼────┼────) после каждой пары
- chunk_size кратен 3 (white + black + border)
- Очки выровнены по самой длинной фамилии
This commit is contained in:
Roman Vrubel 2026-06-14 21:13:48 +00:00
parent bd8cb7d9fc
commit c6d799e82f

View file

@ -59,8 +59,17 @@ def _display_width(s: str) -> int:
def _pad_col(s: str, width: int) -> str:
cur = _display_width(s)
if cur >= width:
return s
if cur > width:
# Truncate to fit: cut chars until it fits, add "…"
result = []
w = 0
for ch in s:
cw = 2 if _display_width(ch) == 2 else 1
if w + cw + 2 > width: # +2 for "…"
break
result.append(ch)
w += cw
return ''.join(result) + ''
return s + ' ' * (width - cur)
@ -89,16 +98,17 @@ def format_pairings(pairings_data: dict, tournament_name: str) -> str:
return {
'title': f'*{_md_escape(tournament_name)}*\n📋 *Тур {rnd}* — пары',
'rows': _build_table_rows(pairings, w_board, max_name_w, w_pts),
'rows': _build_table_rows(pairings, w_board, max_name_w, w_pts, border),
'table_header': table_header,
'footer': footer,
}
def _build_table_rows(pairings: list, w_board: int, w_name: int, w_pts: int) -> list:
def _build_table_rows(pairings: list, w_board: int, w_name: int, w_pts: int,
border: str) -> list:
rows = []
board = 1
for pairing in pairings:
for pi, pairing in enumerate(pairings):
if len(pairing) != 3:
continue
p1, p2, color = pairing
@ -115,6 +125,8 @@ def _build_table_rows(pairings: list, w_board: int, w_name: int, w_pts: int) ->
f'{_pad_col("", w_pts)}'
)
board += 1
if pi + 1 < len(pairings):
rows.append(border)
continue
if color == 'w':
@ -134,6 +146,10 @@ def _build_table_rows(pairings: list, w_board: int, w_name: int, w_pts: int) ->
)
board += 1
# Separator between pairs
if pi + 1 < len(pairings):
rows.append(border)
return rows
@ -145,11 +161,11 @@ def _render_chunks(fmt: dict) -> list:
chunks = []
title_line = fmt['title'] + '\n'
# Estimate overhead per chunk: title (if first) + header + footer + ```
# Estimate overhead per chunk
overhead = len(title_line) + len(header) + len(footer) + 10
available = 3800 - overhead
rows_per_chunk = max(10, available // 60) # ~60 chars per row
rows_per_chunk = (rows_per_chunk // 2) * 2 # keep pairs together
rows_per_chunk = max(15, available // 60)
rows_per_chunk = (rows_per_chunk // 3) * 3 # 3 rows/pair (white, black, border)
for i in range(0, len(rows), rows_per_chunk):
batch = rows[i:i + rows_per_chunk]