This commit is contained in:
Tutur33
2023-11-24 23:58:26 +01:00
parent 25395c0ee1
commit 938ad9d309
4191 changed files with 41 additions and 518781 deletions
-1
View File
@@ -1 +0,0 @@
assets
-6
View File
@@ -1,6 +0,0 @@
sudo: false
language: node_js
node_js:
- "6"
- "8"
- "10"
-23
View File
@@ -1,23 +0,0 @@
Copyright 2012 Thorsten Lorenz.
All rights reserved.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
-131
View File
@@ -1,131 +0,0 @@
# cardinal [![Build Status](https://secure.travis-ci.org/thlorenz/cardinal.svg)](http://travis-ci.org/thlorenz/cardinal)
<a href="https://www.patreon.com/bePatron?u=8663953"><img alt="become a patron" src="https://c5.patreon.com/external/logo/become_a_patron_button.png" height="35px"></a>
[![NPM](https://nodei.co/npm/cardinal.png?downloads=true&stars=true)](https://nodei.co/npm/cardinal/)
**car·di·nal** *(kärdn-l, kärdnl)* - crested thick-billed North American finch having bright red plumage in the male.
![screenshot](https://github.com/thlorenz/cardinal/raw/master/assets/screen-shot.png)
## Features
- highlights JavaScript code with ANSI colors to improve terminal output
- theming support, see [custom color themes](https://github.com/thlorenz/cardinal/tree/master/themes)
- optionally print line numbers
- API and command line interface (`cdl`)
- `.cardinalrc` config to customize settings
- supports UNIX pipes
***
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
- [Installation](#installation)
- [As library](#as-library)
- [As Commandline Tool](#as-commandline-tool)
- [Commandline](#commandline)
- [Highlight a file](#highlight-a-file)
- [As part of a UNIX pipe](#as-part-of-a-unix-pipe)
- [Theme](#theme)
- [API](#api)
- [*highlight(code[, opts])*](#highlightcode-opts)
- [*highlightFileSync(fullPath[, opts])*](#highlightfilesyncfullpath-opts)
- [*highlightFile(fullPath[, opts], callback)*](#highlightfilefullpath-opts-callback)
- [opts](#opts)
- [Examples ([*browse*](https://github.com/thlorenz/cardinal/tree/master/examples))](#examples-[browse]https://githubcom/thlorenz/cardinal/tree/master/examples)
## Installation
### As library
npm install cardinal
### As Commandline Tool
[sudo] npm install -g cardinal
**Note:**
When installed globally, cardinal exposes itself as the `cdl` command.
## Commandline
### Highlight a file
cdl <file.js> [options]
**options**:
- `--nonum`: turns off line number printing (relevant if it is turned on inside `~/.cardinalrc`
### As part of a UNIX pipe
cat file.js | grep console | cdl
**Note:**
Not all code lines may be parsable JavaScript. In these cases the line is printed to the terminal without
highlighting it.
### Theme
The default theme will be used for highlighting.
To use a different theme, include a `.cardinalrc` file in your `HOME` directory.
This is a JSON file of the following form:
```json
{
"theme": "hide-semicolons",
"linenos": true|false
}
```
- `theme` can be the name of any of the [built-in themes](https://github.com/thlorenz/cardinal/tree/master/themes) or the
full path to a custom theme anywhere on your computer.
- linenos toggles line number printing
## API
### *highlight(code[, opts])*
- returns the highlighted version of the passed code ({String}) or throws an error if it was not able to parse it
- opts (see below)
### *highlightFileSync(fullPath[, opts])*
- returns the highlighted version of the file whose fullPath ({String}) was passed or throws an error if it was not able
to parse it
- opts (see below)
### *highlightFile(fullPath[, opts], callback)*
- calls back with the highlighted version of the file whose fullPath ({String}) was passed or with an error if it was not able
to parse it
- opts (see below)
- `callback` ({Function}) has the following signature: `function (err, highlighted) { .. }`
### opts
opts is an {Object} with the following properties:
- `theme` {Object} is used to optionally override the theme used to highlight
- `linenos` {Boolean} if `true` line numbers are included in the highlighted code
- `firstline` {Integer} sets line number of the first line when line numbers are printed
- `jsx` {Boolean} if `true` _JSX_ syntax is supported, otherwise cardinal will raise an error
when encountering _JSX_ (default: `false`)
**Note** The `json` option is obsoleted and not necessary anymore as cardinal properly understands both JSON and JavaScript.
## Examples ([*browse*](https://github.com/thlorenz/cardinal/tree/master/examples))
- [sample .cardinalrc](https://github.com/thlorenz/cardinal/blob/master/examples/.cardinalrc)
- [highlighting a code snippet](https://github.com/thlorenz/cardinal/blob/master/examples/highlight-string.js) via
***highlight()***
- [file that highlights itself](https://github.com/thlorenz/cardinal/blob/master/examples/highlight-self.js) via
***highlightFile()*** including line numbers
- [file that highlights itself hiding all
semicolons](https://github.com/thlorenz/cardinal/blob/master/examples/highlight-self-hide-semicolons.js) via
***highlightFileSync()***
-7
View File
@@ -1,7 +0,0 @@
'use strict'
module.exports = {
highlight: require('./lib/highlight')
, highlightFile: require('./lib/highlightFile')
, highlightFileSync: require('./lib/highlightFileSync')
}
-47
View File
@@ -1,47 +0,0 @@
{
"name": "cardinal",
"version": "2.1.1",
"description": "Syntax highlights JavaScript code with ANSI colors to be printed to the terminal.",
"main": "cardinal.js",
"scripts": {
"test": "npm run run-test && npm run lint",
"run-test": "tape test/*.js",
"lint": "standart",
"lint-fix": "standart --fix",
"demo": "node examples/highlight-string.js; node examples/highlight-self; node examples/highlight-self-hide-semicolons;"
},
"bin": {
"cdl": "./bin/cdl.js"
},
"repository": {
"type": "git",
"url": "git://github.com/thlorenz/cardinal.git"
},
"keywords": [
"syntax",
"highlight",
"theme",
"javascript",
"json",
"terminal",
"console",
"print",
"output"
],
"author": "Thorsten Lorenz <thlorenz@gmx.de> (thlorenz.com)",
"license": "MIT",
"dependencies": {
"ansicolors": "~0.3.2",
"redeyed": "~2.1.0"
},
"devDependencies": {
"readdirp": "~2.1.0",
"standart": "~6.1.0",
"tape": "~4.9.0"
},
"standart": {
"ignore": [
"test/fixtures"
]
}
}
-53
View File
@@ -1,53 +0,0 @@
'use strict'
var path = require('path')
var fs = require('fs')
var utl = require('./utl')
var home = process.env.HOME
var settings
function getSettings(home_) {
if (settings) return settings
var settingsJson
try {
settingsJson = fs.readFileSync(path.join(home_ || home, '.cardinalrc'), 'utf-8')
} catch (_) {
// no .cardinalrc found - not a problem
return undefined
}
try {
return JSON.parse(settingsJson)
} catch (e) {
// Have a .cardinalrc, but something about it is wrong - warn the user
// Coudn't parse the contained JSON
console.error(e)
return undefined
}
}
// home_ mainly to be used during tests
// Resolves the preferred theme from the .cardinalrc found in the HOME directory
// If it couldn't be resolved, undefined is returned
function resolveTheme(home_) {
var themePath
var settings = getSettings(home_)
if (!settings || !settings.theme) return undefined
try {
// allow specifying just the name of a built-in theme or a full path to a custom theme
themePath = utl.isPath(settings.theme) ? settings.theme : path.join(__dirname, 'themes', settings.theme)
return require(themePath)
} catch (e) {
// Specified theme path is invalid
console.error(e)
return undefined
}
}
module.exports = {
resolveTheme: resolveTheme
, getSettings: getSettings
}
-12
View File
@@ -1,12 +0,0 @@
'use strict'
var util = require('util')
module.exports.isPath = function(s) {
return (/[/\\]/).test(s)
}
module.exports.inspect = function(obj, depth) {
console.log(util.inspect(obj, false, depth || 5, true))
}