• Stars
    star
    7
  • Rank 2,294,772 (Top 46 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 2 years ago

Reviews

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

Repository Details

Syntax highlighting for command line

Prims-cli

Prism-cli is small script for highlighting of source code files from command line

It use awesome PrismJS library by Lea Verou and support all languages that prism support, but not all tokens are supported, ANSI colors are handled by ansi-256-colors. If you want you can provide configuration file where you can use any colors you like and provide all the tokens that PrismJS support.

npm GitHub license

Preview

Terminal with JavaScript Code in color

Installation

npm install -g prism-cli

Usage

cat {FILENAME} | prism -l {LANGAUGE}

or

prism -l {LANGUAGE} -f {FILENAME}

if you want to use less you need to use -R option:

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

You need --color option because of detection of 256 colors don't work in less because it's not real terminal. If your terminal don't support 256 colors you can use --color without argument.

If for some reason you need ANSI formatting for each line, like when you have long multiline comments and you use tail or head to get only few lines you can use -n option to have ANSI formatting on each line:

prism -l {LANGUAGE} -f {FILENAME} -n | tail -n 10

If you need to get the html code instead of the terminal output you can pass the --html parameter

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

Node.js module

You can also use it as node.js module and highlight the text in your app.

var highlight = require('prism-cli');

console.log(hightlight('function(x) { return x * x; }', 'javascript'));

There is also 3rd optional argument to hightlight function which is newline flag same as -n in command line.

3rd argument to main function is options that are optional, it can accept this options:

  • html - indicate if it should return default html code from prism.
  • newlines - if set to true it will wrap each line in ANSI formatting.
  • grammar - prism.js grammar that you can load yourself (or you can have custom grammar).
  • colors - object with mapping prism token => ANSI escape color

Config file

If you don't like default colors you can use ~/.prismrc file that should be node module with exported object, that have PrismJS tokens that map to ASNI escapes.

Example mapping for 256 color supported terminals:

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',
};

List of all PrismJS tokens can be found in PrismJS source code in prism.css.

Contribution

If you use some language that lack of colors for prism token, you can create Pull Request. I will happly merge your changes.

If you create nice palette using configuration file, you can create an issue or PR, I will check it and merge if it looks good.

Contributors

License

Licensed under MIT license

Copyright (c) 2017 Jakub T. Jankiewicz

More Repositories

1

jquery.terminal

jQuery Terminal Emulator - JavaScript library for creating web-based terminals with custom commands
JavaScript
2,940
star
2

sysend.js

Web application synchronization between different tabs
JavaScript
1,025
star
3

wayne

Service Worker Routing library for in browser HTTP requests
JavaScript
547
star
4

lips

Scheme based powerful lisp interpreter written in JavaScript
JavaScript
323
star
5

chat-gpt

ChatGPT conversation saving bookmark
JavaScript
291
star
6

tagger

Zero Dependency, Vanilla JavaScript Tag Editor
JavaScript
261
star
7

jquery.splitter

jQuery Splitter is plugin that split your content with movable splitter between them
JavaScript
240
star
8

gaiman

Gaiman: Text based game engine and programming language
JavaScript
137
star
9

leash

Browser Shell
JavaScript
120
star
10

jquery.rotate

Simple plugin that add rotate css property and animation
JavaScript
94
star
11

git

GIT Web Terminal
JavaScript
82
star
12

Clarity

Customizable Monoshape Vector Icon Theme for GTK+
SVG
39
star
13

jquery.filebrowser

File browser jQuery plugin
JavaScript
30
star
14

jquery.terminal-www

jQuery Terminal Website
HTML
26
star
15

favloader

Vanilla JavaScript library for loading animation in favicon
JavaScript
23
star
16

cmatrix

Render Matrix effect animation on Canvas in JavaScript
JavaScript
22
star
17

lily

Simple JavaScript options parser inspired by yargs
JavaScript
21
star
18

jsh.php

Terminal like php shell (PHP web terminal emulator)
PHP
20
star
19

jsvi

fork of JSVI - VI in JavaScript
JavaScript
18
star
20

Monadic

JavaScript micro library - POC
JavaScript
16
star
21

fake-linux-terminal

Fake GNU/Linux, Unix, MacOS terminal based system
HTML
15
star
22

json-rpc

JSON-RPC implementaion in php and JavaScript
PHP
13
star
23

electron-terminal

Base for jQuery Terminal based Electron apps
JavaScript
12
star
24

route.js

Simple routing library that can be use on the server or in the browser
JavaScript
11
star
25

jquery.micro

Pico/Nano like editor for jquery.
JavaScript
11
star
26

