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

CLI: a splash of colour #3096

Merged
merged 12 commits into from
Jun 27, 2019
Merged

Conversation

oliver-sanders
Copy link
Member

@oliver-sanders oliver-sanders commented Apr 9, 2019

Add colour support to the cli_function wrapper.

  • Use the GNU-like colour argument for all Cylc sub-commands:
    • i.e. --color=(auto|always|never)
    • Default to auto which will use colour if displayed in a terminal.
  • Use the ansimarkup library for easy colour control:
    • An xml-like pre-processor with basic ANSI style and 8-bit coluor support.
    • e.g. <red>Error</red>.
  • Make important information prominent and unimportant information ambient.
    • CRITICAL - bold & red
    • ERROR - red
    • WARNING - yellow
    • DEBUG - grey
    • Success messages - green
    • Everything else - black
  • Improve logger output when viewed from the terminal (log/suite/log file not effected).
    • Log entries formatted to width of terminal.
    • Critical, error and warning levels coloured.
  • Colorise log/suite/log when viewed through cylc cat-log
  • Convert some sys.exit to raise CylcError

Note: The cli_function wrapper may change with #2972, colour support is somewhat orthogonal to this.

Example

Screenshot from 2019-06-20 13-30-11

@oliver-sanders oliver-sanders self-assigned this Apr 9, 2019
@oliver-sanders oliver-sanders added this to the cylc-8.0.0 milestone Apr 9, 2019
@hjoliver
Copy link
Member

Some general comments first:

I definitely like colour output for the CLI

Colorama docs say: "ANSI escape character sequences have long been used to produce colored terminal text and cursor positioning on Unix and Macs. Colorama makes this work on Windows, too, by wrapping stdout, stripping ANSI sequences it finds (which would appear as gobbledygook in the output), and converting them into the appropriate win32 calls to modify the state of the terminal. On other platforms, Colorama does nothing."

i.e. "[on Linux] Colorama does nothing", and its main purpose is to translate ANSI color control codes to the MS Windows API (which we don't support).

Presumably in spite of the "it does nothing [on Linux]" statement, it is nicer to use than raw ANSI control codes.

There are high level libs built ontop of colorama including my fave ansimarkup.

Should we use ansimarkup then??

@cylc cylc deleted a comment May 15, 2019
@oliver-sanders
Copy link
Member Author

No objections so I've moved this along:

  • Using ansimarkup to simplify output e.g. <red>red text</red>
  • Pass the option parser to cli_function which populates the arguments of its decorated function

Colour support so far:

  • cylc broadcast
  • cylc validate
  • cylc show

If no-one screams I'll complete the conversion, rename cli_function2 to cli_function and open to review.

@kinow I'm guessing you're not going to like my wrapping of the CLI methods as the wrapper populates the arguments. Happy to change, open to suggestions, trying not to write any solution into argparse.

@cylc cylc deleted a comment May 15, 2019
@oliver-sanders oliver-sanders modified the milestones: cylc-8.0.0, cylc-8.0a2 Jun 17, 2019
@oliver-sanders oliver-sanders marked this pull request as ready for review June 20, 2019 12:20
@cylc cylc deleted a comment Jun 20, 2019
@oliver-sanders oliver-sanders modified the milestones: cylc-8.0a2, cylc-8.0a1 Jun 20, 2019
@cylc cylc deleted a comment Jun 20, 2019
@kinow
Copy link
Member

kinow commented Jun 20, 2019

Tested with a running suite, then validate and show, and show got some colours (validate was green, same colour as my terminal background, so maybe there was some colouring, but I couldn't notice).

Using ansimarkup to simplify output e.g. red text

Does it add/help a lot? Last commit in 2018, and few contributors - which could be fine, as the tool is simple, it could be feature-complete and only fix bugs (which it doesn't have any at the moment in github). But if it does add or simplify the code, and you think it's stable to be used in Cylc, all good 👍

@kinow I'm guessing you're not going to like my wrapping of the CLI methods as the wrapper populates the arguments. Happy to change, open to suggestions, trying not to write any solution into argparse.

No suggestion. I have never used anything like this before, so it looks quite alien for me, but not incorrect. I think it is OK to be added now and we can think in alternatives later if we find issues with the current approach, or if there are simpler alternatives.

(not reviewing as it's marked as discussion, so I think others will want to have a look and give their opinion too before we jump to reviewing/merging?)

@oliver-sanders oliver-sanders changed the title [discussion] CLI: a splash of colour CLI: a splash of colour Jun 20, 2019
@oliver-sanders
Copy link
Member Author

validate was green, same colour as my terminal background

You have a green terminal background!

Not too sure what can be done about this one, it might be possible to detect the terminal background ANSI code, then pair the corresponding foreground code with a white background.

What do you see if you see with tools like diff?

ansimarkup - Does it add/help a lot?

It simplifies things somewhat making code more readable (cleaner syntax, no string formatting required), it also adds 8-bit colour support (where the terminal supports it) as used to turn the DEBUG messages grey (there is no grey ANSI code).

I think ansimarkup suffers from "being too simple" so it's not active as there aren't really any important changes to make.

looks quite alien for me, but not incorrect. I think it is OK

I'm not overjoyed by it as it causes linters to complain, but it's a perfectly valid Python pattern. Happy to change later for a nicer approach if we come up with one.

@kinow
Copy link
Member

kinow commented Jun 20, 2019

Oh sorry, actually green text color! Hahaa, would be pretty hard on my eyes a green background haha

@oliver-sanders
Copy link
Member Author

oliver-sanders commented Jun 20, 2019

Flaky tests/execution-time-limit/00-background.t keeps failing but all else passes.
All tests passing.

@wxtim wxtim self-requested a review June 25, 2019 11:00
Copy link
Member

@wxtim wxtim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Sanity check code
  • Try it out on desktop
    • With --color=[always|auto|never]
    • With my theme and a corner case "nasty" theme that I keep hanging around for this sort of thing. It looks no worse than the theme does anyway.
    • Used a color blindness simulator on the output. It's not as much of an improvement on the uncolored version, but it's not a degradation. :)

bin/cylc-cat-log Outdated Show resolved Hide resolved
@cylc cylc deleted a comment Jun 25, 2019
@hjoliver
Copy link
Member

Codacy failure (2 new issues) because Pylint evidently doesn't understand when decorators alter a function signature:

Screenshot from 2019-06-25 16-58-47

Which is annoying.

cylc/flow/scheduler_cli.py Outdated Show resolved Hide resolved
cylc/flow/scheduler_cli.py Outdated Show resolved Hide resolved
@hjoliver
Copy link
Member

Otherwise LGTM (not that the codacy problem is your fault; Pylint is just deficient).

@cylc cylc deleted a comment Jun 26, 2019
@hjoliver
Copy link
Member

Spurious test battery failure on Travis CI.

@hjoliver hjoliver merged commit 4cfd92b into cylc:master Jun 27, 2019
@oliver-sanders
Copy link
Member Author

🌈

@oliver-sanders oliver-sanders deleted the behold-the-ansi-rainbow branch June 27, 2019 10:34
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

Successfully merging this pull request may close these issues.

5 participants