Skip to content

Commit 395df1f

Browse files
JanWielemakerclaude
andcommitted
CLEANUP: html_text: measure table cells without rendering them twice
Column widths were established by formatting every cell a second time with tty(false) and counting characters, because ANSI attributes would otherwise be counted as text. write_size/4 reports display columns and ignores escape sequences, so the cells are measured as they are printed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LmQHEtHoVQ2NH2Zzusvepa
1 parent 3575a02 commit 395df1f

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

library/lynx/html_text.pl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -626,12 +626,13 @@
626626
option(margin_left(ML), BlockAttrs, 0),
627627
option(margin_right(MR), BlockAttrs, 0),
628628
MaxTableWidth is State.width - ML - MR,
629-
table_cell_state(Attrs, State, CellState),
629+
table_cell_state(Attrs, State, CellState0),
630+
CellState = CellState0.put(tty, TTY),
630631
phrase(rows(Content), Rows),
631632
columns(Rows, Columns),
632-
maplist(auto_column_width(CellState.put(tty,false)), Columns, Widths),
633+
maplist(auto_column_width(CellState), Columns, Widths),
633634
column_widths(Widths, MaxTableWidth, ColWidths),
634-
maplist(format_row(ColWidths, CellState.put(tty,TTY), ML), Rows).
635+
maplist(format_row(ColWidths, CellState, ML), Rows).
635636

636637
tty_state(TTY) :-
637638
stream_property(current_output, tty(true)),
@@ -717,9 +718,7 @@
717718
cell_colspan(Cell, 1),
718719
!,
719720
format_cell_to_string(Cell, 1_000, State, String),
720-
split_string(String, "\n", "", Lines),
721-
maplist(string_length, Lines, LineW),
722-
max_list(LineW, Width0),
721+
write_size(String, Width0, _Height, []),
723722
Width is Width0 + State.margin_right.
724723
auto_cell_width(_, _, 0).
725724

man/builtin.plx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6985,9 +6985,10 @@ appropriate for the use-case.
69856985
True when \arg{Width} and \arg{Height} describe the maximum line width
69866986
and \arg{Height} the number of lines for printing \arg{Term} using
69876987
\arg{Options} using \term{write_term}{Term, Options}. The computed width
6988-
respects Unicode \jargon{coombining} and \jargon{double width}
6989-
characters. In addition to qvalid options for write_term/2, it processes
6990-
the options:
6988+
is a count of display columns, as in line_position/2: it respects Unicode
6989+
\jargon{combining} and \jargon{double width} characters and does not
6990+
count ANSI escape sequences. In addition to qvalid options for
6991+
write_term/2, it processes the options:
69916992

69926993
\begin{description}
69936994
\termitem{max_width}{+MaxWidth}

0 commit comments

Comments
 (0)