Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add color support for help option #301

Closed
hcodes opened this issue Dec 8, 2014 · 10 comments
Closed

Add color support for help option #301

hcodes opened this issue Dec 8, 2014 · 10 comments

Comments

@hcodes
Copy link

hcodes commented Dec 8, 2014

No description provided.

@hcodes
Copy link
Author

hcodes commented Dec 8, 2014

As example:
cli_color

@tenorok
Copy link

tenorok commented Dec 8, 2014

+1

1 similar comment
@arikon
Copy link

arikon commented Dec 8, 2014

👍

@jd327
Copy link

jd327 commented Nov 4, 2016

+1

@kevyworks
Copy link

kevyworks commented Feb 5, 2019

Still open after 3+ years? Anyhow commander can be extended using class myconsole extends Command and override, but also can be direct prototype which I did here: https://gist.github.com/kevyworks/653b40af20dc9a2509f865cd7fca1ef0 -- This issue should be closed already.

@shadowspawn
Copy link
Collaborator

This has gathered a few likes over the years, so not closing quite yet. I have some problems with choosing colors:

  • color choice is quite personal
  • color support in some Windows shells is poor
  • light and dark themed shells makes color choice harder

I suspect it is too much trouble to build in directly, but perhaps commander can make it easier for people to customise the help output.

@shadowspawn
Copy link
Collaborator

This issue has not had any activity in over six months (other than a comment suggesting it be closed). It isn't likely to get acted on due to this report.

Feel free to open a new issue if it comes up again, with new information and renewed interest.

Thank you for your contributions.

@trusktr
Copy link

trusktr commented Apr 15, 2020

Sywac isn't well documented, but it has a way to specify colors like this:

// See http://sywac.io
const cli = require('sywac')

cli
  .string('-c, --cloudEnv <env>', {
    description: `The cloud env to use.`,
    required: true,
  })
  .version('-v, --version')
  .help('-h, --help')
  .showHelpByDefault()
  // Add colors to the help output!
  .style({
    usagePrefix: str => chalk().yellow(str.slice(0, 6)) + ' ' + chalk().bold(str.slice(7)),
    usageCommandPlaceholder: str => chalk().bold(str),
    usagePositionals: str => chalk().bold(str),
    usageArgsPlaceholder: str => chalk().bold(str),
    usageOptionsPlaceholder: str => chalk().bold(str),
    group: str => chalk().yellow(str),
    flags: str => chalk().bold(str),
    desc: str => chalk().cyan(str),
    hints: str => chalk().gray.dim(str),
    groupError: str => chalk().red.bold(str),
    flagsError: str => chalk().red.bold(str),
    descError: str => chalk().red.bold(str),
    hintsError: str => chalk().red(str),
    messages: str => chalk().red.bold(str), // these are error messages
  })
  .parseAndExit()
  .then(main)
  .catch(e => {
    console.error(e)
    process.exit(1)
  })

let c
function chalk() {
  // lazily load chalk, only used if help text displayed
  if (!c) c = require('chalk')
  return c
}

async function main(opts) {
  const {cloudEnv} = opts
  console.log(cloudEnv)
}

Example output with color:

color

It'd be neat to have some sort of color configurability for Commander.

@ivands
Copy link

ivands commented Nov 30, 2020

It would still be nice to have a more simple api to change colors & styles

@shadowspawn
Copy link
Collaborator

#1365 is a major refactor of how the help is generated including user customisation, but not specifically about adding color support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants