GithubHelp home page GithubHelp logo

flip-tables's Introduction

Flip Tables

Because pretty-printing text tables in Java should be easy.

(╯°□°)╯︵ ┻━┻

Development on this project has basically stopped. You can find a more comprehensive and actively-developed text table library at https://github.com/JakeWharton/picnic.

Usage

A FlipTable requires headers and data in string form:

String[] headers = { "Test", "Header" };
String[][] data = {
    { "Foo", "Bar" },
    { "Kit", "Kat" },
};
System.out.println(FlipTable.of(headers, data));
╔══════╤════════╗
║ Test │ Header ║
╠══════╪════════╣
║ Foo  │ Bar    ║
╟──────┼────────╢
║ Kit  │ Kat    ║
╚══════╧════════╝

They can be empty:

String[] headers = { "Test", "Header" };
String[][] data = {};
System.out.println(FlipTable.of(headers, data));
╔══════╤════════╗
║ Test │ Header ║
╠══════╧════════╣
║ (empty)       ║
╚═══════════════╝

Newlines are supported:

String[] headers = { "One Two\nThree", "Four" };
String[][] data = { { "Five", "Six\nSeven Eight" } };
System.out.println(FlipTable.of(headers, data));
╔═════════╤═════════════╗
║ One Two │ Four        ║
║ Three   │             ║
╠═════════╪═════════════╣
║ Five    │ Six         ║
║         │ Seven Eight ║
╚═════════╧═════════════╝

Which means tables can be nested:

String[] innerHeaders = { "One", "Two" };
String[][] innerData = { { "1", "2" } };
String inner = FlipTable.of(innerHeaders, innerData);
String[] headers = { "Left", "Right" };
String[][] data = { { inner, inner } };
System.out.println(FlipTable.of(headers, data));
╔═══════════════╤═══════════════╗
║ Left          │ Right         ║
╠═══════════════╪═══════════════╣
║ ╔═════╤═════╗ │ ╔═════╤═════╗ ║
║ ║ One │ Two ║ │ ║ One │ Two ║ ║
║ ╠═════╪═════╣ │ ╠═════╪═════╣ ║
║ ║ 1   │ 2   ║ │ ║ 1   │ 2   ║ ║
║ ╚═════╧═════╝ │ ╚═════╧═════╝ ║
╚═══════════════╧═══════════════╝

Helper methods convert from types like lists:

List<Person> people = Arrays.asList(new Person("Foo", "Bar"), new Person("Kit", "Kat"));
System.out.println(FlipTableConverters.fromIterable(people, Person.class));
╔═══════════╤══════════╗
║ FirstName │ LastName ║
╠═══════════╪══════════╣
║ Foo       │ Bar      ║
╟───────────┼──────────╢
║ Kit       │ Kat      ║
╚═══════════╧══════════╝

Or a database result:

ResultSet resultSet = statement.executeQuery("SELECT first_name, last_name FROM users");
System.out.println(FlipTableConverters.fromResultSet(resultSet));
╔════════════╤═══════════╗
║ first_name │ last_name ║
╠════════════╪═══════════╣
║ Jake       │ Wharton   ║
╟────────────┼───────────╢
║ Edward     │ Snowden   ║
╚════════════╧═══════════╝

Arbitrary objects are also supported:

String[] headers = { "First Name", "Last Name", "Age", "Type" };
Object[][] data = {
    { "Big", "Bird", 16, PersonType.COSTUME },
    { "Joe", "Smith", 42, PersonType.HUMAN },
    { "Oscar", "Grouchant", 8, PersonType.PUPPET }
};
System.out.println(FlipTableConverters.fromObjects(headers, data));
╔════════════╤═══════════╤═════╤═════════╗
║ First Name │ Last Name │ Age │ Type    ║
╠════════════╪═══════════╪═════╪═════════╣
║ Big        │ Bird      │ 16  │ COSTUME ║
╟────────────┼───────────┼─────┼─────────╢
║ Joe        │ Smith     │ 42  │ HUMAN   ║
╟────────────┼───────────┼─────┼─────────╢
║ Oscar      │ Grouchant │ 8   │ PUPPET  ║
╚════════════╧═══════════╧═════╧═════════╝

