detecting whether the system supports ansi or not

This commit is contained in:
Gabriel Falcao 2012-09-06 15:53:05 -04:00
parent 0588c94a7b
commit dee810302e
6 changed files with 61 additions and 27 deletions

10
.travis.yml Normal file
View File

@ -0,0 +1,10 @@
language: python
python:
- "2.6"
- "2.7"
# command to install dependencies
install:
- pip install -r requirements.pip
# command to run tests
script: make test

25
Makefile Normal file
View File

@ -0,0 +1,25 @@
all: install_deps test
filename=couleur-`python -c 'import couleur;print couleur.version'`.tar.gz
export PYTHONPATH:= ${PWD}
export FORCE_COULEUR:= true
install_deps:
@pip install -r requirements.pip
test:
@nosetests --verbosity=2
clean:
@printf "Cleaning up files that are already in .gitignore... "
@for pattern in `cat .gitignore`; do rm -rf $$pattern; find . -name "$$pattern" -exec rm -rf {} \;; done
@echo "OK!"
release: clean test publish
@printf "Exporting to $(filename)... "
@tar czf $(filename) couleur setup.py README.md
@echo "DONE!"
publish:
@python setup.py sdist register upload

View File

@ -126,7 +126,8 @@ You will need to install [nose](http://somethingaboutorange.com/mrl/projects/nos
And run:
user@machine:~/Projects$ git clone git://github.com/gabrielfalcao/couleur.git
user@machine:~/Projects$ cd couleur
user@machine:~/Projects/couleur$ nosetests
user@machine:~/Projects$ pip install -r requirements.pip
user@machine:~/Projects/couleur$ make
## nomenclature

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# <Couleur - fancy shell output for python>
# Copyright (C) <2010> Gabriel Falcão <gabriel@nacaolivre.org>
# Copyright (C) <2010-2012> Gabriel Falcão <gabriel@nacaolivre.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
@ -20,7 +20,8 @@ import sys
import uuid
import platform
__version__ = '0.3'
__version__ = '0.4.0'
from StringIO import StringIO
@ -34,10 +35,11 @@ for handle in [sys.stdout, sys.stderr]:
else:
SUPPORTS_ANSI = True
if os.getenv('SURE_NO_COLORS'):
if os.getenv('COULEUR_DISABLE'):
SUPPORTS_ANSI = False
SUPPORTS_ANSI = False
if os.getenv('FORCE_COULEUR'):
SUPPORTS_ANSI = True
def minify(string):
@ -213,20 +215,22 @@ _sep2 = '_and_'
class Shell(object):
def __init__(self, indent=2, linebreak=False, bold=False, disabled=False):
def __init__(self, indent=2, linebreak=False, bold=False,
disabled=not SUPPORTS_ANSI):
self._indentation_factor = indent
self._indent = 0
self._linebreak = linebreak
self._bold = bold
self._in_format = False
self._disabled = disabled
self._backcolors = backcolors()
self._forecolors = forecolors()
self._modifiers = modifiers()
if disabled or not SUPPORTS_ANSI:
if disabled:
self._backcolors = empty()
self._forecolors = empty()
self._modifiers = empty()
else:
self._backcolors = backcolors()
self._forecolors = forecolors()
self._modifiers = modifiers()
def indent(self):
self._indent += self._indentation_factor

4
requirements.pip Normal file
View File

@ -0,0 +1,4 @@
distribute==0.6.27
nose==1.1.2
sure==1.0.6
wsgiref==0.1.2

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# <Couleur - fancy shell output for python>
# Copyright (C) <2010> Gabriel Falcão <gabriel@nacaolivre.org>
# Copyright (C) <2010-2012> Gabriel Falcão <gabriel@nacaolivre.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
@ -16,31 +16,21 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from setuptools import setup
import sys
extra = {}
if sys.version_info >= (3,0):
u = str
extra.update( use_2to3 = True )
else:
u = lambda s: unicode(s, 'utf8')
from couleur import __version__
setup(name='couleur',
version='0.3.1',
description='ANSI terminal tool for python, colored shell and other ' \
'handy fancy features',
author=u('Gabriel Falcão'),
version=__version__,
description=(u'ANSI terminal tool for python, colored shell and other '
'handy fancy features'),
author='Gabriel Falcao',
author_email='gabriel@nacaolivre.org',
url='http://github.com/gabrielfalcao/couleur',
py_modules=['couleur'],
classifiers = [
classifiers=[
'Development Status :: 5 - Production/Stable',
'License :: OSI Approved :: Apache Software License',
"Operating System :: POSIX",
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
],
**extra
)