|
Revision 8239, 1.3 kB
(checked in by jacob, 4 months ago)
|
Fixed #8100: Jython, apparently, is now a TTY.
|
- Property svn:eol-style set to
native
|
| Line | |
|---|
| 1 |
""" |
|---|
| 2 |
Sets up the terminal color scheme. |
|---|
| 3 |
""" |
|---|
| 4 |
|
|---|
| 5 |
import sys |
|---|
| 6 |
|
|---|
| 7 |
from django.utils import termcolors |
|---|
| 8 |
|
|---|
| 9 |
def supports_color(): |
|---|
| 10 |
""" |
|---|
| 11 |
Returns True if the running system's terminal supports color, and False |
|---|
| 12 |
otherwise. |
|---|
| 13 |
""" |
|---|
| 14 |
unsupported_platform = (sys.platform in ('win32', 'Pocket PC')) |
|---|
| 15 |
# isatty is not always implemented, #6223. |
|---|
| 16 |
is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty() |
|---|
| 17 |
if unsupported_platform or not is_a_tty: |
|---|
| 18 |
return False |
|---|
| 19 |
return True |
|---|
| 20 |
|
|---|
| 21 |
def color_style(): |
|---|
| 22 |
"""Returns a Style object with the Django color scheme.""" |
|---|
| 23 |
if not supports_color(): |
|---|
| 24 |
return no_style() |
|---|
| 25 |
class dummy: pass |
|---|
| 26 |
style = dummy() |
|---|
| 27 |
style.ERROR = termcolors.make_style(fg='red', opts=('bold',)) |
|---|
| 28 |
style.ERROR_OUTPUT = termcolors.make_style(fg='red', opts=('bold',)) |
|---|
| 29 |
style.NOTICE = termcolors.make_style(fg='red') |
|---|
| 30 |
style.SQL_FIELD = termcolors.make_style(fg='green', opts=('bold',)) |
|---|
| 31 |
style.SQL_COLTYPE = termcolors.make_style(fg='green') |
|---|
| 32 |
style.SQL_KEYWORD = termcolors.make_style(fg='yellow') |
|---|
| 33 |
style.SQL_TABLE = termcolors.make_style(opts=('bold',)) |
|---|
| 34 |
return style |
|---|
| 35 |
|
|---|
| 36 |
def no_style(): |
|---|
| 37 |
"""Returns a Style object that has no colors.""" |
|---|
| 38 |
class dummy: |
|---|
| 39 |
def __getattr__(self, attr): |
|---|
| 40 |
return lambda x: x |
|---|
| 41 |
return dummy() |
|---|