welbornprod / colr Goto Github PK
View Code? Open in Web Editor NEWEasy terminal colors, with chainable methods.
Home Page: http://pypi.python.org/pypi/Colr/
License: MIT License
Easy terminal colors, with chainable methods.
Home Page: http://pypi.python.org/pypi/Colr/
License: MIT License
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.
This would allow things like:
from colr import ColrControl
print(ColrControl('test', 'red').move_up(1).blue('okay'))
Basically, colors and controls without using Control().text()
.
File "/usr/local/lib/python3.4/dist-packages/Colr-0.8.1-py3.4.egg/colr/base.py", line 476
**kwargs,
^
SyntaxError: invalid syntax
text is completly normal, using multiple of the example methods
Is it possible to remove coloring markup with color?
#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.
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
Tests fail on Python 3.7 : RuntimeError: generator raised StopIteration
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.