-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeAutoload.mjs
More file actions
31 lines (25 loc) · 806 Bytes
/
makeAutoload.mjs
File metadata and controls
31 lines (25 loc) · 806 Bytes
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
import {promises as fs} from 'fs';
import colors from './colors.json' with {type: 'json'};
import quantizeColor from './quantizeColor.mjs';
async function main() {
const vimColors = Object.fromEntries(
Object.entries(colors).map(([name, colorGroup]) => (
[name, colorGroup.map(hash => ({gui: hash, cterm: quantizeColor(hashToRgb(hash))}))]
))
);
await fs.writeFile('./vimColors.json', JSON.stringify(vimColors, null, ' '));
await fs.writeFile('./autoload/OuterSunset.vim',
`
let s:colors = ${JSON.stringify(vimColors)}
function! outersunset#GetColors()
return s:colors
endfunction
`
);
}
main();
function hashToRgb(hash) {
const regex = /#(.{2})(.{2})(.{2})/;
const parts = regex.exec(hash);
return Array.from(Array(3).keys()).map(i => parseInt(parts[i + 1], 16));
}