On this page:
Unicode Tables
uni-table->string
print-uni-table
8.3

Unicode Tables

Dominik Pantůček <dominik.pantucek@trustica.cz>

 (require uni-table) package: uni-table

This package is an easy-to-use terminal table renderer. It requires terminal with UTF-8 support and can leverage ECMA-48 SGR control sequences for styling both the table borders and cells’ content.

The public API is inspired by tabular from scribble/base and of course text-table. Based on this prior work, the package aims to be usable with the same expectations about argument names and their behavior. However, some design decisions had to be made, which have lead to slight differences.

Currently supported features are:

Example usage:
> (require uni-table)
> (define tbl
    (for/list ((y 6))
      (for/list ((x 6))
        (case (list x y)
          (((3 3)) "big\nbigger\nthe biggest")
          (((0 0)) "")
          (else (format "r~ac~a" y x))))))
> (print-uni-table tbl
                   #:col-borders '((heavy solid)(left light dashed))
                   #:row-borders '((heavy solid)(top light dashed))
                   #:row-align '((center)3(right)())
                   #:col-align '(4(bottom)())
                   #:table-border '(heavy solid))

┏━━━━┳━━━━┳━━━━┳━━━━━━━━━━━┳━━━━┳━━━━┓

    ┃r0c1┃r0c2┃   r0c3    ┃r0c4┃r0c5┃

┣━━━━╋━━━━╇━━━━╇━━━━━━━━━━━╇━━━━╇━━━━┫

┃r1c0┃r1c1╎r1c2╎       r1c3╎r1c4╎r1c5┃

┣━━━━╉╌╌╌╌┼╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌┼╌╌╌╌┨

┃r2c0┃r2c1╎r2c2╎       r2c3╎r2c4╎r2c5┃

┣━━━━╉╌╌╌╌┼╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌┼╌╌╌╌┨

                    big╎r3c4╎r3c5┃

                bigger╎        

┃r3c0┃r3c1╎r3c2╎the biggest╎        

┣━━━━╉╌╌╌╌┼╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌┼╌╌╌╌┨

┃r4c0┃r4c1╎r4c2╎r4c3       ╎r4c4╎r4c5┃

┣━━━━╉╌╌╌╌┼╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌┼╌╌╌╌┨

┃r5c0┃r5c1╎r5c2╎r5c3       ╎r5c4╎r5c5┃

┗━━━━┻━━━━┷━━━━┷━━━━━━━━━━━┷━━━━┷━━━━┛

Colored example:
(print-uni-table tbl
                 #:col-borders '((solid heavy) (left light dashed))
                 #:row-borders '((solid heavy) (top light dashed))
                 #:row-style '((brred) () ... (White))
                 #:col-style '((brmagenta) ())
                 #:row-align '((center) 3 (right)())
                 #:col-align '(4 (bottom) ())
                 #:border-style '(cyan)
                 #:table-border '(heavy solid))

The output in the text terminal should look like this:

image

To see a colored example, run: racket -l uni-table

procedure

(uni-table->string tbl 
  [#:cell-borders cell-borders-spec 
  #:row-borders rows-borders-spec 
  #:column-borders columns-borders-spec 
  #:col-borders alt-columns-borders-spec 
  #:border-style border-style-spec 
  #:cell-align cell-align-spec 
  #:row-align row-align-spec 
  #:column-align column-align-spec 
  #:col-align alt-column-align-spec 
  #:cell-style cell-style-spec 
  #:row-style row-style-spec 
  #:column-style column-style-spec 
  #:col-style alt-column-style-spec 
  #:table-border table-borders-spec]) 
  string?
  tbl : table/c
  cell-borders-spec : borders-spec/c = '()
  rows-borders-spec : (spec-template-of borders-spec/c) = '()
  columns-borders-spec : (spec-template-of borders-spec/c) = '()
  alt-columns-borders-spec : (spec-template-of borders-spec/c)
   = '()
  border-style-spec : sgr-style-spec/c = '()
  cell-align-spec : cell-align-specs/c = '()
  row-align-spec : (spec-template-of cell-align-specs/c) = '()
  column-align-spec : (spec-template-of cell-align-specs/c)
   = '()
  alt-column-align-spec : (spec-template-of cell-align-specs/c)
   = '()
  cell-style-spec : sgr-style-spec/c = '()
  row-style-spec : (spec-template-of sgr-style-spec/c) = '()
  column-style-spec : (spec-template-of sgr-style-spec/c) = '()
  alt-column-style-spec : (spec-template-of sgr-style-spec/c)
   = '()
  table-borders-spec : borders-spec/c = '()
Effectively an exported alias for table->string - which in turn just captures the output of print-table without trailing newline.

procedure

(print-uni-table tbl 
  [#:cell-borders cell-borders-spec 
  #:row-borders rows-borders-spec 
  #:column-borders columns-borders-spec 
  #:col-borders alt-columns-borders-spec 
  #:border-style border-style-spec 
  #:cell-align cell-align-spec 
  #:row-align row-align-spec 
  #:column-align column-align-spec 
  #:col-align alt-column-align-spec 
  #:cell-style cell-style-spec 
  #:row-style row-style-spec 
  #:column-style column-style-spec 
  #:col-style alt-column-style-spec 
  #:table-border table-borders-spec]) 
  void?
  tbl : table/c
  cell-borders-spec : borders-spec/c = '()
  rows-borders-spec : (spec-template-of borders-spec/c) = '()
  columns-borders-spec : (spec-template-of borders-spec/c) = '()
  alt-columns-borders-spec : (spec-template-of borders-spec/c)
   = '()
  border-style-spec : sgr-style-spec/c = '()
  cell-align-spec : cell-align-specs/c = '()
  row-align-spec : (spec-template-of cell-align-specs/c) = '()
  column-align-spec : (spec-template-of cell-align-specs/c)
   = '()
  alt-column-align-spec : (spec-template-of cell-align-specs/c)
   = '()
  cell-style-spec : sgr-style-spec/c = '()
  row-style-spec : (spec-template-of sgr-style-spec/c) = '()
  column-style-spec : (spec-template-of sgr-style-spec/c) = '()
  alt-column-style-spec : (spec-template-of sgr-style-spec/c)
   = '()
  table-borders-spec : borders-spec/c = '()
Formats given table/c two-dimensional table and displays it using displayln to (current-output-port). Effectively this is just a thin wrapper around print-table.