GithubHelp home page GithubHelp logo

plumpmath / table Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cldwalker/table

0.0 0.0 0.0 212 KB

Display ascii tables for almost any data structure with ease.

License: MIT License

Clojure 100.00%

table's Introduction

Description

Display ascii tables that fit in your terminal for almost any data structure.

Build Status

Install

To have it available on all projects, add to your leiningen2's ~/lein/profiles.clj:

{:user {:dependencies [[table "0.5.0"]] }}

To have it on an individual project, add to your project.clj:

[table "0.5.0"]

Usage

To use in a library:

(use '[table.core :only [table]])

table handles rendering combinations of maps, vecs, lists and sets nested in one another.

$ lein repl
user=> (use 'table.core)
nil

; These three yields the same table
user=> (table [["1" "2"] ["3" "4"]])
user=> (table '((1 2) (3 4)))
user=> (table #{[1 2] [3 4]})
+---+---+
| 1 | 2 |
+---+---+
| 3 | 4 |
+---+---+

user=> (table [{:a 11} {:a 3 :b 22}])
+----+----+
| a  | b  |
+----+----+
| 11 |    |
| 3  | 22 |
+----+----+

table can render different styles of tables:

user=> (table [ [1 2] [3 4]] :style :unicode)
┌───┬───┐
│ 1 │ 2 │
├───┼───┤
│ 3 ╎ 4 │
└───┴───┘

user=> (table [ [1 2] [3 4]] :style :org)
|---+---|
| 1 | 2 |
|---+---|
| 3 | 4 |
|---+---|

# Yes, these will generate tables for github's markdown
user=> (table [ [10 20] [3 4]] :style :github-markdown)

| 10 | 20 |
|--- | ---|
| 3  | 4  |

table can also render custom styles:

user> (table [[10 20] [3 4]] :style {:top ["◤ " " ▼ " " ◥"]
                             :top-dash "✈︎"
                             :middle ["▶︎ " "   " " ◀︎"]
                             :dash "✂︎"
                             :bottom ["◣ " " ▲ " " ◢"]
                             :bottom-dash "☺︎"
                             :header-walls ["  " "   " "  "]
                             :body-walls ["  " "   " "  "] })
◤ ✈︎✈︎ ▼ ✈︎✈︎ ◥
  10   20
▶︎ ✂︎✂︎   ✂︎✂︎ ◀︎
  3    4
◣ ☺︎☺︎ ▲ ☺︎☺︎ ◢

table can handle plain maps and vectors of course:

user=> (table (meta #'doc))
+-----------+---------------------------------------------------------------+
| key       | value                                                         |
+-----------+---------------------------------------------------------------+
| :macro    | true                                                          |
| :ns       | clojure.repl                                                  |
| :name     | doc                                                           |
| :arglists | ([name])                                                      |
| :added    | 1.0                                                           |
| :doc      | Prints documentation for a var or special form given its name |
| :line     | 120                                                           |
| :file     | clojure/repl.clj                                              |
+-----------+---------------------------------------------------------------+

user=> (table (seq (.getURLs (java.lang.ClassLoader/getSystemClassLoader))))
+--------------------------------------------------+
| value                                            |
+--------------------------------------------------|
| file:/Users/me/code/gems/table/test/             |
| file:/Users/me/code/gems/table/src/              |
| file:/Users/me/code/gems/table/dev-resources     |
| file:/Users/me/code/gems/table/resources         |
| file:/Users/me/code/gems/table/target/classes/   |
...

Configuration

If your terminal width isn't being auto-detected, you can execute this in your shell before using the repl: export COLUMNS. Alternatively you can bind/alter table.width/*width* to your desired width.

Similar libraries

  • Clojure 1.5.0 comes with a similar function clojure.pprint/print-table
  • doric is more full-featured than print-table, supporting formats other than text. But it lacks support for handling many data structures and tests are weak.

table improves on these by rendering more data structures, supporting different ascii style tables and resizing to fit your terminal.

Bugs/Issues

Please report them on github.

Contributing

See here

TODO

  • Set default style
  • Handle no rows
  • Handle vecs with different sizes
  • Look into auto-rendering database results in reply repl
  • Escape tabs

table's People

Contributors

cldwalker avatar hotwoofy avatar

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.