Mercurial > libervia-backend
comparison sat/tools/common/ansi.py @ 2624:56f94936df1e
code style reformatting using black
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 27 Jun 2018 20:14:46 +0200 |
parents | 26edcf3a30eb |
children | 003b8b4b56a7 |
comparison
equal
deleted
inserted
replaced
2623:49533de4540b | 2624:56f94936df1e |
---|---|
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 import sys | 20 import sys |
21 | 21 |
22 | |
22 class ANSI(object): | 23 class ANSI(object): |
23 | 24 |
24 ## ANSI escape sequences ## | 25 ## ANSI escape sequences ## |
25 RESET = '\033[0m' | 26 RESET = "\033[0m" |
26 NORMAL_WEIGHT = '\033[22m' | 27 NORMAL_WEIGHT = "\033[22m" |
27 FG_BLACK, FG_RED, FG_GREEN, FG_YELLOW, FG_BLUE, FG_MAGENTA, FG_CYAN, FG_WHITE = ('\033[3%dm' % nb for nb in xrange(8)) | 28 FG_BLACK, FG_RED, FG_GREEN, FG_YELLOW, FG_BLUE, FG_MAGENTA, FG_CYAN, FG_WHITE = ( |
28 BOLD = '\033[1m' | 29 "\033[3%dm" % nb for nb in xrange(8) |
29 BLINK = '\033[5m' | 30 ) |
30 BLINK_OFF = '\033[25m' | 31 BOLD = "\033[1m" |
32 BLINK = "\033[5m" | |
33 BLINK_OFF = "\033[25m" | |
31 | 34 |
32 @classmethod | 35 @classmethod |
33 def color(cls, *args): | 36 def color(cls, *args): |
34 """output text using ANSI codes | 37 """output text using ANSI codes |
35 | 38 |
37 """ | 40 """ |
38 # XXX: we expect to have at least one argument | 41 # XXX: we expect to have at least one argument |
39 if args[-1] != cls.RESET: | 42 if args[-1] != cls.RESET: |
40 args = list(args) | 43 args = list(args) |
41 args.append(cls.RESET) | 44 args.append(cls.RESET) |
42 return u''.join(args) | 45 return u"".join(args) |
43 | 46 |
44 | 47 |
45 try: | 48 try: |
46 tty = sys.stdout.isatty() | 49 tty = sys.stdout.isatty() |
47 except (AttributeError, TypeError): # FIXME: TypeError is here for Pyjamas, need to be removed | 50 except ( |
51 AttributeError, | |
52 TypeError, | |
53 ): # FIXME: TypeError is here for Pyjamas, need to be removed | |
48 tty = False | 54 tty = False |
49 if not tty: | 55 if not tty: |
50 # we don't want ANSI escape codes if we are not outputing to a tty! | 56 # we don't want ANSI escape codes if we are not outputing to a tty! |
51 for attr in dir(ANSI): | 57 for attr in dir(ANSI): |
52 if isinstance(getattr(ANSI, attr), basestring): | 58 if isinstance(getattr(ANSI, attr), basestring): |
53 setattr(ANSI, attr, u'') | 59 setattr(ANSI, attr, u"") |
54 del tty | 60 del tty |