From 9b7b5c6fffa9c1c6c260934a8313e4bbe87fc3b3 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Fri, 18 Jan 2019 23:47:00 -0700 Subject: [PATCH] Initial to_ansi util for color codes -> ANSI --- util/to_ansi.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 util/to_ansi.js diff --git a/util/to_ansi.js b/util/to_ansi.js new file mode 100755 index 00000000..72838493 --- /dev/null +++ b/util/to_ansi.js @@ -0,0 +1,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();