Coder Social home page Coder Social logo

banquet's Introduction

banquet

Fancy tables.

(def books
  [{:name "The Fellowship of the Ring" :word-count 187790}
   {:name "The Two Towers" :word-count 156198}
   {:name "The Return of the King" :word-count 137115}])

(banquet/print books)

# ╭────────────────────────────┬────────────╮
# │ name                       │ word-count │
# ├────────────────────────────┼────────────┤
# │ The Fellowship of the Ring │ 187790     │
# │ The Two Towers             │ 156198     │
# │ The Return of the King     │ 137115     │
# ╰────────────────────────────┴────────────╯

Banquet is a library for laying out text-based tables that represent lists of Janet structs or tables. It pairs well with Judge, as you can use Banquet in conjunction with test-stdout to write some very readable tests.

Usage

There are a few options to control the output:

(banquet/print books :padding 0)

# ╭──────────────────────────┬──────────╮
# │name                      │word-count│
# ├──────────────────────────┼──────────┤
# │The Fellowship of the Ring│187790    │
# │The Two Towers            │156198    │
# │The Return of the King    │137115    │
# ╰──────────────────────────┴──────────╯
(banquet/print books :separate-rows true)

# ╭────────────────────────────┬────────────╮
# │ name                       │ word-count │
# ├────────────────────────────┼────────────┤
# │ The Fellowship of the Ring │ 187790     │
# ├────────────────────────────┼────────────┤
# │ The Two Towers             │ 156198     │
# ├────────────────────────────┼────────────┤
# │ The Return of the King     │ 137115     │
# ╰────────────────────────────┴────────────╯
(banquet/print books :style banquet/styles/square)

# ┌────────────────────────────┬────────────┐
# │ name                       │ word-count │
# ├────────────────────────────┼────────────┤
# │ The Fellowship of the Ring │ 187790     │
# │ The Two Towers             │ 156198     │
# │ The Return of the King     │ 137115     │
# └────────────────────────────┴────────────┘
(banquet/print books :style banquet/styles/ascii)

# .-----------------------------------------.
# | name                       | word-count |
# |----------------------------+------------|
# | The Fellowship of the Ring | 187790     |
# | The Two Towers             | 156198     |
# | The Return of the King     | 137115     |
# '-----------------------------------------'

The default style is banquet/styles/round. Currently the only styles are:

  • banquet/styles/square
  • banquet/styles/round
  • banquet/styles/ascii

But it's easy to add more.

API

banquet/print-rows takes an iterable of iterables of strings.

(banquet/print-rows [["x" "x²"] ["1" "2"] ["2" "4"]])

banquet/print takes an iterable of dicts, and infers the headers from them.

(banquet/print [{:x 1 :y 2} {:x 2 :y 4}])

Both can take the optional named arguments :padding, :separate-rows, and :style.

There are lower-level helpers for formatting values and inferring headers from dicts. It's probably easiest to just read the source for those.

Changelog

next

  • renamed print-table to print-rows

v1.0.0 2023-06-19

Initial release.

banquet's People

Contributors

ianthehenry avatar

Stargazers

Alec Troemel avatar tionis avatar Eli Mellen avatar Diogo Lisboa avatar Samuel Ludwig avatar Josef Pospíšil avatar

Watchers

 avatar tionis avatar  avatar

Forkers

cfiggers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.