Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/brendanashworth/cli-table

Draw tables in a command line interface. Just like MySQL.
https://github.com/brendanashworth/cli-table

Last synced: 9 days ago
JSON representation

Draw tables in a command line interface. Just like MySQL.

Awesome Lists containing this project

README

        

# cli-table

> cli-table helps with drawing tables in command line interfaces.

# Usage
```java
TextTable table = new TextTable();
table.addRow("Name", "Age");
table.addBar();
table.addRow("Gracie Weber", 24);
table.addRow("Lexi O'Conner", 22);

System.out.println(table.toString());
```

```
+--------------+----+
|Name |Age |
+--------------+----+
|Gracie Weber |24 |
|Lexi O'Conner |22 |
+--------------+----+
```

## Order by statement
```java
TextTable table = new TextTable();

table.addRow("Name", "Age");
table.addBar();
table.addRow("Gracie Weber", 24);
table.addRow("Lexi O'Conner", 22);
table.orderBy(1, true); // order by first column, ascending

System.out.println(table.toString());
```

~~~~
+--------------+----+
|Name |Age |
+--------------+----+
|Lexi O'Conner |22 |
|Gracie Weber |24 |
+--------------+----+
~~~~

## Where statement
```java
TextTable table = new TextTable();

table.addRow("Name", "Age");
table.addBar();
table.addRow("Gracie Weber", 24);
table.addRow("Lexi O'Conner", 22);
table.where(1, new WhereComparator() {
@Override
public boolean onCompare(Object colData) {
return (Integer) colData > 23;
}
});

System.out.println(table.toString());
```

```
+-------------+----+
|Name |Age |
+-------------+----+
|Gracie Weber |24 |
+-------------+----+
```