Coder Social home page Coder Social logo

crayons's Introduction

crayons's People

Contributors

bobotig avatar caizixian avatar duck2 avatar frostming avatar grahamu avatar homebysix avatar kennethreitz avatar masterodin avatar nkantar avatar timofurrer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

crayons's Issues

Does not respect TERM=dumb

Hello,

I'm using pipenv in an Acme win which doesn't recognize ANSI escape sequences and prints garbled output instead of colors. In other words, it is a dumb terminal and it sets TERM=dumb so nobody tries to pass colors to it.

pipenv prints Usage: �[39m�[1mpipenv�[39m�[22m [OPTIONS] COMMAND [ARGS]... which I suppose is actually crayons behavior.

Crayons already seems to support turning colors off, so I will try to make a PR which implements turning colors off on TERM=dumb.

Not for this human… ;)

Hi, I find this syntax rather inhuman (esp. the 3× repetition):

print('{red} white'.format(red=crayons.red('red')))

and would very much prefer:

print('{red}important {foo}{off}normal text {userval}'
      .format(**crayons.palette(userval=1, foo='bar')))

(with the arguments being optional of course). Also, those two variants can live in harmony.

If an `AttributeError` is raised in `ColoredString.color_str`, python will raise a `TypeError` when printing

Hi,

The color_str property is checking if the stdout is a tty by running sys.stdout.isatty().

In our case, a 3rd party populated the sys.stdout with an object that did not implement isatty. Because of this, an AttributeError was thrown when running the code in color_str. Python implicitly caught this and defaulted to getting the value from __getattr__, which is, as you know, a function and indeed not a compatible type for printing.

An implicit fix would be

@property
def color_str(self):
    try:
        return self._color_str()
    except Exception:
        return self.s

def _color_str(self):
    # current existing code

An explicit fix would be

@property
def color_str(self):
    try:
        return self._color_str()
    except AttributeError as e:
        raise MyCustomError("An error was thrown when assembling the colored string: {}".format(e))

def _color_str(self):
    # current existing code

But I will leave it to your judgement to find the best approach.

Thanks for your time.

embedded colored strings unset outer colored string

Situations like this (or here in pipenv):

print(crayons.blue('horses, like {0}, eat grass too'.format(crayons.red('goats'))))

produce the following in Python 3.6.2:
screen shot 2017-08-30 at 15 43 41

To me, the expectation is that embedded colored text would not effect the coloring outside of there, so you'd get the following instead:
screen shot 2017-08-30 at 15 46 03

I spotted this after spawning a virtualenv shell from pipenv :) Notice closing parenthesis:
screen shot 2017-08-30 at 15 38 13

Crayons can't handle padding

Hi,

I recognized that crayons can't deal with string formatted with padding. Examples:

>>> import crayons
>>> print("{:15}".format(crayons.red('NOTE:', bold=True)))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported format string passed to ColoredString.__format__
>>> print("{}".format(crayons.red('NOTE:', bold=True)))
NOTE:

Any ideas?
Regards, Thomas

Add function to just make bold text

Sometimes, it's desirable to have bold text without specifying color (to be consistent with different backgrounds). At the moment, it seems like there isn't any way to do this with crayons, and a crayons.bold function should be easy to add. Another advantage is to allow chaining bold/color calls. For example,

if condition_1:
    msg = crayons.red(msg)
if condition_2:
    msg = crayons.bold(msg)

It should be a very simple function to add, and I'd be happy to make a pull request.

Blue is too dark on the black background

System: Ubuntu 18.04 (LTS)
Terminal: xfce-terminal (default terminal in XFCE)
All fonts and appearance settings kept default

How to reproduce:

import crayons
for c in crayons.COLORS: print(getattr(crayons,c)(c))

Expected result:
blue is readable

Actual result:
blue is hardly readable

I guess this issue is a root cause of pypa/pipenv#1923

crayons from pip is outdated

Thanks for this module. I did pip install crayons and noticed that it does not have the normal() method. Could you push a new version so it includes the latest code?

str.join is broken

import crayons

s1 = "this"
s2 = crayons.red("breaks")
s1.join([s2])

>>> TypeError: sequence item 0: expected str instance, ColoredString found

Padding strings won't work with colored strings.

Hey there, @kennethreitz!

I was hacking around a new cli-tool with some cool colored strings with crayons but I needed to make customization on formatting and ran into this issue.

capture

The second attempt is using colorama's own API and worked as expected. I also tried using string interpolation like %-5s and it didn't work.

Anyways, if point me out to where this issue is happening I'll gladly try to solve this and send a PR.

Thanks for the great work. 🍺

Cheers from Brazil.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.