Skip to content

Commit 6ddfa61

Browse files
committed
use _colorize instead of our own Color
1 parent 0ea7c49 commit 6ddfa61

2 files changed

Lines changed: 28 additions & 48 deletions

File tree

Lib/_colorize.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@
77

88
class ANSIColors:
99
BACKGROUND_YELLOW = "\x1b[43m"
10+
BOLD_BLUE = "\x1b[1;34m"
1011
BOLD_GREEN = "\x1b[1;32m"
1112
BOLD_MAGENTA = "\x1b[1;35m"
1213
BOLD_RED = "\x1b[1;31m"
14+
BOLD_TEAL = "\x1b[1;36m"
15+
BOLD_YELLOW = "\x1b[1;33m"
1316
BLACK = "\x1b[30m"
1417
GREEN = "\x1b[32m"
1518
GREY = "\x1b[90m"
1619
MAGENTA = "\x1b[35m"
1720
RED = "\x1b[31m"
1821
RESET = "\x1b[0m"
22+
TEAL = "\x1b[36m"
1923
YELLOW = "\x1b[33m"
2024

2125

Lib/_pyrepl/fancycompleter.py

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,69 +9,44 @@
99
from __future__ import print_function
1010

1111
from _pyrepl import readline
12+
from _colorize import ANSIColors
1213
import rlcompleter
1314
import sys
1415
import types
1516
import os.path
1617
from itertools import count
1718

18-
class Color:
19-
black = '30'
20-
darkred = '31'
21-
darkgreen = '32'
22-
brown = '33'
23-
darkblue = '34'
24-
purple = '35'
25-
teal = '36'
26-
lightgray = '37'
27-
darkgray = '30;01'
28-
red = '31;01'
29-
green = '32;01'
30-
yellow = '33;01'
31-
blue = '34;01'
32-
fuchsia = '35;01'
33-
turquoise = '36;01'
34-
white = '37;01'
35-
36-
@classmethod
37-
def set(cls, color, string):
38-
try:
39-
color = getattr(cls, color)
40-
except AttributeError:
41-
pass
42-
return '\x1b[%sm%s\x1b[00m' % (color, string)
43-
4419

4520
class DefaultConfig:
4621

4722
consider_getitems = True
4823
use_colors = 'auto'
4924

5025
color_by_type = {
51-
types.BuiltinMethodType: Color.turquoise,
52-
types.MethodType: Color.turquoise,
53-
type((42).__add__): Color.turquoise,
54-
type(int.__add__): Color.turquoise,
55-
type(str.replace): Color.turquoise,
56-
57-
types.FunctionType: Color.blue,
58-
types.BuiltinFunctionType: Color.blue,
59-
60-
type: Color.fuchsia,
61-
62-
types.ModuleType: Color.teal,
63-
type(None): Color.lightgray,
64-
str: Color.green,
65-
bytes: Color.green,
66-
int: Color.yellow,
67-
float: Color.yellow,
68-
complex: Color.yellow,
69-
bool: Color.yellow,
26+
types.BuiltinMethodType: ANSIColors.BOLD_TEAL,
27+
types.MethodType: ANSIColors.BOLD_TEAL,
28+
type((42).__add__): ANSIColors.BOLD_TEAL,
29+
type(int.__add__): ANSIColors.BOLD_TEAL,
30+
type(str.replace): ANSIColors.BOLD_TEAL,
31+
32+
types.FunctionType: ANSIColors.BOLD_BLUE,
33+
types.BuiltinFunctionType: ANSIColors.BOLD_BLUE,
34+
35+
type: ANSIColors.BOLD_MAGENTA,
36+
37+
types.ModuleType: ANSIColors.TEAL,
38+
type(None): ANSIColors.GREY,
39+
str: ANSIColors.BOLD_GREEN,
40+
bytes: ANSIColors.BOLD_GREEN,
41+
int: ANSIColors.BOLD_YELLOW,
42+
float: ANSIColors.BOLD_YELLOW,
43+
complex: ANSIColors.BOLD_YELLOW,
44+
bool: ANSIColors.BOLD_YELLOW,
7045
}
7146
# Fallback to look up colors by `isinstance` when not matched
7247
# via color_by_type.
7348
color_by_baseclass = [
74-
((BaseException,), Color.red),
49+
((BaseException,), ANSIColors.BOLD_RED),
7550
]
7651

7752

@@ -230,10 +205,11 @@ def color_for_obj(self, i, name, value):
230205
color = _color
231206
break
232207
else:
233-
color = '00'
208+
color = ANSIColors.RESET
234209
# hack: prepend an (increasing) fake escape sequence,
235210
# so that readline can sort the matches correctly.
236-
return '\x1b[%03d;00m' % i + Color.set(color, name)
211+
N = f"\x1b[{i:03d};00m"
212+
return f"{N}{color}{name}{ANSIColors.RESET}"
237213

238214

239215
def commonprefix(names, base=''):

0 commit comments

Comments
 (0)