How to use tty-table - 9 common examples

To help you get started, we’ve selected a few tty-table examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github subzerocloud / subzero-cli / src / cloud.js View on Github external
const printAppWithDescription = app => {
  let rows = [];
  Object.keys(app).map( x => rows.push([ x, app[x] + "\n" + (descriptions[x]||'').grey]));
  let table = new Table([
      { value: "Property", align: 'left', headerAlign: 'left' },
      { value: "Value", width: 80, align: 'left', headerAlign: 'left'}
  ], rows, { defaultValue: "", borderStyle: 0, compact: true});
  console.log(table.render().toString());
}
github terascope / teraslice / packages / teraslice-cli / src / cmds / lib / display.ts View on Github external
async function pretty(headerValues: any, rows: any) {
    const header: any[] = [];
    _.each(headerValues, (item) => {
        const col: any = [];
        col.value = item;
        header.push(col);
    });

    const table = ttyTable(header, rows, {
        borderStyle: 1,
        paddingTop: 0,
        paddingBottom: 0,
        headerAlign: 'left',
        align: 'left',
        defaultValue: ''
    });

    console.log(table.render());
}
github teambit / bit / src / cli / templates / list-template.ts View on Github external
id,
      localVersion: version,
      deprecated: listScopeResult.deprecated,
      currentVersion: listScopeResult.currentlyUsedVersion || 'N/A',
      remoteVersion: listScopeResult.remoteVersion || 'N/A'
    };
    return data;
  }

  if (json) {
    const jsonResults = listScopeResults.map(toJsonComponent);
    return JSON.stringify(jsonResults, null, 2);
  }
  const rows = listScopeResults.map(tabulateComponent);

  const table = new Table(header, rows.map(row => R.values(row)), opts);
  return table.render();
};
github teambit / bit / src / cli / commands / private-cmds / cat-scope-cmd.ts View on Github external
});
      return JSON.stringify(payload, null, 2);
    }
    if (json) {
      return JSON.stringify(payload, null, 2);
    }
    if (!full) {
      const header = [
        { value: 'Id', width: 70, headerColor: 'cyan' },
        { value: 'Object', width: 50, headerColor: 'cyan' }
      ];
      const opts = {
        align: 'left'
      };

      const table = new Table(header, [], opts);
      payload.forEach(co => table.push([co.id(), `obj: ${co.hash().toString()}`]));
      return table.render();
    }

    return payload.map(co => `> ${co.hash().toString()}\n\n${co.id()}\n`).join('\n');
  }
}
github takeoff-env / takeoff / src / lib / generate-table.ts View on Github external
.reduce(
      (headerWidths: number[], textWidths: number[]) =>
        headers.map(
          (h: TableHeader, index: number) =>
            textWidths[index] > headerWidths[index]
              ? textWidths[index] > 60
                ? 60
                : textWidths[index]
              : headerWidths[index],
        ),
      [DEFAULT_WIDTH, DEFAULT_WIDTH, DEFAULT_WIDTH, DEFAULT_WIDTH],
    );

  headers.map((header: TableHeader, index: number) => (header.width = colWidths[index] + PADDING));

  return new table(headers, tableValues, options);
};
github teambit / bit / src / cli / templates / list-template.js View on Github external
id,
      localVersion: version,
      deprecated: listScopeResult.deprecated,
      currentVersion: listScopeResult.currentlyUsedVersion || 'N/A',
      remoteVersion: listScopeResult.remoteVersion || 'N/A'
    };
    return data;
  }

  if (json) {
    const jsonResults = listScopeResults.map(toJsonComponent);
    return JSON.stringify(jsonResults, null, 2);
  }
  const rows = listScopeResults.map(tabulateComponent);

  const table = new Table(header, rows.map(row => R.values(row)), opts);
  return table.render();
};
github teambit / bit / src / cli / templates / docs-template.ts View on Github external
export const paintDoc = (doc: Doclet) => {
  const { name, description, args, returns, properties } = doc;

  const header = [
    { value: 'Name', width: 20, headerColor: 'cyan', headerAlign: 'left' },
    { value: `${name}`, width: 50, headerColor: 'white', color: 'white', headerAlign: 'left' }
  ];
  const opts = {
    align: 'left'
  };

  const table = new Table(header, [], opts);

  const paintArg = arg => {
    if (!arg && !arg.type && !arg.name) {
      return '';
    }
    if (!arg.type) {
      return `${arg.name}`;
    }
    return `${arg.name}: ${arg.type}`;
  };

  const paintArgs = () => {
    if (!args || !args.length) return '';
    return `(${args.map(paintArg).join(', ')})`;
  };
github teambit / bit / src / cli / commands / public-cmds / remote-cmd.ts View on Github external
report(remotes: { [key: string]: string }): string {
    if (empty(remotes)) return chalk.red('no configured remotes found in scope');

    const header = [
      { value: 'scope name', width: 30, headerColor: 'cyan' },
      { value: 'host', width: 100, headerColor: 'cyan' }
    ];
    const opts = {
      align: 'left'
    };

    const table = new Table(header, [], opts);

    forEach(remotes, (host, name) => {
      table.push([name, host]);
    });

    return table.render();
  }
}
github teambit / bit / src / cli / chalk-box.ts View on Github external
const specsSummary = specResults => {
    const specsPassed = specResults.map(specResult => specResult.pass);
    const areAllPassed = specsPassed.every(isPassed => isPassed);
    return areAllPassed ? c.green('passed') : c.red('failed');
  };
  const summaryRows = results.map(result => {
    const componentId = c.bold(result.componentId.toString());
    if (result.missingTester) return [componentId, c.bold.red('tester is not defined')];
    if (result.missingDistSpecs) {
      return [componentId, c.yellow('bit found test file tracked, but none was found when running tests')];
    }
    if (result.specs) return [componentId, specsSummary(result.specs)];
    return [componentId, c.yellow('tests are not defined')];
  });

  const summaryTable = new Table(summaryHeader, summaryRows);
  return summaryTable.render();
};

tty-table

Node cli table

MIT
Latest version published 6 months ago

Package Health Score

73 / 100
Full package analysis

Popular tty-table functions