Skip to content

Commit

Permalink
Reify colors from debugger. (#14387)
Browse files Browse the repository at this point in the history
This help with static checking.
  • Loading branch information
Carreau committed Apr 5, 2024
2 parents 86d864e + 8225d78 commit 38aa68c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
15 changes: 0 additions & 15 deletions IPython/core/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,21 +253,6 @@ def __init__(self, completekey=None, stdin=None, stdout=None, context=5, **kwarg
C = coloransi.TermColors
cst = self.color_scheme_table

cst['NoColor'].colors.prompt = C.NoColor
cst['NoColor'].colors.breakpoint_enabled = C.NoColor
cst['NoColor'].colors.breakpoint_disabled = C.NoColor

cst['Linux'].colors.prompt = C.Green
cst['Linux'].colors.breakpoint_enabled = C.LightRed
cst['Linux'].colors.breakpoint_disabled = C.Red

cst['LightBG'].colors.prompt = C.Blue
cst['LightBG'].colors.breakpoint_enabled = C.LightRed
cst['LightBG'].colors.breakpoint_disabled = C.Red

cst['Neutral'].colors.prompt = C.Blue
cst['Neutral'].colors.breakpoint_enabled = C.LightRed
cst['Neutral'].colors.breakpoint_disabled = C.Red

# Add a python parser so we can syntax highlight source while
# debugging.
Expand Down
23 changes: 20 additions & 3 deletions IPython/core/excolors.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ def exception_colors():
>>> ec.active_scheme_name
'NoColor'
>>> sorted(ec.active_colors.keys())
['Normal', 'caret', 'em', 'excName', 'filename', 'filenameEm', 'line',
'lineno', 'linenoEm', 'name', 'nameEm', 'normalEm', 'topline', 'vName',
'val', 'valEm']
['Normal', 'breakpoint_disabled', 'breakpoint_enabled', 'caret', 'em',
'excName', 'filename', 'filenameEm', 'line', 'lineno', 'linenoEm', 'name',
'nameEm', 'normalEm', 'prompt', 'topline', 'vName', 'val', 'valEm']
"""

ex_colors = ColorSchemeTable()
Expand Down Expand Up @@ -70,6 +71,10 @@ def exception_colors():
"line": C.NoColor,
"caret": C.NoColor,
"Normal": C.NoColor,
# debugger
"prompt": C.NoColor,
"breakpoint_enabled": C.NoColor,
"breakpoint_disabled": C.NoColor,
},
)
)
Expand Down Expand Up @@ -99,6 +104,10 @@ def exception_colors():
"line": C.Yellow,
"caret": C.White,
"Normal": C.Normal,
# debugger
"prompt": C.Green,
"breakpoint_enabled": C.LightRed,
"breakpoint_disabled": C.Red,
},
)
)
Expand Down Expand Up @@ -132,6 +141,10 @@ def exception_colors():
"line": C.Red,
"caret": C.Normal,
"Normal": C.Normal,
# debugger
"prompt": C.Blue,
"breakpoint_enabled": C.LightRed,
"breakpoint_disabled": C.Red,
},
)
)
Expand Down Expand Up @@ -161,6 +174,10 @@ def exception_colors():
"line": C.Red,
"caret": C.Normal,
"Normal": C.Normal,
# debugger
"prompt": C.Blue,
"breakpoint_enabled": C.LightRed,
"breakpoint_disabled": C.Red,
},
)
)
Expand Down
30 changes: 28 additions & 2 deletions IPython/utils/coloransi.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,34 @@ class TermColors:
Normal = '\033[0m' # Reset normal coloring
_base = '\033[%sm' # Template for all other colors

# Build the actual color table as a set of class attributes:
make_color_table(TermColors)
Black = "0;30"
Red = "0;31"
Green = "0;32"
Brown = "0;33"
Blue = "0;34"
Purple = "0;35"
Cyan = "0;36"
LightGray = "0;37"
# Light colors
DarkGray = "1;31"
LightRed = "1;32"
LightGreen = "1;33"
Yellow = "1;34"
LightBlue = "1;35"
LightPurple = "1;36"
LightCyan = "1;37"
White = "1;38"
# Blinking colors. Probably should not be used in anything serious.
BlinkBlack = "5;30"
BlinkRed = "5;31"
BlinkGreen = "5;32"
BlinkYellow = "5;33"
BlinkBlue = "5;34"
BlinkPurple = "5;35"
BlinkCyan = "5;36"
BlinkLightGray = "5;37"



class InputTermColors:
"""Color escape sequences for input prompts.
Expand Down

0 comments on commit 38aa68c

Please sign in to comment.