mirror of
https://github.com/kennethreitz/clint.git
synced 2026-06-05 23:00:18 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 57955b9156 | |||
| f1ab574413 | |||
| 2aff70618c | |||
| 4b7688b220 | |||
| 03731d6ef2 | |||
| 8a2aed6c32 | |||
| 98cab56e97 |
@@ -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)
|
||||
|
||||
@@ -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
@@ -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'
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user