1 | const ck = require('chalk')
|
2 | const sp = require('sprintf-js').sprintf
|
3 | const _ = require('underscore')
|
4 |
|
5 | let cl = {
|
6 | i: ck.yellow,
|
7 | h: ck.red,
|
8 | x: ck.dim,
|
9 | i2: ck.blue,
|
10 | ls(ents) {
|
11 | let max = _.max(ents.map(x => x.length)) + 1
|
12 |
|
13 | let n = ents.length
|
14 |
|
15 | let cols = Math.floor(process.stdout.columns / max)
|
16 | let rows = Math.ceil(n / cols)
|
17 | cols = Math.ceil(n / rows)
|
18 |
|
19 | let s = ''
|
20 | for (let i = 0; i < rows; i++) {
|
21 | for (let j = 0; j < cols; j++) {
|
22 | let ent = ents[i + j * rows]
|
23 | if (!ent) continue
|
24 | s += sp(`%-${max}s`, ent)
|
25 | }
|
26 | s += '\n'
|
27 | }
|
28 |
|
29 | return s
|
30 | }
|
31 | }
|
32 |
|
33 | module.exports = cl
|