jmsv / ety-python

A Python module to discover the etymology of words
http://ety-python.rtfd.io
MIT License
144 stars 18 forks source link

CLI option to disable ANSI formatting #31

Closed jmsv closed 6 years ago

jmsv commented 6 years ago

PR #29 added bold formatting on input words:

screenshot from 2018-06-13 09-21-30

This is cool :sunglasses: but not always desired, for example when piping to a file:

screenshot from 2018-06-13 09-53-26

Flag to disable ANSI could be -p (--plaintext), e.g.

parser.add_argument("-p", "--plaintext",
                    help="output plaintext, disabling ANSI formatting",
                    action="store_true")

ANSI codes could be replaced with a library such as kennethreitz/crayons, which supports disabling colours etc. without too much extra code:

if args.plaintext:
    crayons.disable()
alxwrd commented 6 years ago

I'd suggest timofurrer/colorful. It seems to have better windows support.

the difference between the packages crayons and colorful in a windows environment

Also, I think both crayons and colorful disable ANSI when piping.

$ python -c "import colorful;print(colorful.red('hello'))" > test.txt & cat test.txt
hello
$ python -c "import colorful;print(colorful.red('hello'))" | cat
hello
alxwrd commented 6 years ago

I think --plain could still be useful though, maybe it could turn off the bullet points?

parker57 commented 6 years ago

Colorful looks cool Do you think it would be a good idea to assign each language a colour/style?

jmsv commented 6 years ago

Probably not, too many languages and not enough style combos

Yeah colorful looks good

--plain could make origin lists use - instead of bullet points maybe

jmsv commented 6 years ago

ANSI replaced with colorful in 583ca75ebc1c388d87b86dc62260af401a66e840