PitchHut logo
prism-cli
Elevate command line outputs with syntax highlighting.
Pitch

prism-cli offers a powerful solution for syntax highlighting of source code directly in the command line. Leveraging the capabilities of the PrismJS library, it supports an array of languages and allows customization of colors and tokens. Ideal for developers seeking clear and visually appealing outputs in their terminal.

Description

Prism-cli is a lightweight command line tool that enhances the readability of source code files through syntax highlighting. Built on the robust PrismJS library, developed by Lea Verou, this tool supports a wide range of programming languages. While not all tokens from PrismJS are implemented, it effectively manages ANSI colors with the help of ansi-256-colors. Users can customize the experience further by providing a configuration file to define color mappings and token support as desired.

Key Features

  • Versatile Highlighting: Highlight sources via the command line with ease, leveraging the capabilities of the PrismJS library.
  • Custom Configurations: Define personal color schemes and supported tokens by creating a configuration file.

Example Usage

For basic highlighting, the command can be used as follows:

cat {FILENAME} | prism -l {LANGUAGE}

Alternatively:

prism -l {LANGUAGE} -f {FILENAME}

For better color detection with less, include the -R option:

prism --color=256 -l {LANGUAGE} -f {FILENAME} | less -R

HTML Output

To obtain HTML output instead of terminal formatting, the --html parameter can be added:

prism -l {LANGUAGE} -f {FILENAME} --html

Integration as Node.js Module

The tool can also be used as a Node.js module for inline code highlighting:

var highlight = require('prism-cli');
console.log(highlight('function(x) { return x * x; }', 'javascript'));

Configuration Example

A configuration file can be created at ~/.prismrc to define custom colors for various PrismJS tokens. Below is an example:

module.exports = {
  'function': '\x1b[37m',
  'comment': '\x1b[38;5;241m',
  'keyword': '\x1b[38;5;31m',
  'string': '\x1b[38;5;28m',
  'punctuation': '',
  'operator': '',
  'number': '\x1b[38;5;166m',
};

A comprehensive list of PrismJS tokens is available in the prism.css file.

Contribution

Contributions are welcomed, especially for languages that currently lack color support. Create a pull request or submit an issue with your enhancements and configurations.

0 comments

No comments yet.

Sign in to be the first to comment.