Merge pull request #15 from grahamu/normal

Backport improvements/fixes from pipenv
This commit is contained in:
2018-09-10 04:41:35 -04:00
committed by GitHub
3 changed files with 23 additions and 7 deletions
+2 -1
View File
@@ -19,7 +19,7 @@ Crayons: Text UI colors for Python.
This module is really simple, it gives you colored strings for terminal
usage. Included colors are ``red``, ``green``, ``yellow``, ``blue``, ``black``, ``magenta``, ``cyan``, and ``white`` ( as well as ``clean`` and ``disable``).
usage. Included colors are ``red``, ``green``, ``yellow``, ``blue``, ``black``, ``magenta``, ``cyan``, ``white``, and ``normal`` ( as well as ``clean`` and ``disable``).
**Crayons** is nice because it automatically wraps a given string in both the foreground color, as well as returning to the original state after the string is complete. Most terminal color libraries make you manage this yourself.
@@ -33,6 +33,7 @@ Features
--------
- If you call ``disable()``, all future calls to colors will be ignored.
- If you call ``normal()``, color is reset to default foreground color
- If the current process is not in a TTY (e.g. being piped), no colors will be displayed.
- Length of ColoredStrings can be properly calculated.
- Powered by colorama.
+20 -5
View File
@@ -12,13 +12,13 @@ import os
import re
import sys
PY3 = sys.version_info[0] >= 3
import colorama
PY3 = sys.version_info[0] >= 3
__all__ = (
'red', 'green', 'yellow', 'blue',
'black', 'magenta', 'cyan', 'white',
'black', 'magenta', 'cyan', 'white', 'normal',
'clean', 'disable'
)
@@ -67,7 +67,11 @@ class ColoredString(object):
@property
def color_str(self):
style = 'BRIGHT' if self.bold else 'NORMAL'
c = '%s%s%s%s%s' % (getattr(colorama.Fore, self.color), getattr(colorama.Style, style), self.s, colorama.Fore.RESET, getattr(colorama.Style, 'NORMAL'))
c = '%s%s%s%s%s' % (getattr(colorama.Fore, self.color),
getattr(colorama.Style, style),
self.s,
colorama.Fore.RESET,
getattr(colorama.Style, 'NORMAL'))
if self.always_color:
return c
@@ -76,7 +80,6 @@ class ColoredString(object):
else:
return self.s
def __len__(self):
return len(self.s)
@@ -121,30 +124,42 @@ def clean(s):
return txt
def normal(string, always=False, bold=False):
return ColoredString('RESET', string, always_color=always, bold=bold)
def black(string, always=False, bold=False):
return ColoredString('BLACK', string, always_color=always, bold=bold)
def red(string, always=False, bold=False):
return ColoredString('RED', string, always_color=always, bold=bold)
def green(string, always=False, bold=False):
return ColoredString('GREEN', string, always_color=always, bold=bold)
def yellow(string, always=False, bold=False):
return ColoredString('YELLOW', string, always_color=always, bold=bold)
def blue(string, always=False, bold=False):
return ColoredString('BLUE', string, always_color=always, bold=bold)
def magenta(string, always=False, bold=False):
return ColoredString('MAGENTA', string, always_color=always, bold=bold)
def cyan(string, always=False, bold=False):
return ColoredString('CYAN', string, always_color=always, bold=bold)
def white(string, always=False, bold=False):
return ColoredString('WHITE', string, always_color=always, bold=bold)
def disable():
"""Disables colors."""
global DISABLE_COLOR
+1 -1
View File
@@ -30,7 +30,7 @@ required = [
setup(
name='crayons',
version='0.1.2',
version='0.1.3',
description='TextUI colors for Python.',
long_description=long_description,
author='Kenneth Reitz',