Skip to content

NO_COLOR variable ignored  #1488

Closed

Description

@danshearer

Describe the bug

NO_COLOR variable is ignored in "gh issue create"

gh version 0.10.1-226-gebdd79d (2020-08-05)

Steps to reproduce the behavior

  1. gh issue create
  2. Text starting from "Choose a template" has ANSI colour sequences
  3. I tried various values for NO_COLOR including "yes" and "***************" just in case

See attached screenshot.
NO_COLOR

Expected vs actual behavior

I expected all text to be plain, ie no ANSI escapes

Activity

  1. added
    bug
    on Aug 5, 2020
  2. mislav commented on Aug 5, 2020

    @mislav
    Contributor

    Thanks for reporting! This is indeed a bug.

    We don't output any ANSI escape sequences in NO_COLOR mode from our code, but we do invoke the Survey library for prompts, and it appears that it doesn't respect NO_COLOR. We can try to fix this.

    Do you think it's still appropriate to render terminal prompts in NO_COLOR mode? We can disable all color-related ANSI sequences, but there might be other escape sequences involved in these prompts, such as ones for redrawing parts of the screen.

    The other alternative would be to disable prompts entirely in NO_COLOR mode and rely on all information being supplied via flags.

  3. added
    more-info-needed
    on Aug 5, 2020
  4. danshearer commented on Aug 5, 2020

    @danshearer
    ContributorAuthor

    I think there are two main cases to consider, automation and accessibility. There are obvious subcases as well for example automation by means of scraping the accessible output, but the two cases cover the technical point as far as I can see.

    1. Automation. Just like you are doing for gh auth login, it is important to be able to specify everything via commandline parameters. I notice for example in pr_create.go that you don't call titleBodySurvey() until you have checked !isWeb && !autofill && interactive , which suggests you can relatively easily make sure the non-interactive mode fills in up to 100% of parameters from the commandline. (In addition it would be also be possible to call Survey to fill in those parameters that have not been supplied on the commandline but that makes the logic more complicated because you can't just test for interactivity in a boolean way.)

    2. Accessibility. There are many highly accessible utilities that have user interaction, and many of them use libreadline. libreadline is more boring than Survey. A library that doesn't respect NO_COLOR is a library that has given no thought to accessibility, and that is a problem no matter how exciting it can make the output.

    For your encouragement, if you do enable 100% of parameters to be optionally passed by commandline, and if you implement this in a general manner so that help can automatically be generated by recursively visiting for every parameter supported, then you have created something new. Because a version of "gh help" that recursively lists all parameters is a map to github that other applications can build on to do things you haven't thought of yet.

    In summary, I think the problem is with Survey not the use of Survey.

  5. danshearer commented on Aug 5, 2020

    @danshearer
    ContributorAuthor

    I said above

    A library that doesn't respect NO_COLOR is a library that has given no thought to accessibility

    but I think Survey is worse than that. It doesn't seem to consider anything about the terminal at all, for example, export TERM=vt52 makes no difference to gh's behaviour.

    On the other hand, you can see from the discussion of colour in Ncurses at https://invisible-island.net/ncurses/ncurses.faq.html that terminal color is quite complicated and library authors should not pretend it doesn't exist.

  6. mislav commented on Aug 5, 2020

    @mislav
    Contributor

    and if you implement this in a general manner so that help can automatically be generated by recursively visiting for every parameter supported, then you have created something new.

    Thank you! Would you please elaborate on how you imagined this help system to work, or with an example? We're looking how to improve our help output this month, so any feedback would be great.

    Re: accessibility: we definitely aim to provide flags for any inputs that are otherwise prompted for. In fact, that should already be the experience with the latest released version of gh. GitHub CLI should be always accessible in non-interactive mode since we're aware that Survey right now is not accessible when it comes to selecting an option from a list, and for the reasons with terminal detection/support that you already pointed out.

  7. danshearer commented on Aug 5, 2020

    @danshearer
    ContributorAuthor

    Re: accessibility: we definitely aim to provide flags for any inputs that are otherwise prompted for.

    I was also suggesting the opposite: that you prompt for any inputs that have not been specified on the commandline.

    This leads to better results for the end user. For example if I have a script that can set up 3 parameters because it has that knowledge, and just prompt for a 4th from the user, that will reduce errors and frustration. Often there is a situation where partial automation is possible.

  8. danshearer commented on Aug 5, 2020

    @danshearer
    ContributorAuthor

    Would you please elaborate on how you imagined this help system to work, or with an example? We're looking how to improve our help output this month, so any feedback would be great.

    Right now gh has a manual help system because I have to specify both the command and the subcommand:

    gh <command> <subcommand> --help
    

    In fact, gh modules collectively have the knowledge to supply both command and subcommand and could make it available:

    gh <command> --help-recursive
    

    would list all of the subcommands and attributes of these subcommands, and any sub-subcommands that may exist one day.

    gh --help-recursive
    

    would list every single command and parameter.

    Since cli's whole purpose is to be a commandline, then I think this feature should be an important part of testing, and it lends itself to unit tests. When developing a new command, we would first start by writing the help function.

    Finally, cli is entirely based around a parse tree, so I think the only way to do this in a fully machine-readable/automatable manner would be to have these commands:

    gh --help-recursive --xml
    gh <command> --help-recursive --xml
    gh <command> <subcommand> --xml
    

    And this is how gh can futureproof itself. You will have designed an interface to github that is self-documenting and which maps both to human-usable commandline parameters but also machine-readable commandline parameters, and with a little care, what is effectively a machine-readable programmable API specification.

    It is quite likely that the current Go code for cli won't be in use five years from now (look at Hub - it is deprecated already even though it has more functionality than gh.) But if you get this new functional description for github right it will be maintained and in use for many years to come, probably decades.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmore-info-needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions