text-table
table->string
print-simple-table
print-table
7.8

text-table

orseau

A simple package to display utf-8 textual tables.

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

Examples:
> (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
Accepts a table specified as a list of lists, and returns a string representing the table. The lists must all be of the same length.

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
Like table->string, but prints the table instead of returning it and uses default arguments for a minimalistic table.

Example:
> (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 ...)

Shorthand form for (displayln (table->string args ...)). Takes the same arguments as table->string.