px普贤教程PuXian
普贤教程 › 包参考

table 包

ASCII/UTF-8 对齐表格渲染

项值
包名table
版本0.2.0
可用版本0.1.0 / 0.2.0
入口table.px
分类文本与中文处理
文件数 / 行数1 / 279

安装与引入

bash
pxpkg init          # 首次
pxpkg add table@0.2.0
pxpkg install
px
import table
所属分类教程:文本与中文处理

公开接口

函数参数
tb_renderheaders, rows, opts
其余 10 个 def(内部与辅助,可直接调用但不属稳定接口)
函数参数
tb_cell_strv
tb_widthsheaders, rows, pad
tb_pad_cells, width, align
tb_render_rowrow, w, align, pad
tb_is_widec
tb_display_widths
tb_widths_v2headers, rows, pad
tb_pad_cell_v2s, width, align
tb_render_row_v2row, w, align, pad
tb_render_v2headers, rows, opts

包内说明(源码头注释)

text
============================================================
普贤生态库:registry/table —— ASCII/UTF-8 对齐表格渲染
------------------------------------------------------------
纯函数库(无 IO、无状态),编译(px build)与解释(px run)双模式一致。
tb_render(headers, rows, opts) → str
参数:
headers : [str]          表头
rows    : [[str|数值...]] 数据行(单元格自动 str())
opts    : dict           可选:
border  : "utf8"(默认)| "ascii"
align   : "left"(默认)| "right" | "center"
padding : int(默认 1,单元格两侧空格数)
说明:列宽按 rune 宽度计(len,中文每字 1;与 textwrap 同口径的排版子集,
精确 CJK 双宽留给 0.2.0)。
============================================================
内部:单元格转字符串