ts-prune icon indicating copy to clipboard operation
ts-prune copied to clipboard

[FEATURE] Add colour to the terminal output

Open rubengmurray opened this issue 2 years ago • 7 comments

When lots of items are outputted in the cli, I find they can be difficult to separate out easily by eye.

My initial thought was to separate out the following items by colour (with 1 extra feature):

  • file name (e.g. blue)
  • line number (e.g. yellow)
  • exported name (myObj1) (e.g. green)
  • (new) type of export (const, interface, type) (runtime vs build time) (e.g. red for runtime, purple for buildtime)

After some light digging, the (new) type information felt like a fair amount of extra work as ts-prune doesn't appear to be concerned about that, so I thought I'd add chalk to the outputs, link locally, and raise a proposal PR here.

However, whilst I get additional text being output during testing, I get no colouring.

I'm using Node 14.17.0, Chalk 4, yarn link to symlink and npm link ts-prune, then running as an npm script in another repo.

The fact I'm getting additional text output indicates the yarn/npm link is working, but chalk is not... very strange

// presenter.ts
import chalk from 'chalk';
....

// This had no affect
const formatOutput = (file: string, result: ResultSymbol) => {
  const {name, line, usedInModule} = result;
  return `${chalk.blue(file)}:${chalk.yellow(line)} - ${chalk.green(name)}` + (usedInModule ? USED_IN_MODULE : '');
}
// runner.ts
...

// I then attempted this on the entire output, no affect
filterIgnored.forEach(value => {
  output(chalk.blue(value), 'changed');
});

// I then attempted this on the entire output for sanity, no affect
filterIgnored.forEach(value => {
  console.log(chalk.blue(value), 'changed');
});
console.log(chalk.red('test'))

Any thoughts @nadeesha ? Have you tried colouring here before? 👋 thanks for providing this package

rubengmurray avatar Apr 24 '22 08:04 rubengmurray

Thanks @rubengmurray. I haven't played around with colors, as I've mainly intended this to be a quick CI check. But I'd happily accept a PR if you've got one.

nadeesha avatar May 11 '22 20:05 nadeesha

I managed to get it working... The lack of visibility was based on piping logic applied e.g. ts-prune | grep -v....

PR with code here: https://github.com/nadeesha/ts-prune/pull/180 Piping reference here: https://stackoverflow.com/a/48649918/10732370

rubengmurray avatar May 15 '22 23:05 rubengmurray

Gentle nudge on this @nadeesha - PR is ready if you'd like to give your opinion?

rubengmurray avatar Jun 11 '22 09:06 rubengmurray

Stale issue message

github-actions[bot] avatar Aug 10 '22 13:08 github-actions[bot]

#180 was merged but I can't see that it's been published to npm

rubengmurray avatar Aug 11 '22 21:08 rubengmurray

Stale issue message

github-actions[bot] avatar Oct 11 '22 13:10 github-actions[bot]

@nadeesha looks like this hasn't made it to npm. Could you publish?

rubengmurray avatar Oct 11 '22 15:10 rubengmurray

Stale issue message

github-actions[bot] avatar Dec 12 '22 13:12 github-actions[bot]