Giter VIP home page Giter VIP logo

colr's People

Contributors

cjwelborn avatar jayvdb avatar sebleier 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

Watchers

 avatar  avatar  avatar  avatar  avatar

colr's Issues

Custom method, __colr__, not documented.

Colr(obj), with no args, and where obj has a __colr__() method that returns a Colr object, will return obj.__colr__().

This is the Colr version of __str__ or __bytes__.

If you need your classes to colorize themselves a certain way by default, you can write a custom __colr__ method and Colr(mything) will recognize it. The quickest example is this:

from colr import Colr

class ErrorTag(object):

    def __str__(self):
        """ Stringify this thing. """
        return 'Error'
    
    def __colr__(self):
    """ Colrize this thing. """
        # must return a Colr instance.
        return Colr('Error', 'red', style='bright')

o = ErrorTag()
# prints a bright red 'Error'.
print(Colr(o))

None of this is documented, except here in this issue. It needs to be in the README.

doesnt work

text is completly normal, using multiple of the example methods

doesnt work 2: electric boogalo

#4
windows 10 and debian linux

python 3.7

putty through ssh and whatever IDEa is.

256 color, true colors and hex examples in the readme.

Two failures on openSUSE

With the patch for #7 applied against the current release, I get the following two errors.

Maybe they have been fixed on master. I'll try that next..

[   67s] =================================== FAILURES ===================================
[   67s] ________________________ ColrToolTests.test_list_codes _________________________
[   67s] 
[   67s] self = <test.test_colr_tool.ColrToolTests testMethod=test_list_codes>
[   67s] 
[   67s]     def test_list_codes(self):
[   67s]         """ colr tool should list escape codes with --listcodes. """
[   67s]         cases = {
[   67s]             s: str(Colr('test', s))
[   67s]             for s in ('red', 'blue', 'green', 'white')
[   67s]         }
[   67s]         for name, s in cases.items():
[   67s]             argd = {'TEXT': s, '--listcodes': True}
[   67s]             self.assertMainIn(
[   67s]                 argd,
[   67s]                 stdout=name,
[   67s] >               msg='main() with --listcodes did not recognize an escape code.',
[   67s]             )
[   67s] 
[   67s] test/test_colr_tool.py:334: 
[   67s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   67s] test/testing_tools.py:694: in assertMainIn
[   67s]     msg='main() returned a non-zero exit status.',
[   67s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   67s] 
[   67s] self = <test.test_colr_tool.ColrToolTests testMethod=test_list_codes>, a = 1
[   67s] b = 0, msg = 'main() returned a non-zero exit status.'
[   67s] 
[   67s]     def assertEqual(self, a, b, msg=None):
[   67s]         if a == b:
[   67s]             return None
[   67s] >       raise self.failureException(_equality_msg('!=', a, b, msg=msg))
[   67s] E       AssertionError: 
[   67s] E         1 !=
[   67s] E         0
[   67s] E       
[   67s] E       main() returned a non-zero exit status.
[   67s] 
[   67s] test/testing_tools.py:417: AssertionError
[   67s] __________________________ ColrToolTests.test_styles ___________________________
[   67s] 
[   67s] self = <test.test_colr_tool.ColrToolTests testMethod=test_styles>
[   67s] 
[   67s]     def test_styles(self):
[   67s]         """ colr tool should recognize styles. """
[   67s]         argd = {'TEXT': 'Hello World', 'FORE': '235', 'STYLE': 'normal'}
[   67s]         for _ in range(10):
[   67s]             argd['STYLE'] = r.choice(self.valid_style_vals)
[   67s]             self.assertMain(argd, msg='main() failed with valid style arg.')
[   67s]         # Invalid style values should raise a InvalidStyle.
[   67s]         badargsets = (
[   67s]             {'STYLE': 'dimmer'},
[   67s]             {'STYLE': 'x'},
[   67s]         )
[   67s]         for argset in badargsets:
[   67s]             argd.update(argset)
[   67s]             with self.assertRaises(InvalidStyle):
[   67s] >               self.run_main_test(argd, should_fail=True)
[   67s] E               AssertionError: InvalidStyle not raised
[   67s] 
[   67s] test/test_colr_tool.py:427: AssertionError

Python 3.7 support

Tests fail on Python 3.7 : RuntimeError: generator raised StopIteration

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.