1. cli-highlight
Syntax highlighting in your terminal
cli-highlight
Package: cli-highlight
Created by: felixfbecker
Last modified: Wed, 12 Apr 2023 02:46:09 GMT
Version: 2.1.11
License: ISC
Downloads: 10,470,516
Repository: https://github.com/felixfbecker/cli-highlight

Install

npm install cli-highlight
yarn add cli-highlight

cli-highlight

Syntax highlighting in your terminal

npm
downloads
CI status
codecov
node
code style: prettier
semantic-release
license

Example

Example Output

CLI Usage

Output a file

 $ highlight package.json

Color output of another program with piping. Example: A database migration script that logs SQL Queries

 $ db-migrate --dry-run | highlight

Command line options:

 Usage: highlight [options] [file]

Outputs a file or STDIN input with syntax highlighting

Options:
  --language, -l  Set the langugage explicitely
                  If omitted will try to auto-detect
  --theme, -t     Use a theme defined in a JSON file
  --version, -v   Show version number                                   [boolean]
  --help, -h      Show help                                             [boolean]

Programmatic Usage

You can use this module programmatically to highlight logs of your Node app. Example:

 const highlight = require('cli-highlight').highlight
const Sequelize = require('sequelize')

const db = new Sequelize(process.env.DB, {
  logging(log) {
    console.log(highlight(log, {language: 'sql', ignoreIllegals: true}))
  }
})

Detailed API documenation can be found here.

Themes

You can write your own theme in a JSON file and pass it with --theme.
The key must be one of the highlight.js CSS class names or "default",
and the value must be one or an array of Chalk styles to be applied to that token.

 {
  "keyword": "blue",
  "built_in": ["cyan", "dim"],
  "string": "red",
  "default": "gray"
}

The style for "default" will be applied to any substrings not handled by highlight.js. The specifics depend on the language but this typically includes things like commas in parameter lists, semicolons at the end of lines, etc.

The theme is combined with the default theme.
The default theme is still not colored a lot or optimized for many languages, PRs welcome!

Supported Languages

All languages of highlight.js are supported.
Check a CI build for examples of all the different languages and their highlighting.

Contributing

The module is written in TypeScript and can be compiled with npm run build.
npm run watch starts tsc in watch mode. Tests are written with mocha.

Improving language support is done by adding more colors to the tokens in the default theme and writing more tests.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code