Skip to content

[RFC]: add syntax highlighting support to the REPL #2072

Closed
@kgryte

Description

@kgryte

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:.

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementIssue or pull request for enhancing existing functionality.JavaScriptIssue involves or relates to JavaScript.Needs DiscussionNeeds further discussion.REPLIssue or pull request specific to the project REPL.RFCRequest for comments. Feature requests and proposed changes.difficulty: 4Likely to be moderately difficult.priority: NormalNormal priority concern or feature request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions