Coder Social home page Coder Social logo

ivanfrolovmd / asciitable Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 0.0 81 KB

ASCII Table

License: The Unlicense

Kotlin 1.54% Scala 98.46%
ascii-table terminal command-line command-line-tool commandline-interface ascii ascii-graphics table scala spreadsheet

asciitable's Introduction

JitPack

ASCII Table

This is a small library to render tables using ascii art. The column widths are calculated automatically by sampling the first 50 rows (configurable) to fit the table in desired screen width.

Multi-line mode

When used in multi-line mode, cells overflowing the column width are rendered using several lines, for example:

AsciiTable()
  .width(40) // screen width to fit table in
  .multiline(true) // render rows across multiple lines
  .columnMinWidth(7) // column width will be 7 characters or more
  .rowMaxHeight(3) // clip cells at 3 lines
  .header("N", "column", "column with long values")
  .row("1", "value 1", "Lorem ipsum dolor sit amet, consectetur")
  .row("2", "value 2", "Lorem ipsum dolor sit amet, consectetur" * 3)
  .row("3", "foo", "bar")
  .write()

produces:

<------------ 40 characters ----------->
╔═╤═══════╤════════════════════════════╗
║N│column │column with long values     ║
╠═╪═══════╪════════════════════════════╣
║1│value 1│Lorem ipsum dolor sit amet, ║
║ │       │consectetur                 ║
╟─┼───────┼────────────────────────────╢ ↑
║2│value 2│Lorem ipsum dolor sit amet, ║ |
║ │       │consecteturLorem ipsum dolor║ 3 lines max
║ │       │ sit amet, consecteturLorem…║ |
╟─┼───────┼────────────────────────────╢ ↓
║3│foo    │bar                         ║
╚═╧═══════╧════════════════════════════╝
   <- 7 -> 

One-line mode

In one-line mode cells are clipped at column width:

AsciiTable()
  .width(40) // screen width to fit table in
  .multiline(false) // one line per row
  .columnMinWidth(7) // column width is be 7 characters or more
  .header("N", "column", "column with long values")
  .row("1", "value 1", "Lorem ipsum dolor sit amet, consectetur")
  .row("2", "value 2", "Lorem ipsum dolor sit amet, consectetur" * 3)
  .row("3", "foo", "bar")
<------------ 40 characters ----------->
╔═╤═══════╤════════════════════════════╗
║N│column │column with long values     ║
╠═╪═══════╪════════════════════════════╣
║1│value 1│Lorem ipsum dolor sit amet,…║
║2│value 2│Lorem ipsum dolor sit amet,…║
║3│foo    │bar                         ║
╚═╧═══════╧════════════════════════════╝

ASCII-only mode

Previous sections used box drawing characters, which contain unicode symbols. If ASCII-only set is required, it is possible to switch to legacy mode:

AsciiTable()
  .useAscii(true) // use ASCII-only characters
  .width(40)
  .multiline(true)
  .columnMinWidth(7)
  .rowMaxHeight(3)
  .header("N", "column", "column with long values")
  .row("1", "value 1", "Lorem ipsum dolor sit amet, consectetur")
  .row("2", "value 2", "Lorem ipsum dolor sit amet, consectetur" * 3)
  .row("3", "foo", "bar")
  .write()
+-+-------+----------------------------+
|N|column |column with long values     |
+-+-------+----------------------------+
|1|value 1|Lorem ipsum dolor sit amet, |
| |       |consectetur                 |
+-+-------+----------------------------+
|2|value 2|Lorem ipsum dolor sit amet, |
| |       |consecteturLorem ipsum dolor|
| |       | sit amet, consecteturLorem_|
+-+-------+----------------------------+
|3|foo    |bar                         |
+-+-------+----------------------------+

Installation

Gradle

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

dependencies {
  compile 'com.github.ivanfrolovmd:asciitable:0.0.8'
}

Maven

<repositories>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
  </repository>
</repositories>

<dependency>
  <groupId>com.github.ivanfrolovmd</groupId>
  <artifactId>asciitable</artifactId>
  <version>0.0.8</version>
</dependency>

SBT

resolvers += "jitpack" at "https://jitpack.io"
libraryDependencies += "com.github.ivanfrolovmd" % "asciitable" % "0.0.8"

asciitable's People

Contributors

ivanfrolovmd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.