nathanpeck / clui

Command Line UI toolkit for Node.js
MIT License
1.66k stars 40 forks source link

How do I print items of two arrays, side by side? #24

Closed hunkjazz closed 4 years ago

hunkjazz commented 4 years ago

What I tried, with no success:

var line = new Line();

let foo = arr1.toString("\n")
let bar = arr2.toString("\n")

line.padding(2)
      .column(foo, 40)
      .column(bar, 40)
      .fill();

line.output();

Printed content is either trimmed or mixed.

hunkjazz commented 4 years ago

OK... This project seems to be abandoned. I'll be using cliui.

nathanpeck commented 4 years ago

Your code sample was turning each array into a gigantic string. You needed to put each item from each array into a colume like this:


var outputBuffer = new LineBuffer({
  x: 0,
  y: 0,
  width: 'console',
  height: 'console'
});

for(var i = 0; i < foo.length; i++)
{
  line = new Line(outputBuffer)
    .column(foo[i], 40)
    .column(bar[i], 40)
    .fill()
    .store();
}

outputBuffer.output();