Description
Description
This RFC proposes adding syntax highlighting to the REPL. Currently, when a user types commands in the REPL, no syntax highlighting is applied. It would be nice to provide at least basic syntax highlighting as is commonly available in modern IDEs.
Syntax highlighting would be accomplished via ANSI escape codes. One of the trickier aspects will be stripping those ANSI escape codes from commands prior to evaluation, saving to a history file, or if a user attempts to copy terminal contents.
One possible option for avoiding stripping is maintaining two command lists: one the text that a user actually enters (i.e., "raw" text) and another which contains "display" text (i.e., text with ANSI markup). What gets executed is the raw text, but what gets actually written to the terminal is the display text.
Additionally, as syntax highlighting is dependent on proper contrast with the terminal background, we'd likely want to support theming. In which case, we need to design associated APIs and support providing a theme on REPL instantiation.
It would also probably be worthwhile adding a built-in command to allow dynamically changing the theme during the REPL session (e.g., switchTheme( theme )
).
Theming should likely be disabled with the REPL is not TTY.
Related Issues
No.
Questions
No.
Other
Potential resources:
Checklist
- I have read and understood the Code of Conduct.
- Searched for existing issues and pull requests.
- The issue name begins with
RFC:
.