print-table
 
  
 
Print_table provides a minimal library for rendering text tables with Unicode box-drawing characters and optional ANSI colors:
# let columns =
  Print_table.O.
    [ Column.make ~header:"Name" (fun (name, _) -> Cell.text name)
    ; Column.make ~header:"Score" ~align:Right (fun (_, score) ->
        Cell.text (Int.to_string score))
    ]
val columns : (string * int) Print_table.Column.t list = [<abstr>; <abstr>]
# let rows = [ "Alice", 10; "Bob", 3 ] ;;
val rows : (string * int) list = [("Alice", 10); ("Bob", 3)]
# print_endline (Print_table.to_string_text (Print_table.make ~columns ~rows))
┌───────┬───────┐
│ Name  │ Score │
├───────┼───────┤
│ Alice │    10 │
│ Bob   │     3 │
└───────┴───────┘
- : unit = ()
Or as GitHub-flavored Markdown:
# print_endline (Print_table.to_string_markdown (Print_table.make ~columns ~rows))
| Name  | Score |
|:------|------:|
| Alice |    10 |
| Bob   |     3 |
- : unit = ()
which is rendered natively by GitHub like this:
Code Documentation
The code documentation of the latest release is built with odoc and published to GitHub pages here.
Acknowledgments
This library has taken some inspiration from 2 existing and more feature-complete libraries, which we link to here for more advanced usages.