hustcer/tabular/papergrid does not have a README file
pub(open) trait ANSIFmt {
fn fmt_ansi_prefix(Self, StringBuilder) -> Unit
fn fmt_ansi_suffix(Self, StringBuilder) -> Unit
}pub struct Borders {
top : Char?
top_left : Char?
top_right : Char?
top_intersection : Char?
bottom : Char?
bottom_left : Char?
bottom_right : Char?
bottom_intersection : Char?
horizontal : Char?
vertical : Char?
left : Char?
right : Char?
intersection : Char?
left_intersection : Char?
right_intersection : Char?
}pub(all) struct CellBorder {
top : Char?
bottom : Char?
left : Char?
right : Char?
left_top_corner : Char?
right_top_corner : Char?
left_bottom_corner : Char?
right_bottom_corner : Char?
}fn Formatting::new(trim_horizontal~ : Bool, trim_vertical~ : Bool, align_lines~ : Bool) -> Formattingpub enum HAlign {
Left
Right
Center
}pub enum HeightMode {
None
Increase(Int)
Limit(Int)
}pub struct HorizontalLine {
main : Char?
left : Char?
intersection : Char?
right : Char?
}fn HorizontalLine::from_chars(main : Char?, left : Char?, intersection : Char?, right : Char?) -> HorizontalLinefn HorizontalLine::full(main : Char, left : Char, intersection : Char, right : Char) -> HorizontalLinepub enum HorizontalLines {
All
HeaderOnly
None
}fn IterGrid::new(records : IterRecords, config : SpannedConfig, dimension : IterGridDimension) -> IterGridfn IterGridDimension::estimate(self : IterGridDimension, records : IterRecords, cfg : SpannedConfig) -> Unitfn IterGridDimension::measure_heights(records : IterRecords, config : SpannedConfig, apply_modes? : Bool) -> Array[Int]fn IterGridDimension::measure_rendered(records : IterRecords, config : SpannedConfig) -> (Array[Int], Array[Int])test {
let records = @papergrid.IterRecords::new([["abcdef"]])
let config = @papergrid.SpannedConfig::default()
config.set_width_mode(@papergrid.WidthMode::wrap(2))
config.set_height_mode(@papergrid.HeightMode::increase(5))
assert_eq(
@papergrid.IterGridDimension::measure_rendered(records, config),
([2], [5]),
)
}fn PeekableGridDimension::estimate(self : PeekableGridDimension, records : IterRecords, config : SpannedConfig) -> Unitfn PeekableGridDimension::measure(records : IterRecords, config : SpannedConfig) -> (Array[Int], Array[Int])fn PeekableGridDimension::measure_heights(records : IterRecords, config : SpannedConfig) -> Array[Int]fn PeekableGridDimension::measure_widths(records : IterRecords, config : SpannedConfig) -> Array[Int]pub struct SpannedConfig {
borders : Borders
padding_left : Int
padding_right : Int
padding_top : Int
padding_bottom : Int
align : HAlign
valign : VAlign
width_mode : WidthMode
height_mode : HeightMode
horizontal_lines : HorizontalLines
custom_horizontal_lines : Array[(Int, HorizontalLine)]
width_rules : Array[(Scope, WidthMode)]
height_rules : Array[(Scope, HeightMode)]
align_rules : Array[(Scope, HAlign)]
valign_rules : Array[(Scope, VAlign)]
padding_rules : Array[(Scope, Int, Int, Int, Int)]
col_spans : Array[(Int, Int, Int)]
row_spans : Array[(Int, Int, Int)]
span_sources : Array[(Int, Int, Int, Int)]
border_horizontal : Array[(Int, Int, Char)]
border_vertical : Array[(Int, Int, Char)]
border_intersection : Array[(Int, Int, Char)]
margin_top : Int
margin_bottom : Int
margin_left : Int
margin_right : Int
margin_fill_top : Char
margin_fill_bottom : Char
margin_fill_left : Char
margin_fill_right : Char
margin_offset_top : Int
margin_offset_bottom : Int
margin_offset_left : Int
margin_offset_right : Int
// private fields
}fn SpannedConfig::clear_span_source(self : SpannedConfig, anchor_row : Int, anchor_col : Int) -> Unitfn SpannedConfig::clear_unused_span_source(self : SpannedConfig, anchor_row : Int, anchor_col : Int) -> Unitfn SpannedConfig::get_cell_border(self : SpannedConfig, row : Int, col : Int, count_rows : Int, count_cols : Int) -> CellBorderfn SpannedConfig::has_left_border(self : SpannedConfig, row : Int, col : Int, count_rows : Int, count_cols : Int) -> Boolfn SpannedConfig::has_top_border(self : SpannedConfig, row : Int, col : Int, count_rows : Int, count_cols : Int) -> Boolfn SpannedConfig::horizontal_override_at(self : SpannedConfig, row_boundary : Int, col : Int) -> Char?fn SpannedConfig::intersection_override_at(self : SpannedConfig, row_boundary : Int, col_boundary : Int) -> Char?fn SpannedConfig::set_align_for_cell(self : SpannedConfig, row : Int, col : Int, align : HAlign) -> Unitfn SpannedConfig::set_align_for_cols(self : SpannedConfig, start : Int, end : Int, align : HAlign) -> Unitfn SpannedConfig::set_align_for_rows(self : SpannedConfig, start : Int, end : Int, align : HAlign) -> Unitfn SpannedConfig::set_alignment_fill(self : SpannedConfig, entity : Entity, fill : Char, color? : ANSIBuf) -> Unitfn SpannedConfig::set_cell_border(self : SpannedConfig, row : Int, col : Int, border : CellBorder) -> Unitfn SpannedConfig::set_custom_horizontal_lines(self : SpannedConfig, lines : Array[(Int, HorizontalLine)]) -> Unitfn SpannedConfig::set_formatting(self : SpannedConfig, entity : Entity, formatting : Formatting) -> Unitfn SpannedConfig::set_height_mode_for_cell(self : SpannedConfig, row : Int, col : Int, mode : HeightMode) -> Unitfn SpannedConfig::set_height_mode_for_cols(self : SpannedConfig, start : Int, end : Int, mode : HeightMode) -> Unitfn SpannedConfig::set_height_mode_for_rows(self : SpannedConfig, start : Int, end : Int, mode : HeightMode) -> Unitfn SpannedConfig::set_margin(self : SpannedConfig, top : Int, bottom : Int, left : Int, right : Int, fill_top : Char, fill_bottom : Char, fill_left : Char, fill_right : Char) -> Unitfn SpannedConfig::set_margin_offset(self : SpannedConfig, top : Int, bottom : Int, left : Int, right : Int) -> Unitfn SpannedConfig::set_padding(self : SpannedConfig, left : Int, right : Int, top : Int, bottom : Int) -> Unitfn SpannedConfig::set_padding_color(self : SpannedConfig, entity : Entity, colors : Sides[ANSIBuf?]) -> Unitfn SpannedConfig::set_padding_for_all(self : SpannedConfig, left : Int, right : Int, top : Int, bottom : Int) -> Unitfn SpannedConfig::set_padding_for_cell(self : SpannedConfig, row : Int, col : Int, left : Int, right : Int, top : Int, bottom : Int) -> Unitfn SpannedConfig::set_padding_for_cols(self : SpannedConfig, start : Int, end : Int, left : Int, right : Int, top : Int, bottom : Int) -> Unitfn SpannedConfig::set_padding_for_rows(self : SpannedConfig, start : Int, end : Int, left : Int, right : Int, top : Int, bottom : Int) -> Unitfn SpannedConfig::set_padding_sides(self : SpannedConfig, entity : Entity, padding : Sides[Indent]) -> Unitfn SpannedConfig::set_span_source(self : SpannedConfig, anchor_row : Int, anchor_col : Int, source_row : Int, source_col : Int) -> Unitfn SpannedConfig::set_trim_horizontal(self : SpannedConfig, entity : Entity, enabled : Bool) -> Unitfn SpannedConfig::set_valign_for_cell(self : SpannedConfig, row : Int, col : Int, align : VAlign) -> Unitfn SpannedConfig::set_valign_for_cols(self : SpannedConfig, start : Int, end : Int, align : VAlign) -> Unitfn SpannedConfig::set_valign_for_rows(self : SpannedConfig, start : Int, end : Int, align : VAlign) -> Unitfn SpannedConfig::set_width_mode_for_cell(self : SpannedConfig, row : Int, col : Int, mode : WidthMode) -> Unitfn SpannedConfig::set_width_mode_for_cols(self : SpannedConfig, start : Int, end : Int, mode : WidthMode) -> Unitfn SpannedConfig::set_width_mode_for_rows(self : SpannedConfig, start : Int, end : Int, mode : WidthMode) -> Unitfn SpannedConfig::span_anchor_for_source(self : SpannedConfig, source_row : Int, source_col : Int) -> (Int, Int)?fn SpannedConfig::span_source_at(self : SpannedConfig, anchor_row : Int, anchor_col : Int) -> (Int, Int)fn SpannedConfig::vertical_override_at(self : SpannedConfig, row : Int, col_boundary : Int) -> Char?pub enum VAlign {
Top
Bottom
Center
}pub enum WidthMode {
None
Wrap(Int, String)
Truncate(Int, String)
}fn colorize_suffix(text : String, suffix : String) -> Stringfn cut_str(text : String, width : Int) -> Stringtest {
assert_eq(
@papergrid.cut_str("\u001b[31m中文\u001b[39m", 3),
"\u001b[31m中\u001b[39m�",
)
}fn get_char_width(ch : Char) -> Intfn get_line_width(text : String) -> Intfn get_string_width(text : String) -> Inttest {
assert_eq(@papergrid.get_string_width("👩🔬"), 2)
assert_eq(@papergrid.get_char_width('🏳'), 1)
assert_eq(@papergrid.get_string_width("🏳️"), 2)
}fn get_text_dimension(text : String) -> (Int, Int)fn processed_lines(content : String, width_mode : WidthMode, height_mode : HeightMode) -> Array[String]fn replace_tab(text : String, size : Int) -> Stringfn strip_ansi(text : String) -> Stringfn trim_ansi_whitespace(text : String) -> Stringfn wrap_text(text : String, width : Int, placeholder? : String, keep_words? : Bool) -> Stringtest {
assert_eq(@papergrid.wrap_text("ab中", 2), "ab\n中")
}Install
Download zipA MoonBit library for pretty-printing tables in terminal. Ported from Rust tabled.