Bringing VS Code syntax highlighting to the terminal!
VS Code has developed phenomenally over the last few years, making it the de facto code editor for millions of developers. With extensive styling and theming, developers quickly became comfortable with its syntax highlighting. Having consistent highlighting means:
- Improved code readability.
- Easier and faster code reviews.
- Consistent and clear diagnostic messages.
Unfortunately, this did not translate to CLI tools that the same developers use. This library aims to bridge the gap by bringing VS Code grammars and themes to the terminal. We hope that future build tools, apis, and linters can adopt it to provide a consistent experience accross all surfaces.
π typescript π default-dark-plus |
π cpp π default-light-plus |
π json π abyss |
π python π default-high-contrast |
π html π default-dark-plus |
π python π tomorrow-night-blue |
π javascriptreact π default-high-contrast |
π javascriptreact π default-high-contrast |
π javascriptreact π default-high-contrast |
π javascriptreact π default-high-contrast |
We support all built in VS Code languages. You can also pass the explicit path to a text mate grammar file if you would like to use a custom language. By default, we try to automatically detect the file's language based on VS Code's file detection rules.
We support all built in VS Code themes. You can also pass the explicit path to a custom theme file if you would like to use a custom theme.
We released the first version of this library to gauge interest and assess further investment areas. Please open an issue to give feedback on your use-case, or how can this library serve you better. Here are some of the features on our roadmap:
- Supporting nested languages (#2)
- Supporting advanced decorators, like underlines, background colors (#3)
- Supporting diffing individual characters in diff view (#4)
You can write automated tests for the output of this library, either by taking snapshots and comparing the raw ANSI output, or by combining this with a library like terminal-screenshot. This library uses XTerm.js to render real terminal output, and saves a screenshot as an image. You can also combine it with jest-image-snapshot to persist and diff these images using Jest.
import vscat from "vscat";
import {renderScreenshot} from "terminal-screenshot";
it("can highlight source code", async () => {
const output = await vscat.highlightSource({sourceCode, ...});
const image = await renderScreenshot({output, ...});
expect(image).toMatchImageSnapshot();
});
Please use GitHub Issues to report any issues, or ask questions.