Giter Site home page Giter Site logo

dyu / cli-highlight Goto Github PK

View Code? Open in Web Editor NEW

This project forked from felixfbecker/cli-highlight

0.0 1.0 0.0 1.39 MB

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

Home Page: https://cli-highlight.surge.sh

License: ISC License

Shell 0.80% JavaScript 0.36% Scheme 2.29% Groovy 4.93% XQuery 2.38% TypeScript 72.42% Hy 3.40% Zephir 3.66% HTML 0.59% 1C Enterprise 9.17%

cli-highlight's Introduction

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.

cli-highlight's People

Contributors

christianbratschke avatar felixfbecker avatar greenkeeper[bot] avatar keplersj avatar larsbs avatar loriswit avatar mkantor avatar renovate[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.