GithubHelp home page GithubHelp logo

table's Introduction

Description

This library displays ascii tables that automatically fit in your terminal and handle most data structures.

Build Status

Install

To have it in a lein project, add to your project.clj:

[table "0.5.0"]

To have it in a deps.edn project, add to your deps.edn:

{table/table {:mvn/version "0.5.0"}}

To use with babashka, add to bb.edn.

Usage

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

$ lein repl
user=> (require '[table.core :as t])
nil

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

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

table can render different styles of tables:

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

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

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

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

table can also render custom styles:

user> (t/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=> (t/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=> (t/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.

table improves on these alternatives 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

  • Handle no rows
  • Handle vecs with different sizes
  • Escape tabs

table's People

Contributors

cldwalker avatar hotwoofy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

table's Issues

Finalizer hang after printing

On the latest Mac OS using alacritty, the following minimum project hangs:

(ns foo.core
  (:require [table.core])
  (:gen-class))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println (table.core/table-str [ [1 2] [3 4]])))

When run with the env variable COLUMNS set to some number it does not hang.
I took a stacktrace of the java process:


"DestroyJavaVM" #15 prio=5 os_prio=31 tid=0x00007fd4d3031800 nid=0x1703 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"clojure-agent-send-off-pool-1" #14 prio=5 os_prio=31 tid=0x00007fd4d2b2c000 nid=0x5803 waiting on condition [0x0000700009414000]
   java.lang.Thread.State: TIMED_WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x000000076dffeac8> (a java.util.concurrent.SynchronousQueue$TransferStack)
        at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
        at java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:460)
        at java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:362)
        at java.util.concurrent.SynchronousQueue.poll(SynchronousQueue.java:941)
        at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1073)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

"clojure-agent-send-off-pool-0" #13 prio=5 os_prio=31 tid=0x00007fd4d19c1000 nid=0x560b waiting on condition [0x0000700009311000]
   java.lang.Thread.State: TIMED_WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x000000076dffeac8> (a java.util.concurrent.SynchronousQueue$TransferStack)
        at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
        at java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:460)
        at java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:362)
        at java.util.concurrent.SynchronousQueue.poll(SynchronousQueue.java:941)
        at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1073)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

"process reaper" #10 daemon prio=10 os_prio=31 tid=0x00007fd4d2b09000 nid=0x5503 waiting on condition [0x000070000920e000]
   java.lang.Thread.State: TIMED_WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x000000076d5d74f0> (a java.util.concurrent.SynchronousQueue$TransferStack)
        at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
        at java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:460)
        at java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:362)
        at java.util.concurrent.SynchronousQueue.poll(SynchronousQueue.java:941)
        at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1073)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

"Service Thread" #9 daemon prio=9 os_prio=31 tid=0x00007fd4d182d800 nid=0x4203 runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C1 CompilerThread3" #8 daemon prio=9 os_prio=31 tid=0x00007fd4d181b000 nid=0x3d03 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread2" #7 daemon prio=9 os_prio=31 tid=0x00007fd4d181a000 nid=0x4403 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread1" #6 daemon prio=9 os_prio=31 tid=0x00007fd4d2843000 nid=0x3b03 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" #5 daemon prio=9 os_prio=31 tid=0x00007fd4d1042800 nid=0x3a03 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" #4 daemon prio=9 os_prio=31 tid=0x00007fd4d2836800 nid=0x3803 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Finalizer" #3 daemon prio=8 os_prio=31 tid=0x00007fd4d1042000 nid=0x4c03 in Object.wait() [0x0000700008ace000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x000000076f589078> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
        - locked <0x000000076f589078> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:165)
        at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:216)

"Reference Handler" #2 daemon prio=10 os_prio=31 tid=0x00007fd4d2806800 nid=0x3303 in Object.wait() [0x00007000089cb000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x000000076f5890d0> (a java.lang.ref.Reference$Lock)
        at java.lang.Object.wait(Object.java:502)
        at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
        - locked <0x000000076f5890d0> (a java.lang.ref.Reference$Lock)
        at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)

"VM Thread" os_prio=31 tid=0x00007fd4d1041000 nid=0x4e03 runnable

"GC task thread#0 (ParallelGC)" os_prio=31 tid=0x00007fd4d1018800 nid=0x1e07 runnable

"GC task thread#1 (ParallelGC)" os_prio=31 tid=0x00007fd4d1019000 nid=0x2a03 runnable

"GC task thread#2 (ParallelGC)" os_prio=31 tid=0x00007fd4d1801000 nid=0x2b03 runnable

"GC task thread#3 (ParallelGC)" os_prio=31 tid=0x00007fd4d1019800 nid=0x5303 runnable

"GC task thread#4 (ParallelGC)" os_prio=31 tid=0x00007fd4d101a000 nid=0x2e03 runnable

"GC task thread#5 (ParallelGC)" os_prio=31 tid=0x00007fd4d1802000 nid=0x5103 runnable

"GC task thread#6 (ParallelGC)" os_prio=31 tid=0x00007fd4d1802800 nid=0x3003 runnable

"GC task thread#7 (ParallelGC)" os_prio=31 tid=0x00007fd4d1803000 nid=0x4f03 runnable

"VM Periodic Task Thread" os_prio=31 tid=0x00007fd4d3002000 nid=0x4103 waiting on condition

JNI global references: 232

Heap
 PSYoungGen      total 76288K, used 65242K [0x000000076ab00000, 0x0000000770000000, 0x00000007c0000000)
  eden space 65536K, 86% used [0x000000076ab00000,0x000000076e277118,0x000000076eb00000)
  from space 10752K, 78% used [0x000000076f580000,0x000000076fdbf9e8,0x0000000770000000)
  to   space 10752K, 0% used [0x000000076eb00000,0x000000076eb00000,0x000000076f580000)
 ParOldGen       total 175104K, used 40K [0x00000006c0000000, 0x00000006cab00000, 0x000000076ab00000)
  object space 175104K, 0% used [0x00000006c0000000,0x00000006c000a000,0x00000006cab00000)
 Metaspace       used 19547K, capacity 20838K, committed 20992K, reserved 1064960K
  class space    used 3957K, capacity 4484K, committed 4608K, reserved 1048576K

I am not sure what is causing that though but it is related to table or one of its dependency.

Configuration:

  • Clojure 1.10
  • Mac OS 10.11.4
  • Table 0.5.0

No option to disable truncations

Hello,

I am trying to print out URLs with this library but they are cut to 32 characters, making them unclickable.

After digging through the code, I don't see any way to specify that I do not want it to truncate data, how can I achieve this?

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.