Skip to content

Conversation

@exhuma
Copy link

@exhuma exhuma commented Sep 9, 2019

This PR adds a very simple implementation for ANSI color output.

I am aware about #101 and that there are plans to "vendorise" something like colorama. This PR serves mainly to get the ball rolling and to scratch my own itch.

I am willing to incorporate colorama instead of using hand-crafted code.

However, I am unaware what is meant by "vendorising" code. Does that mean adding it as a simple dependency? Or rather copying the code into invoke. In the latter case, should I simply copy the code into invoke/vendor?

Let me know what option you'd prefer and I'll get to it.

A "sticky" color is a color which remains the same for the same "key".
It is intended to be used to colorise host-names
@exhuma
Copy link
Author

exhuma commented Sep 9, 2019

Note that this also tries to reproduce the behaviour from fabric 1 (same function names, and same args as the clr module). However, the environmen variable FABRIC_DISABLE_COLORS has been renamed to INVOKE_DISABLE_COLORS.

One could argue to add a code into fabric along these lines:

import invoke.termcolor
import os
invoke.termcolor.INVOKE_DISABLE_COLORS = os.getenv(
    'FABRIC_DISABLE_COLORS', False)

... although that looks a bit hacky, but would reproduce fabric-1 behaviour completely. Thoughts?

@exhuma
Copy link
Author

exhuma commented Sep 9, 2019

Sorry for the commit-spam... I am having issues with my dev environment and rely on travis.

@exhuma
Copy link
Author

exhuma commented Sep 9, 2019

There seems to be something strange going on with sys.stderr and sys.stdout. Maybe related to the @trap decorator from pytest-relaxed?

For the time being I will split the test Runner_.command_echoing.uses_ansi_bold as it's behaviour is really unpredictable. It works different in Python 2 and 3 as it seems and I don't really know why. Also, on my environment it behaves differently than on travis. Splitting it for Python 2/3 should make the tests pass... I hope 🤞

@exhuma
Copy link
Author

exhuma commented Sep 9, 2019

Okay... should be good now... all checks are passing at least.

I cleaned up the intermediary commits. Most of which are caused because I was unable to run the tests locally so I was dependent on pushing to make it run in Travis.

@exhuma
Copy link
Author

exhuma commented Sep 9, 2019

oh no... 😆

@exhuma exhuma force-pushed the color-output branch 2 times, most recently from 2ca8c00 to f06c707 Compare September 9, 2019 15:29
@exhuma
Copy link
Author

exhuma commented Sep 9, 2019

Done.

@nickatnight
Copy link

When can we merge this in?

@ofek
Copy link

ofek commented Apr 19, 2020

@bitprophet Hello again! Are there still plans to support colored output?

@bitprophet bitprophet added this to the p2 milestone Nov 6, 2020
@bitprophet
Copy link
Member

Thanks for this! Haven't dig into it yet but to answer the question about vendoring, it means adding something to the vendor folder like the rest of the stuff in there. There's actually an invoke task somewhere for pulling a pip installable library into that tree, tho I haven't used it in ages.

When I have time to review I'll make the judgement call re: whether it is worth replacing custom color codes with a lib or not.

@exhuma
Copy link
Author

exhuma commented Nov 6, 2020

Sure. No worries. Take your time. I'm not in a hurry. If you need any feedback, don't hesitate to give me a nudge.

I also see that there are conflicts on the branch. If I don't forget about this I'll try to remove those to make merging this a bit less painful 😉

@neozenith
Copy link

Since the inception of this PR there is another library that is heavily supporting colorising terminal text across the multitudes of terminals:
https://github.com/Textualize/rich

Even pip itself vendored it:
pypa/pip#10423

This might be a good feature to target in the v2.0 of invoke once Python2 support is dropped and all the work on CircleCI is tidied up as well as some outstanding bugs for python 3.10
https://bitprophet.org/projects/#roadmap

The colorised output could be a good visual indicator of the major change to invoke that it aesthetically got a coat of paint.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants