• Stars
    star
    282
  • Rank 146,549 (Top 3 %)
  • Language
    TypeScript
  • License
    ISC License
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Syntax highlighting for your terminal ๐Ÿ’ปโœจ

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.

More Repositories

1

php-language-server

PHP Implementation of the VS Code Language Server Protocol ๐Ÿ†šโ†”๐Ÿ–ฅ
PHP
1,126
star
2

svg-screenshots

๐Ÿ“ธ๐Ÿงฉ Browser extension to take scalable, semantic, accessible screenshots of websites in SVG format.
TypeScript
834
star
3

node-sql-template-strings

ES6 tagged template strings for prepared SQL statements ๐Ÿ“‹
JavaScript
588
star
4

vscode-php-intellisense

Advanced PHP IntelliSense for Visual Studio Code ๐Ÿ†š๐Ÿ’ฌ
TypeScript
397
star
5

dom-to-svg

Library to convert a given HTML DOM node into an accessible SVG "screenshot".
TypeScript
378
star
6

iterare

Array methods + ES6 Iterators = โค๏ธ
TypeScript
284
star
7

php-advanced-json-rpc

A more advanced PHP implementation of the JSONRPC Protocol ๐Ÿ“žโ—
PHP
245
star
8

php-language-server-protocol

Protocol classes for the Language Server Protocol in PHP
PHP
216
star
9

semantic-release-docker

๐Ÿณ Set of semantic-release plugins to publish to DockerHub
JavaScript
76
star
10

sequelize-decorators

Sequelize + Decorators = โค
TypeScript
76
star
11

PSKubectl

kubectl with the power of the object pipeline
C#
61
star
12

merkel

Handles your database migration crisis ๐Ÿ›„
TypeScript
42
star
13

link-preview-sidebar

Browser extension to open links in a sidebar instead of a new tab.
TypeScript
39
star
14

PowerGit

Git with the power of the PowerShell object pipeline. For macOS, Linux and Windows.
PowerShell
31
star
15

vscode-php-pack

Visual Studio Code extension pack for PHP ๐Ÿ“ฆ
17
star
16

vscode-css-stacking-contexts

VS Code extension to highlight stacking contexts in CSS and ineffective z-index declarations ๐Ÿ’ค
TypeScript
17
star
17

abortable-rx

Drop-in replacements for RxJS Observable methods and operators that work with AbortSignal
TypeScript
13
star
18

semantic-release-firefox

๐ŸฆŠ๐Ÿ“ฆ๐Ÿš€ semantic-release plugin to automatically release Firefox extensions
HTML
10
star
19

angular-async-filter

Angular2's async pipe for Angular 1. Promise in controller, value in view.
JavaScript
6
star
20

aggregate-map

Read-only ES6 Map implementation that aggregates results from multiple Maps in O(n)
TypeScript
4
star
21

PowerShellXSD

XML schema definitions for PowerShell Format and Types.ps1xml files. NOTE: MOVED TO THE OFFICIAL POWERSHELL REPO
PowerShell
4
star
22

PSDefaults

Manage macOS preferences from PowerShell
PowerShell
4
star
23

PSBuildkite

Module to interact with the Buildkite API from PowerShell
PowerShell
3
star
24

rx-component

Functional, Reactive React Components
TypeScript
3
star
25

PSTravis

Interact with the Travis API from PowerShell
PowerShell
2
star
26

iterare-php

Functional utilities for Iterators
PHP
2
star
27

npm-changing-lockfile-repro

Minimal reproduction case for https://npm.community/t/package-lock-json-keeps-changing-between-platforms-and-runs/1129/4
2
star
28

vscode-postgresql-syntax

Better syntax highlighting for PostgreSQL in VSCode
2
star
29

lint-blame

Blames your lint complaints to enable incremental adoption of new lint rules
TypeScript
2
star
30

whatwg-url-custom-host-repro

Website to show inconsistent behavior of the WHATWG URL API in different browsers when parsing custom protocols
HTML
2
star
31

olfaction

Storage server for code smell analysis data
TypeScript
1
star
32

node-date-only

DONT USE THIS ATM, WILL SEE v2 SOON
JavaScript
1
star
33

rxx

Reactive JSX
TypeScript
1
star
34

stringscore

String scoring algorithm used by VS Code ported to Go
Go
1
star
35

lspindex

CLI tool to build a symbol graph by querying a language server
TypeScript
1
star
36

php-semantic-release-test

PHP
1
star
37

sourcegraph-css-stacking-contexts

Sourcegraph extension to highlight CSS declarations that introduce new stacking contexts.
TypeScript
1
star
38

react-resizable-css-grid

TypeScript
1
star
39

PSCodeCovIo

Helper to use in CI to convert test coverage data emitted by https://github.com/pester/Pester to JSON that can be uploaded to https://codecov.io
PowerShell
1
star