Skip to content

mbarbin/print-table

Repository files navigation

print-table

CI Status Coverage Status OCaml-CI Build Status

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))
┌───────┬───────┐
│ NameScore │
├───────┼───────┤
│ Alice10 │
│ Bob3 │
└───────┴───────┘

- : 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:

Name Score
Alice 10
Bob 3

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.

About

Simple Unicode/ANSI and Markdown text table rendering for OCaml

Topics

Resources

License

ISC, Unknown licenses found

Licenses found

ISC
LICENSE
Unknown
COPYING.HEADER

Code of conduct

Stars

Watchers

Forks

Packages

No packages published