coverage.el

Emacs minor mode for displaying code coverage
Emacs Lisp
10
star
27

chat

Simple Chat with Server Side Events, PHP and SQLite
PHP
8
star
28

try-python

Try Python website
Python
7
star
29

commodore64

Commodore 64 jQuery Terminal Demo
HTML
7
star
30

ascii-canvas

String based text rendering for Node and Browser
JavaScript
6
star
31

jquery.resize

Custom resize jQuery event for element
JavaScript
6
star
32

notes

Simple text based notes taking app
JavaScript
6
star
33

webrtc-share

Application for sharing files using WebRTC
PHP
6
star
34

jcubic.pl

Głównie JavaScript - blog głównie o Front-Endzie
PHP
5
star
35

awesome-ascii

List of Awesome ASCII libraries
5
star
36

ansidec

Unix formatting transformer in JavaScript
JavaScript
5
star
37

firepad

Simple firepad based source code editor
HTML
5
star
38

quizerach

Simple Quiz Maker Open Source App (WIP)
TypeScript
4
star
39

calendar

ASCII calendar that can be used in Node.js or Browser
JavaScript
4
star
40

angular.piechart

Angular 1.5 component for svg based piecharts
JavaScript
4
star
41

velvet

Vanilla JavaScript Universal CSS in JS library
TypeScript
4
star
42

jcubic

3
star
43

chess

Terminal based chess game
HTML
3
star
44

snapp

Simple Text based notes taking app
PHP
3
star
45

open-source-library

Template for JavaScript Open Source library
Makefile
3
star
46

ToME

ToME - Tales of Middle Earth
C
3
star
47

leash-cordova

Cordova leash shell
JavaScript
3
star
48

filter-paste-js

intercept content pasting into iframe with design mode
JavaScript
3
star
49

fs-browser

In Browser File System App
JavaScript
3
star
50

jquery-position-event

jQuery cursor position change event
JavaScript
2
star
51

isomorphic-lolcat

Lolcat gradient that can be used in browser or Node
JavaScript
2
star
52

react-wayne-auth

JavaScript
2
star
53

koduj-curriculum

Curriculum for teaching programming using JavaScript and p5.js library
2
star
54

dotfiles

Linux dotfiles
Shell
2
star
55

cataloger

Shopping cart like catalog library
JavaScript
2
star
56

json-rpc-list

List of JSON-RPC implementations
2
star
57

compickr

Flickr composition checker
JavaScript
2
star
58

jankiewicz

Personal Blog of Jakub T. Jankiewicz
Liquid
2
star
59

aimed

Simple JavaScript Markdown Editor
JavaScript
2
star
60

yapp

Yet Another PHP Proxy
JavaScript
2
star
61

kopalinski.sqlite

Słownik Wyrazów Obcych Kopalińskiego jako baza sqlite
Python
2
star
62

koduj

P5.js playground
PHP
2
star
63

static

static files used with cdn.jsdelivr.net
JavaScript
2
star
64

opensourcelogo

Logo for you Open Source project
2
star
65

price.py

Scraping prices from Ceneo.pl and save in SQLite database
Python
1
star
66

php-terminal-jwt

Demo of JWT with jQuery Terminal
PHP
1
star
67

refClass

R
1
star
68

jquery.draglessClick

Better jQuery click event that's not invoked when you drag or select text
JavaScript
1
star
69

swift.manager

Server file browser and terminal with apps support
JavaScript
1
star
70

bassel.jcubic.pl

Bassel badge page
PHP
1
star
71

roman

ReactJS application with unit tests
TypeScript
1
star
72

REPL

REPL Bookmarklets for different languages
1
star
73

Similar-Stuff

Get Similar stuff from tastekid.com
Python
1
star
74

expression.php

Safely evaluate math, string, and boolean expressions
PHP
1
star
75

cv

My resume
Makefile
1
star
76

quatro

Simple Q&A Open Source application in PHP
PHP
1
star
77

interactive-scheme-tutorial

Interactive Scheme Tutorial
HTML
1
star
78

Downloader

Command Line tool for download file from file hosting sites.
Ruby
1
star
79

gps.py

Simple script to add GPS EXIF data to images
Python
1
star
80

flash-3d

School project 3D Flash animation in C++
C
1
star
81

FizzBuzz

JavaScript version of function only FizzBuzz
JavaScript
1
star
82

uncp

UNsplash Cache Proxy
PHP
1
star
83

jsvi-app

jsvi app for leash shell
JavaScript
1
star
84

bash

Bash Interpreter written in JavaScript
1
star