Skip to content

Commit b538806

Browse files
committed
Colorize commands separately in the REPL
1 parent a700732 commit b538806

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

Lib/_colorize.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ class Syntax(ThemeSection):
407407
keyword: str = ANSIColors.BOLD_BLUE
408408
keyword_constant: str = ANSIColors.BOLD_BLUE
409409
builtin: str = ANSIColors.CYAN
410+
command: str = ANSIColors.BOLD_CYAN
410411
comment: str = ANSIColors.RED
411412
string: str = ANSIColors.GREEN
412413
number: str = ANSIColors.YELLOW

Lib/_pyrepl/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
IDENTIFIERS_AFTER = frozenset({"def", "class"})
2525
KEYWORD_CONSTANTS = frozenset({"True", "False", "None"})
2626
BUILTINS = frozenset({str(name) for name in dir(builtins) if not name.startswith('_')})
27+
COMMANDS = frozenset({"exit", "quit", "copyright", "help", "clear"})
2728

2829

2930
def THEME(**kwargs):
@@ -235,6 +236,13 @@ def gen_colors_from_token_stream(
235236
):
236237
span = Span.from_token(token, line_lengths)
237238
yield ColorSpan(span, "soft_keyword")
239+
elif (
240+
token.string in COMMANDS
241+
and not (prev_token and prev_token.exact_type == T.DOT)
242+
and (not next_token or next_token.type == T.NEWLINE)
243+
):
244+
span = Span.from_token(token, line_lengths)
245+
yield ColorSpan(span, "command")
238246
elif (
239247
token.string in BUILTINS
240248
and not (prev_token and prev_token.exact_type == T.DOT)

0 commit comments

Comments
 (0)