stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

feat: add syntax highlighting in the REPL

Open Snehil-Shah opened this issue 1 year ago • 0 comments

Resolves #2072

Description

What is the purpose of this pull request?

This pull request:

  • [x] adds syntax highlighting to the REPL
  • [ ] add more color themes and API for user-defined themes
  • [ ] add settings to control behavior and change themes.
  • [ ] handle non-TTY contexts
  • [ ] add tests

This PR is in progress. Requesting for feedback..

Related Issues

Does this pull request have any related issues?

This pull request:

  • resolves #2072

Questions

Any questions for reviewers of this pull request?

As there are only a few colors we can choose from to highlight using ANSI codes, I have kept a minimalist approach to highlighting. We don't highlight identifiers, operators and brackets. This is consistent with how IPython and node's repl-rewrite do their syntax highlighting. This can easily be changed as acorn's tokenizer is pretty verbose, so would love to hear your thoughts..

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

Currently, I have only added one theme. I will be extending this and also going to add an API for user-defined themes.

Tokens gettings highlighted:

  • String literals: strings, regexes, templates
  • Numeric literals
  • Keywords
  • Looping keywords: while, for etc
  • REPL commands
  • Comments

Attaching some screenshots at different terminal backgrounds:

Light:

light

Dark:

dark

Monokai:

monokai

Solarized:

solarized

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

Snehil-Shah avatar May 20 '24 18:05 Snehil-Shah