core/text/table
text_table
Types
6Aligned_Value
Aligned_Value :: struct {
alignment: Cell_Alignment,
value: any,
}SourceCell
Cell :: struct {
text: string,
width: int,
alignment: Cell_Alignment,
}SourceCell_Alignment
Cell_Alignment :: enum int {
Left = 0,
Center = 1,
Right = 2,
}SourceDecorations
Decorations :: struct {
// These are strings, because of multi-codepoint Unicode graphemes.
// Connecting decorations:
sw: string,
s: string,
se: string,
// Straight lines:
vert: string,
horz: string,
}SourceTable
Table :: struct {
lpad: int,
rpad: int,
cells: [dynamic]Cell,
caption: string,
nr_rows: int,
nr_cols: int,
has_header_row: bool,
table_allocator: runtime.Allocator,
format_allocator: runtime.Allocator,
// The following are computed on build()
colw: [dynamic]int,
tblw: int,
}SourceWidth_Proc
Width_Proc :: proc(str: string) -> (int)SourceDetermines the width of a string used in the table for alignment purposes.
Procedures
34aligned_header_of_values
aligned_header_of_values :: proc(tbl: ^Table, alignment: Cell_Alignment, values, loc = #caller_location)Sourcealigned_row_of_values
aligned_row_of_values :: proc(tbl: ^Table, alignment: Cell_Alignment, values, loc = #caller_location)Sourceascii_width_proc
ascii_width_proc :: proc(str: string) -> (int)Sourcebuild
build :: proc(tbl: ^Table, width_proc: Width_Proc)Sourcecaption
caption :: proc(tbl: ^Table, value: string)Sourcedestroy
destroy :: proc(tbl: ^Table)Sourcefirst_row
first_row :: proc(tbl: ^Table) -> (int)Sourceformat
format :: proc(tbl: ^Table, _fmt: string, args) -> (string)Sourceget_cell
get_cell :: proc(tbl: ^Table, row: int, col: int, loc = #caller_location) -> (^Cell)Sourceheader
header :: proc(tbl: ^Table, values, loc = #caller_location)Sourceheader_of_aligned_values
header_of_aligned_values :: proc(tbl: ^Table, aligned_values: []Aligned_Value, loc = #caller_location)Sourceheader_of_values
header_of_values :: proc(tbl: ^Table, values, loc = #caller_location)Sourceheader_row
header_row :: proc(tbl: ^Table) -> (int)Sourceinit_with_allocator
init_with_allocator :: proc(tbl: ^Table, format_allocator = context.temp_allocator, table_allocator: mem.Allocator = context.allocator) -> (^Table)Sourceinit_with_mem_arena
init_with_mem_arena :: proc(tbl: ^Table, format_arena: ^mem.Arena, table_allocator: mem.Allocator = context.allocator) -> (^Table)Sourceinit_with_virtual_arena
init_with_virtual_arena :: proc(tbl: ^Table, format_arena: ^virtual.Arena, table_allocator: mem.Allocator = context.allocator) -> (^Table)Sourcelast_row
last_row :: proc(tbl: ^Table) -> (int)SourceTODO: This should work correctly when #3262 is fixed. row :: proc {
row_of_values,
aligned_row_of_values,
row_of_aligned_values,
}padding
padding :: proc(tbl: ^Table, lpad: int, rpad: int)Sourcerow
row :: proc(tbl: ^Table, values, loc = #caller_location)Sourcerow_of_aligned_values
row_of_aligned_values :: proc(tbl: ^Table, aligned_values: []Aligned_Value, loc = #caller_location)Sourcerow_of_values
row_of_values :: proc(tbl: ^Table, values, loc = #caller_location)Sourceset_cell_alignment
set_cell_alignment :: proc(tbl: ^Table, row: int, col: int, alignment: Cell_Alignment, loc = #caller_location)Sourceset_cell_value
set_cell_value :: proc(tbl: ^Table, row: int, col: int, value: any, loc = #caller_location)Sourceset_cell_value_and_alignment
set_cell_value_and_alignment :: proc(
tbl: ^Table,
row: int,
col: int,
value: any,
alignment: Cell_Alignment,
loc: _ = #caller_location,
)Sourcestdio_writer
stdio_writer :: proc() -> (io.Writer)Sourcestrings_builder_writer
strings_builder_writer :: proc(b: ^strings.Builder) -> (io.Writer)Sourceunicode_width_proc
unicode_width_proc :: proc(str: string) -> (width: int)Sourcewrite_byte_repeat
write_byte_repeat :: proc(w: io.Writer, n: int, b: u8)Sourcewrite_decorated_table
write_decorated_table :: proc(w: io.Writer, tbl: ^Table, decorations: Decorations, width_proc: Width_Proc)Sourcewrite_html_table
write_html_table :: proc(w: io.Writer, tbl: ^Table)Sourcewrite_markdown_table
write_markdown_table :: proc(w: io.Writer, tbl: ^Table, width_proc: Width_Proc)SourceRenders table according to GitHub Flavored Markdown (GFM) specification
write_plain_table
write_plain_table :: proc(w: io.Writer, tbl: ^Table, width_proc: Width_Proc)Sourcewrite_table_cell
write_table_cell :: proc(w: io.Writer, tbl: ^Table, row: int, col: int)Sourcewrite_text_align
write_text_align :: proc(
w: io.Writer,
text: string,
alignment: Cell_Alignment,
lpad: int,
rpad: int,
space: int,
)Source