text-table
(require text-table) | package: text-table |
To install:
raco pkg install text-table |
See the example in the main submodule of the "main.rkt" file. You can observe the results by running:
racket -l text-table |
> (displayln (table->string '((a b c d e f gggg h) (123 456 77 54 1 5646547987 41 1) (111 22 3333 44 5 6 7 8888))))
┌───┬───┬────┬──┬─┬──────────┬────┬────┐
│a │b │c │d │e│f │gggg│h │
├───┼───┼────┼──┼─┼──────────┼────┼────┤
│123│456│77 │54│1│5646547987│41 │1 │
├───┼───┼────┼──┼─┼──────────┼────┼────┤
│111│22 │3333│44│5│6 │7 │8888│
└───┴───┴────┴──┴─┴──────────┴────┴────┘
> (displayln (table->string '((a b c d e f gggg h) (123 456 77 54 1 5646547987 41 1) (111 22 3333 44 5 6 7 8888)) #:border-style 'double #:framed? #f #:row-sep? #t #:align '(left center center center center center center right)))
a ║ b ║ c ║d ║e║ f ║gggg║ h
═══╬═══╬════╬══╬═╬══════════╬════╬════
123║456║ 77 ║54║1║5646547987║ 41 ║ 1
═══╬═══╬════╬══╬═╬══════════╬════╬════
111║22 ║3333║44║5║ 6 ║ 7 ║8888
procedure
(table->string table [ #:->string to-string #:border-style border-style #:framed? framed? #:row-sep? row-sep? #:align align]) → string? table : (listof list?) to-string : procedure? = ~a
border-style : (or/c 'single 'space 'space-single 'rounded 'double 'latex) = 'single framed? : boolean? = #t row-sep? : boolean? = #t
align :
(or/c (listof (or/c 'left 'center 'right)) (or/c 'left 'center 'right)) = 'left
The to-string procedure is used to convert cell values to strings.
The border-style specifies the style of lines to be used in drawing the table.
When framed? is #true, a frame is drawn around the outside of the table.
When row-sep? is false, no separators are drawn between the rows.
The align specification indicates how the contents of the cells are to be aligned within their cells. A single-symbol specification applies to all cells, or a list of symbols of the same length as the rows can be applied in order to specify the alignment of each column independently. When align is a list, it is trimmed to the length of the columns if it is too long, or the last element of the list is used for the remaining columns if it is too short.
procedure
(print-simple-table table [ #:->string to-string #:border-style border-style #:framed? framed? #:row-sep? row-sep? #:align align]) → string? table : (listof list?) to-string : procedure? = ~a
border-style : (or/c 'single 'space 'space-single 'rounded 'double 'latex) = 'space framed? : boolean? = #f row-sep? : boolean? = #f
align :
(or/c (listof (or/c 'left 'center 'right)) (or/c 'left 'center 'right)) = 'left
> (print-simple-table #:align '(left right) '((1 2 3 4444) (aaa bbb ccc d)))
1 2 3 4444
aaa bbb ccc d
syntax
(print-table args ...)