示例#1
0
const displayTable = (callback) => {
  const winner = (string) => {
    return chalk.yellow.bold('★ ') + chalk.green.bold(string);
  };

  var array = [
    ['File Name', 'Time (sec)', 'Output']
  ];
  var lowest = -1;

  const removeControlCharacters = (string) => {
    var out = '';
    for (var i = 0; i < string.length; i++) {
      if (string[i] != '\n')
        out += string[i];
    }

    if (out.length > 20)
      out = out.substring(0, 20) + '...';

    return out;
  };

  for (var fileName in scores) {
    if (scores[fileName].time < lowest || lowest == -1)
      lowest = scores[fileName].time;
    array.push([fileName, scores[fileName].time, removeControlCharacters(scores[fileName].result)]);
  }

  var scoreTableNoColor = table.default(array, {
    border: table.getBorderCharacters('norc')
  });

  array[0] = [chalk.bold('File Name'), chalk.bold('Time (sec)'), chalk.bold('Output')];
  for (var i = 1; i < array.length; i++) {
    if (!scores[array[i][0]].correct) {
      array[i][0] = chalk.red(array[i][0]);
      continue;
    }
    if (array[i][1] == lowest) {
      array[i][0] = winner(array[i][0]);
    } else {
      array[i][0] = chalk.yellow(array[i][0]);
    }
  }

  var scoreTable = table.default(array, {
    border: table.getBorderCharacters('norc')
  });

  fs.writeFile('table.txt', scoreTableNoColor, (err) => {
    logger.info('Score table saved as \'table.txt\'');
    console.log(scoreTable);
    callback();
  });
};
  instance.on('done', (result) => {
    // the code below this `if` just renders the results table...
    // if the user doesn't want to render the table, we can just return early
    if (!opts.renderResultsTable) return

    const out = table([
      asColor(chalk.cyan, ['Stat', 'Avg', 'Stdev', 'Max']),
      asRow(chalk.bold('Latency (ms)'), result.latency),
      asRow(chalk.bold('Req/Sec'), result.requests),
      asRow(chalk.bold('Bytes/Sec'), asBytes(result.throughput))
    ], {
      border: getBorderCharacters('void'),
      columnDefault: {
        paddingLeft: 0,
        paddingRight: 1
      },
      drawHorizontalLine: () => false
    })

    logToStream(out)

    if (opts.renderLatencyTable) {
      const latency = table([
        asColor(chalk.cyan, ['Percentile', 'Latency (ms)'])
      ].concat(percentiles.map((perc) => {
        const key = ('p' + perc).replace('.', '')
        return [
          chalk.bold('' + perc),
          result.latency[key]
        ]
      })), {
        border: getBorderCharacters('void'),
        columnDefault: {
          paddingLeft: 0,
          paddingRight: 6
        },
        drawHorizontalLine: () => false
      })

      logToStream(latency)
    }

    if (result.non2xx) {
      logToStream(`${result['2xx']} 2xx responses, ${result.non2xx} non 2xx responses`)
    }
    logToStream(`${format(result.requests.total)} requests in ${result.duration}s, ${prettyBytes(result.throughput.total)} read`)
    if (result.errors) {
      logToStream(`${format(result.errors)} errors (${format(result.timeouts)} timeouts)`)
    }
  })
