From e397bdf11db7f6a9557be17a000473fd6561b078 Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Mon, 24 Jun 2024 13:38:59 -0400 Subject: [PATCH] Let `WIDTH_PROC` be specified as proc argument to `write_*_table` --- core/text/table/table.odin | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/core/text/table/table.odin b/core/text/table/table.odin index 4233902c8..881af1fb5 100644 --- a/core/text/table/table.odin +++ b/core/text/table/table.odin @@ -371,11 +371,9 @@ write_html_table :: proc(w: io.Writer, tbl: ^Table) { io.write_string(w, "\n") } -write_plain_table :: proc(w: io.Writer, tbl: ^Table) { - WIDTH_PROC :: unicode_width_proc - +write_plain_table :: proc(w: io.Writer, tbl: ^Table, width_proc: Width_Proc = unicode_width_proc) { if tbl.dirty { - build(tbl, WIDTH_PROC) + build(tbl, width_proc) } write_caption_separator :: proc(w: io.Writer, tbl: ^Table) { @@ -400,7 +398,7 @@ write_plain_table :: proc(w: io.Writer, tbl: ^Table) { write_caption_separator(w, tbl) io.write_byte(w, '|') write_text_align(w, tbl.caption, .Center, - tbl.lpad, tbl.rpad, tbl.tblw + tbl.nr_cols - 1 - WIDTH_PROC(tbl.caption) - tbl.lpad - tbl.rpad) + tbl.lpad, tbl.rpad, tbl.tblw + tbl.nr_cols - 1 - width_proc(tbl.caption) - tbl.lpad - tbl.rpad) io.write_byte(w, '|') io.write_byte(w, '\n') } @@ -423,12 +421,10 @@ write_plain_table :: proc(w: io.Writer, tbl: ^Table) { } // Renders table according to GitHub Flavored Markdown (GFM) specification -write_markdown_table :: proc(w: io.Writer, tbl: ^Table) { +write_markdown_table :: proc(w: io.Writer, tbl: ^Table, width_proc: Width_Proc = unicode_width_proc) { // NOTE(oskar): Captions or colspans are not supported by GFM as far as I can tell. - WIDTH_PROC :: unicode_width_proc - if tbl.dirty { - build(tbl, WIDTH_PROC) + build(tbl, width_proc) } write_row :: proc(w: io.Writer, tbl: ^Table, row: int, alignment: Cell_Alignment = .Left) {