| 1 | # This file is part of the "Cleverbox" program. |
|---|
| 2 | # |
|---|
| 3 | # Cleverbox is free software: you can redistribute it and/or modify |
|---|
| 4 | # it under the terms of the GNU General Public License as published by |
|---|
| 5 | # the Free Software Foundation, either version 3 of the License, or |
|---|
| 6 | # (at your option) any later version. |
|---|
| 7 | # |
|---|
| 8 | # Cleverbox is distributed in the hope that it will be useful, |
|---|
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | # GNU General Public License for more details. |
|---|
| 12 | # |
|---|
| 13 | # You should have received a copy of the GNU General Public License |
|---|
| 14 | # along with Cleverbox. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 15 | # |
|---|
| 16 | # Copyright 2008, Tristan Rivoallan |
|---|
| 17 | |
|---|
| 18 | import sys |
|---|
| 19 | from cleverbox.utils import termcolors |
|---|
| 20 | |
|---|
| 21 | # Set up the terminal color scheme. |
|---|
| 22 | class dummy: pass |
|---|
| 23 | style = dummy() |
|---|
| 24 | style.ERROR = termcolors.make_style(fg='red', opts=('bold',)) |
|---|
| 25 | style.WARNING = termcolors.make_style(fg='yellow', opts=('bold',)) |
|---|
| 26 | style.SUCCESS = termcolors.make_style(fg='green', opts=('bold',)) |
|---|
| 27 | style.H1 = termcolors.make_style(fg='white', opts=('bold', 'underline')) |
|---|
| 28 | style.ENABLED = termcolors.make_style(fg='green', opts=('bold',)) |
|---|
| 29 | style.DISABLED = termcolors.make_style(fg='red') |
|---|
| 30 | |
|---|
| 31 | style.SUCCESSNORESET = termcolors.make_style(fg='green', opts=('bold', 'noreset',)) |
|---|
| 32 | style.RESET = termcolors.make_style() |
|---|
| 33 | del dummy |
|---|
| 34 | |
|---|
| 35 | def disable_termcolors(): |
|---|
| 36 | class dummy: |
|---|
| 37 | def __getattr__(self, attr): |
|---|
| 38 | return lambda x: x |
|---|
| 39 | global style |
|---|
| 40 | style = dummy() |
|---|
| 41 | |
|---|
| 42 | # Disable terminal coloring on Windows, Pocket PC, or if somebody's piping the output. |
|---|
| 43 | if sys.platform == 'win32' or sys.platform == 'Pocket PC' or not sys.stdout.isatty(): |
|---|
| 44 | disable_termcolors() |
|---|