7 Commits

Author SHA1 Message Date
Jason Piper 57955b9156 Pushing 0.3.7 to pypi 2014-04-17 16:05:53 +01:00
Jason Piper f1ab574413 Merge pull request #106 from joemiller/features/force_color
if env var CLINT_FORCE_COLOR is set, always output color codes
2014-03-23 10:36:55 +00:00
Jason Piper 2aff70618c Merge pull request #111 from jezdez/fix-yn
Fixed the prompt.yn function to work on Python3.
2014-03-23 10:36:04 +00:00
Jason Piper 4b7688b220 Merge pull request #110 from infamy/master
Fixed bold issue
2014-03-23 10:35:03 +00:00
Jannis Leidel 03731d6ef2 Fixed the prompt.yn function to work on Python3. 2014-03-23 11:31:59 +01:00
infamy 8a2aed6c32 Fixed bold issue
Bold would get "stuck" on in powershell/cmd prompt.
2014-03-19 22:19:51 -07:00
joe miller 98cab56e97 if env var CLINT_FORCE_COLOR is set, always output color codes even if stdout is not a tty 2014-03-14 16:58:06 +00:00
6 changed files with 37 additions and 10 deletions
+8
View File
@@ -1,6 +1,14 @@
History
-------
0.3.7
+++++
* Clint now obeys the CLINT_FORCE_COLOR environmental variable
0.3.6
+++++
* Fixed faulty PyPI deployment
0.3.5
+++++
* progress.bar is now a context manager - doesn't require an iterable anymore (thanks to @jric)
+4
View File
@@ -109,6 +109,10 @@ I want to store a configuration file. ::
# Windows: 'C:\\Users\\appuser\\AppData\\Local\\Company\\AppName\\config.ini'
# Linux: '/home/appuser/.config/appname/config.ini'
I want to force color output even if stdout is not a TTY:
$ export CLINT_FORCE_COLOR=1
Installation
------------
+2 -2
View File
@@ -26,8 +26,8 @@ from .pipes import piped_in
__title__ = 'clint'
__version__ = '0.3.5'
__build__ = 0x000305
__version__ = '0.3.7'
__build__ = 0x000307
__author__ = 'Kenneth Reitz'
__license__ = 'ISC'
__copyright__ = 'Copyright 2012 Kenneth Reitz'
+4 -2
View File
@@ -11,6 +11,7 @@ This module provides a simple and elegant wrapper for colorama.
from __future__ import absolute_import
import os
import re
import sys
@@ -37,7 +38,6 @@ else:
DISABLE_COLOR = False
class ColoredString(object):
"""Enhanced string for __len__ operations on Colored output."""
def __init__(self, color, s, always_color=False, bold=False):
@@ -46,6 +46,8 @@ class ColoredString(object):
self.color = color
self.always_color = always_color
self.bold = bold
if os.environ.get('CLINT_FORCE_COLOR'):
self.always_color = True
def __getattr__(self, att):
def func_help(*args, **kwargs):
@@ -65,7 +67,7 @@ class ColoredString(object):
@property
def color_str(self):
style = 'BRIGHT' if self.bold else 'NORMAL'
c = '%s%s%s%s' % (getattr(colorama.Fore, self.color), getattr(colorama.Style, style), self.s, colorama.Fore.RESET)
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
+11 -6
View File
@@ -11,21 +11,26 @@ Module for simple interactive prompts handling
from __future__ import absolute_import, print_function
from re import match, I
try:
raw_input
except NameError:
raw_input = input
def yn(prompt, default='y', batch=False):
# A sanity check against default value
# If not y/n then y is assumed
# If not y/n then y is assumed
if default not in ['y', 'n']:
default = 'y'
# Let's build the prompt
choicebox = '[Y/n]' if default == 'y' else '[y/N]'
prompt = prompt + ' ' + choicebox + ' '
choicebox = '[Y/n]' if default == 'y' else '[y/N]'
prompt = prompt + ' ' + choicebox + ' '
# If input is not a yes/no variant or empty
# keep asking
while True:
# If batch option is True then auto reply
# If batch option is True then auto reply
# with default input
if not batch:
input = raw_input(prompt).strip()
@@ -39,7 +44,7 @@ def yn(prompt, default='y', batch=False):
return True
# Given 'yes' as input if default choice is y
# then return True, False otherwise
# then return True, False otherwise
if match('y(?:es)?', input, I):
return True if default == 'y' else False
+8
View File
@@ -3,6 +3,7 @@
"""Clint Test Suite."""
import os
import unittest
@@ -50,5 +51,12 @@ class ColoredStringTestCase(unittest.TestCase):
from clint.textui import puts
puts(new_str)
def test_clint_force_color_env_var(self):
from clint.textui.colored import ColoredString
os.environ['CLINT_FORCE_COLOR'] = "1"
new_str = ColoredString('RED', 'hello world')
assert new_str.always_color == True
if __name__ == '__main__':
unittest.main()