-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Color #213
Color #213
Conversation
…thods, full property name support, properties now dynamic, some support for setting .use_color
… object and works like one.
… use ColorfulApplication.
Conflicts: docs/_news.rst docs/local_commands.rst
…them. Color API docstrings.
…uff) is now color[stuff]. Docs update next.
…on, camelcase names
…hout metaclasses.
Conflicts: .travis.yml CHANGELOG.rst plumbum/machines/base.py tests/test_local.py
… original factories.
…ibrary, None or '' means no color.
Conflicts: CHANGELOG.rst
Conflicts: docs/_cheatsheet.rst
hey, i merged it in so it would stop "rotting" on side branches, but i'd love if you could cleanup (or explain the reason for) the following:
here's a snippet from your example: with colors:
print('It is always a good idea to be in a context manager, to avoid being',
'left with a colorsed terminal if there is an exception!')
print(colors.bold + "This is bold and exciting!" - colors.bold)
print(colors.bg.cyan + "This is on a cyan background." + colors.reset)
print(colors.fg[42] + "If your terminal supports 256 colorss, this is colorsful!" + colors.reset)
print()
for c in colors:
print(c + u'\u2588', end='')
colors.reset()
print()
print('Colors can be reset ' + colors.underline['Too!'])
for c in colors[:16]:
print(c["This is in colors!"])
here's a simplified, cleaner version that i have in mind: from plumbum.colors import fg, bg, bold, underline
# or ``from plumbum.colors.fg import red`` if that's all you want
with bg.blue:
print("hello ", fg.red["world"], " bingo was his ", underline["name-o"])
yell = fg.red | underline | bold
print(yell["SHAKIRA SHKIRA"])
print("and ", fg.red["it can ", bold["be nested ", underline["just as well"]]]) thanks for your hard work, man, i really appreciate it. but here i think you should let usability guide you (i.e., "the lean startup" approach) and not "think in advance" what would be cool (to be able) to do. on the other hand, i think the library is missing some built-in semantic combinators such as |
I tried using my library with git-all and a few demo scripts, that's where some of the ideas came from. Should we combine colors with | or &? You've used both in previous comments. The names are almost the "official" names, just with some extra text added to make each unique. To me, I'll be adding the warn, etc, and looking at moving hex into rgb, and working on tightening it up. |
By the way, thanks for taking the time to review it and add it! And let me know if you still want changes, I'll be working on it off and on for the next week or so. |
I'm standardising on rgb now works as mentioned, and I'm thinking about a way to add the warn, etc. This means that you can do the following: from plumbum.colors import fg, bg, bold, underline
with bg.blue:
print("hello ", fg.red | "world", " bingo was his ", underline | "name-o")
yell = fg.red & underline & bold
print(yell["SHAKIRA SHKIRA"])
print( fg.red & underline & bold | "SHAKIRA SHKIRA")
print("and ", fg.red[ "it can " + bold["be nested " + underline["just as well"]]]) |
This is the
plumbum.colors
module I've been working on, designed to make adding colors easy and safe. I've prepared a post about it here, this post has been updated, and there is extensive documentation in the addition. As a quick example:You can access the ANSI 16 basic colors, 256 colors (with names), and full 24 bit color - and can convert between them (This is the only library I know of that can do that). You can easily subclass Style to create more representations (HTMLStyle is included to make documentation easier to write). Styles are smart and know how to combine to create the most effective ANSI sequence. Styles correctly handle being turned off, and don't turn on for non-posix tty systems (can be forced, though). Basic colors can be used on Windows with a tool (like colorama) to convert ANSI codes. (See examples).
Docs (with list of color names), API docs, tests, examples included.
Closes #128.
Replacement for #206, as this is now a branch in the main repo to make it easier to test and github doesn't allow this to be changed after the fact. I'll close that one in favor of this one.