From b6f135419df020916c3b56c877a4e331ea8a0637 Mon Sep 17 00:00:00 2001 From: Olli Vanhoja Date: Thu, 6 Oct 2016 16:27:06 +0300 Subject: [PATCH] Proper strlen function for strings containing ANSI escape codes --- bin/now-alias | 3 ++- bin/now-list | 3 ++- bin/now-secrets | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bin/now-alias b/bin/now-alias index 3a5d51e..a7374be 100755 --- a/bin/now-alias +++ b/bin/now-alias @@ -2,6 +2,7 @@ import chalk from 'chalk'; import minimist from 'minimist'; import table from 'text-table'; +import strlen from '../lib/strlen'; import ms from 'ms'; import NowAlias from '../lib/alias'; import login from '../lib/login'; @@ -142,7 +143,7 @@ async function run (token) { _url, time ]; - }), { align: ['l', 'r', 'l', 'l'], hsep: ' '.repeat(2) }); + }), { align: ['l', 'r', 'l', 'l'], hsep: ' '.repeat(2), stringLength: strlen }); const elapsed_ = ms(new Date() - start_); console.log(`> ${aliases.length} alias${aliases.length > 1 ? 'es' : ''} found ${chalk.gray(`[${elapsed_}]`)}`); diff --git a/bin/now-list b/bin/now-list index 11766b2..8fdca69 100755 --- a/bin/now-list +++ b/bin/now-list @@ -4,6 +4,7 @@ import fs from 'fs-promise'; import minimist from 'minimist'; import chalk from 'chalk'; import table from 'text-table'; +import strlen from '../lib/strlen'; import ms from 'ms'; import Now from '../lib'; import login from '../lib/login'; @@ -101,7 +102,7 @@ async function list (token) { const _url = chalk.underline(`https://${url}`); const time = chalk.gray(ms(current - created) + ' ago'); return [uid, _url, time]; - }), { align: ['l', 'r', 'l'], hsep: ' '.repeat(6) }); + }), { align: ['l', 'r', 'l'], hsep: ' '.repeat(6), stringLength: strlen }); return chalk.bold(name) + '\n\n' + indent(t, 2); }).join('\n\n'); const elapsed = ms(new Date() - start); diff --git a/bin/now-secrets b/bin/now-secrets index 788bd2e..5632837 100755 --- a/bin/now-secrets +++ b/bin/now-secrets @@ -1,6 +1,7 @@ #!/usr/bin/env node import chalk from 'chalk'; import table from 'text-table'; +import strlen from '../lib/strlen'; import minimist from 'minimist'; import * as cfg from '../lib/cfg'; import { handleError, error } from '../lib/error'; @@ -119,7 +120,7 @@ async function run (token) { chalk.bold(secret.name), chalk.gray(ms(cur - new Date(secret.created)) + ' ago') ]; - }), { align: ['l', 'r', 'l'], hsep: ' '.repeat(2) }); + }), { align: ['l', 'r', 'l'], hsep: ' '.repeat(2), stringLength: strlen }); if (out) console.log('\n' + out + '\n'); return secrets.close(); }