示例#3
0
function formatTable(modules) {
    var data = [];
    var tableConfig = {
        border: getBorderCharacters("norc"),
        drawHorizontalLine: (index, size) => index <= 1 || index == size
    };
    var stats = {
        moduleCount: modules.length,
        licenseWarning: 0,
        missingLicense: 0,
        missingLicenseFile: 0
    };

    for (let elm in tableConfig.border) {
        tableConfig.border[elm] = chalk.gray.dim(tableConfig.border[elm]);
    }

    data.push([
        chalk.cyan.bold("Module Name"),
        chalk.cyan.bold("Version"),
        chalk.cyan.bold("License"),
        chalk.cyan.bold("License File")
    ]);

    for (let i = 0 ; i < modules.length ; i++) {
        let module = modules[i];
        data.push([
            chalk.bold(module.name),
            module.version,
            module.license ? (module.license.match(/bsd|mit|apache|isc|wtfpl/i)) ? module.license : chalk.yellow(module.license) : chalk.bgRed.white("Unknown"),
            (module.licenseFile ? chalk.green("Yes") : chalk.red("No")) + (module.noticeFile ? " + notice" : "")
        ]);
        if (!module.license) stats.missingLicense += 1;
        if (module.license && !module.license.match(/bsd|mit|apache|isc|wtfpl/i)) stats.licenseWarning += 1;
        if (!module.licenseFile) stats.missingLicenseFile += 1;
    }

    var result = table(data, tableConfig);
    result += `\n${modules.length} modules`;
    if (stats.licenseWarning || stats.missingLicense || stats.missingLicenseFile) {
        var licenseIssues = [];
        if (stats.licenseWarning) licenseIssues.push(chalk.yellow(`${stats.licenseWarning} warning(s)`));
        if (stats.missingLicenseFile) licenseIssues.push(chalk.red(`${stats.missingLicenseFile} missing license file(s)`));
        if (stats.missingLicense) licenseIssues.push(chalk.bgRed.white(`${stats.missingLicense} modules(s) without license`));
        result += "\nLicenses: " + licenseIssues.join(", ");
    }

    return result;
}
示例#4
0
  client.request( 'nodeByName', argv[ 2 ], function( error, item ){

    if( error ){
      console.log( error );
      console.log('');
      return process.exit();
    }

    var res = [];
    var tableConfig = {

      border : table.getBorderCharacters('norc'),
      drawHorizontalLine : function( index, size ){
        return index === 0 || index === 1 || index === size;
      },
      columnDefault : {
        paddingLeft : 2,
        paddingRight : 2
      }

    };

    res.push([ item.name, item.ip, item.status ]);

    item.containers = item.containers.sort( function( a, b ){
      return a.Names[ 0 ] > b.Names[ 0 ];
    });

    item.containers.forEach( function( item ){
      res.push( [ '  ' + item.Names[ 0 ].replace( /^\//, '' ), item.Id.slice( 0, 12 ), item.State === 'running' ? 'ON' : 'OFF' ] );
    });

    res.forEach( function( item ){

      if( item[ 2 ] === 'OFF' ){
        item[ 2 ] = chalk.bgRed.bold( ' ' + item[ 2 ] + ' ' );
      }else{
        item[ 2 ] = ' ' + item[ 2 ] + ' ';
      }

    });

    console.log( table.default( res, tableConfig ) );
    process.exit();

  });
示例#5
0
function formatter(messages, source) {
  if (!messages.length) return ""

  const orderedMessages = _.sortBy(
    messages,
    (m) => m.line ? 2 : 1, // positionless first
    (m) => m.line,
    (m) => m.column
  )

  // Create a list of column widths, needed to calculate
  // the size of the message column and if needed wrap it.
  const columnWidths = { 0: 1, 1: 1, 2: 1, 3: 1, 4: 1 }

  const calculateWidths = function (columns) {

    _.forOwn(columns, (value, key) => {
      columnWidths[key] = Math.max(columnWidths[key], stringWidth(value.toString()))
    })

    return columns
  }

  let output = "\n"

  if (source) {
    output += chalk.underline(logFrom(source)) + "\n"
  }

  const cleanedMessages = orderedMessages.map(
    (message) => {
      const location = utils.getLocation(message)
      const severity = message.severity
      const row = [
        location.line || "",
        location.column || "",
        symbols[severity] ? chalk[levelColors[severity]](symbols[severity]) : severity,
        message
          .text
          // Remove all control characters (newline, tab and etc)
          .replace(/[\x01-\x1A]+/g, " ") // eslint-disable-line
          .replace(/\.$/, "")
          .replace(new RegExp(_.escapeRegExp("(" + message.rule + ")") + "$"), ""),
        chalk.gray(message.rule || ""),
      ]

      calculateWidths(row)

      return row
    })

  output += table(
    cleanedMessages,
    {
      border: getBorderCharacters("void"),
      columns: {
        0: { alignment: "right", width: columnWidths[0], paddingRight: 0 },
        1: { alignment: "left", width: columnWidths[1] },
        2: { alignment: "center", width: columnWidths[2] },
        3: { alignment: "left", width: getMessageWidth(columnWidths), wrapWord: true },
        4: { alignment: "left", width: columnWidths[4], paddingRight: 0 },
      },
      drawHorizontalLine: () => false,
    }
    )
    .split("\n")
    .map((el) => el.replace(/(\d+)\s+(\d+)/, (m, p1, p2) => chalk.gray(p1 + ":" + p2)))
    .join("\n")

  return output
}