Skip to content

Commit

Permalink
Nicer CLI table
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick McElhaney committed Aug 3, 2019
1 parent a7c21d5 commit 19a827f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 41 deletions.
27 changes: 15 additions & 12 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
const Boolio = require("./Boolio");
const AsciiTable = require("ascii-table");
const table = require("table").table;

const expression = process.argv[2];

const truthTable = new Boolio(expression).truthTable();

const asciiTable = AsciiTable.factory({
heading: [...truthTable.atoms, " = "],
rows: truthTable.rows.map(cols => cols.map(cell => (cell ? "T" : "F")))
});

for (let i = 0; i <= truthTable.atoms.length; i++) {
asciiTable.setAlign(i, AsciiTable.CENTER);
}

console.log(expression);
console.log(asciiTable.toString());
console.log(
table(
[
[...truthTable.atoms, "="],
...truthTable.rows.map(row => row.map(cell => (cell ? "T" : "F")))
],
{
columns: new Array(4).fill({
width: 10,
alignment: "center"
})
}
)
);
75 changes: 47 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
},
"dependencies": {
"acorn": "^6.2.1",
"ascii-table": "0.0.9"
"table": "^5.4.5"
}
}

0 comments on commit 19a827f

Please sign in to comment.