Download

Download the latest jar or reference on Maven central as com.jakewharton.fliptables:fliptables:1.1.1.

Snapshots of the development version are available in Sonatype's snapshots repository.

License

Copyright 2014 Jake Wharton

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

flip-tables's People

Contributors

a11n avatar christiankatzmann avatar dave-r12 avatar dependabot[bot] avatar jakewharton avatar operando avatar renovate[bot] avatar urosjarc 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flip-tables's Issues

Handle Newlines

String[] headers = { "Test", "Header" };
String[][] data = {
    { "Foo\nBar", "Kit\nKat" },
    { "Ping", "Pong" },
};

System.out.println(FlipTables.makeTable(headers, data));
╔══════╤════════╗
║ Test │ Header ║
╠══════╪════════╣
║ Foo  │ Kit    ║
║ Bar  │ Kat    ║
╟──────┼────────╢
║ Ping │ Pong   ║
╚══════╧════════╝

This is essential in order to support nesting.

Explore Column Alignment

A way to specify alignment (left and right only) for columns. Hoping to avoid center alignment and alignment of headers.

FlipTableConverters.fromResultSet() is not public

flip-tables/src/main/java/com/jakewharton/fliptables/FlipTableConverters.java : line 100

The method signature doesn't include keyword "public", so calling it from another class raises a warning.

I'm using this in a Groovy-based test so it doesn't really matter, but it would make it harder to use in something more serious.

Happy to submit a pull request if it's useful, but first wanted to check whether it's intentional or I'm otherwise missing something.

Thanks for the tool! Otherwise works great and is totally saving me time in producing debug output.

Doesn't work in Discord

When I make the table and print it to console, it works just fine. However when I send the same string to discord as a message, it comes out on the other end with messed spaces between columns.

Is this project dead?

Is this project dead?

Support questions and PRs are just sitting there. Should we fork this project or can it be maintained?

Support variable length data

Is it possible to (implicitly) support variable length content? For example,

String[] headers = { "Test", "Header" };
String[][] data = {
    { "Foo", "Bar" },
    { "Kit", "Kat", "Kot" },
};
System.out.println(FlipTable.of(headers, data));

could yield something like:

╔══════╤════════╤═════╗
║ Test │ Header │     ║
╠══════╪════════╪═════╣
║ Foo  │ Bar    │     ║
╟──────┼────────┼─────╢
║ Kit  │ Kat    │ Kot ║
╚══════╧════════╧═════╝

I know this can be achieved by adding an empty string to each other row, but I'm asking for adding it implicitly. Also I'll be happy to submit a PR if it sounds good for you.

Strange characters for the table border

I noticed that from time to time, there are some unidentified characters, printed out as ��� in my Eclipse IDE (4.7.3a) console output which runs on my Debian.

Sometimes, it's 3 of that chars, or sometimes it's 2 only, most of the time, there are none of them. It's totally random.

These unknown characters pushes the border out of sync for that particular line.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/build.yaml
  • actions/checkout v4
  • actions/setup-java v4
  • ffurrer2/extract-release-notes v2
  • softprops/action-gh-release v2
.github/workflows/gradle-wrapper.yaml
  • actions/checkout v4
  • gradle/actions v3
gradle
gradle.properties
settings.gradle
  • org.gradle.toolchains.foojay-resolver-convention 0.8.0
build.gradle
  • com.vanniktech:gradle-maven-publish-plugin 0.28.0
  • junit:junit 4.13.2
  • com.google.truth:truth 1.4.2
gradle-wrapper
gradle/wrapper/gradle-wrapper.properties
  • gradle 8.7

  • Check this box to trigger a request for Renovate to run again on this repository

Fixed column-width

Thanks for a nice lib!

I have an issue here:
tomasbjerre/violations-lib#30

We want a way to set a maximum width of columns. Inject newline to the content of the columns if the length is exceeded.

Would be nice to have that implemented in this lib.

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.