-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
67 lines (51 loc) 路 1.45 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const path = require('path')
const deepMerge = require('deepmerge')
const itermcolorsToHex = require('itermcolors-to-hex')
const parseAnsi = require('parse-ansi')
const defaultColors = require('./colors/ansi-tag-html-colors-as-hex.json')
const iTerm2ColorsNames = require('./ansi-tags-to-iterm2-color-names')
const optsDefault = {
colors: defaultColors
}
const iTerm2Colors = plistFile => {
const colorMap = {}
const iTermHexColors = itermcolorsToHex(plistFile)
Object.entries(iTerm2ColorsNames).forEach(([ansiTag, iTerm2Tag]) => {
colorMap[ansiTag] = iTermHexColors[iTerm2Tag]
})
return colorMap
}
const parseOpts = $opts => {
if (typeof $opts.colors === 'string') {
const colorFile = path.parse($opts.colors)
if (colorFile.ext === '.itermcolors') {
const colorMap = iTerm2Colors($opts.colors)
$opts.colors = colorMap
}
}
return $opts
}
const mergeOpts = (pluginOpts, userOpts) => {
let $opts = optsDefault
if (pluginOpts) {
$opts = deepMerge(optsDefault, pluginOpts)
}
if (userOpts) {
$opts = deepMerge($opts, userOpts)
}
return parseOpts($opts)
}
const activePlugins = {}
const plugin = pluginModule => {
activePlugins[pluginModule.name] = pluginModule.name
const wrappedHandler = (ansi, userOpts) => {
const $opts = mergeOpts(pluginModule.opts, userOpts)
const parsed = parseAnsi(ansi)
return pluginModule.handler(parsed, $opts)
}
return wrappedHandler
}
const load = {
iTerm2Colors
}
module.exports = {load, plugin}