-
Notifications
You must be signed in to change notification settings - Fork 104
/
to_ansi.js
executable file
·46 lines (35 loc) · 957 Bytes
/
to_ansi.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
#!/usr/bin/env node
/* jslint node: true */
/* eslint-disable no-console */
'use strict';
const { controlCodesToAnsi } = require('../core/color_codes.js');
const fs = require('graceful-fs');
const iconv = require('iconv-lite');
const ToolVersion = '1.0.0';
function main() {
const argv = (exports.argv = require('minimist')(process.argv.slice(2), {
alias: {
h: 'help',
v: 'version',
},
}));
if (argv.version) {
console.info(ToolVersion);
return 0;
}
if (0 === argv._.length || argv.help) {
console.info('usage: to_ansi.js [--version] [--help] PATH');
return 0;
}
const path = argv._[0];
fs.readFile(path, (err, data) => {
if (err) {
console.error(err.message);
return -1;
}
data = iconv.decode(data, 'cp437');
console.info(controlCodesToAnsi(data));
return 0;
});
}
main();